beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
ahungry 2021-06-12T04:49:09.078100Z

I think your v2 should be a btree so your O is logarithmic not n*n

2021-06-12T09:24:48.083600Z

Hi, is there a way to overwrite a protocol implementation for some type in a thread-local way (or for some scope would be even better). Concretely, I'm using mongo-driver-3 to store clojure data in mongo, and for the specific data structure I need to encode the namespace of keywords in the field name. But I'd rather not do that for everything, since it would be very unpredictable for other libraries/code.

practicalli-john 2021-06-12T10:25:29.083700Z

@popeyepwr there is an #sql channel

1๐Ÿ‘
borkdude 2021-06-12T14:11:55.084500Z

@mathias_dw What protocol would you override to accomplish that?

borkdude 2021-06-12T14:12:15.085100Z

I guess you could also pre-process the data yourself (stringify the keys that is)

2021-06-12T14:12:18.085200Z

the serialization one in mongo-driver-3

2021-06-12T14:14:08.087300Z

Yeah, I can definitely do it myself, although taking care of all the nesting feels like duplication of the serialization code. But I was mainly wondering if such a "local extends" exists

borkdude 2021-06-12T14:15:06.088400Z

I'm not aware of this. But what you could do is override the protocol with an implementation and use a dynamic var to control the namespacing, defaulting to the previous behavior.

1๐Ÿ‘
2021-06-12T14:15:28.089Z

ah, smart trick, thanks!

borkdude 2021-06-12T14:33:32.089600Z

It might have an adverse affect on performance with large volumes of data, so good to check this

alexmiller 2021-06-12T14:40:28.090600Z

depending on what you need to do, you can do metadata extension on a particular instance (but the protocol has to support it)

sova-soars-the-sora 2021-06-12T17:12:17.091600Z

apply map filter reduce what other functions do you use daily that might not be so well-known?

sova-soars-the-sora 2021-06-12T17:12:32.091900Z

tryna expand on my general purpose toolkit and knowledge

Lu 2021-06-12T17:18:39.093500Z

keep remove some every? sort-by group-by select-keys keys vals

1
Lu 2021-06-12T17:20:17.094500Z

Iโ€™d say I use these ones very frequently

Lu 2021-06-12T17:23:12.096300Z

Some others that come to mind are mapcat concat reverse map-indexed partition-by for doseq reduce-kv

2021-06-12T17:30:44.103600Z

Hi guys, I've just started to learn Clojure and I have a newbie question. How to read a file from stdin? I'd like to know the best way to do that in Clojure. It would be great to do something like that in command line: my-app < file.json Could someone help me with that ?

phronmophobic 2021-06-12T18:16:00.104100Z

This should work:

(def input-string (slurp *in*))
You can also use use the input stream from <http://System.in|System.in> using java interop

2021-06-12T18:24:46.104400Z

How can use this approach in a main function for instance?

sova-soars-the-sora 2021-06-12T18:27:04.104600Z

Are you wanting to provide the input file as an argument on the command line, or wanting to dynamically grab some keystrokes from the REPL?

sova-soars-the-sora 2021-06-12T18:27:13.104800Z

(or perhaps something else?)

phronmophobic 2021-06-12T18:30:48.105Z

Here's an example. You can just use a let

(defn -main [&amp; args]
  (let [input-string (slurp *in*)]
    (println "character count:" (count input-string))))

2021-06-12T18:34:03.105200Z

Oh that works. Thanks @smith.adriane

1๐Ÿ‘
souenzzo 2021-06-12T18:48:36.105900Z

Work with stdin from the repl usually is not a good experience. You can use (require '[<http://clojure.java.io|clojure.java.io> :as io]) and (def input (io/reader "file.json")) Then you can swap from "file.json" to *in*

2021-06-12T18:50:33.106100Z

I'll try this approach too. Thanks @souenzzo

2021-06-12T19:00:54.106300Z

list* is super helpful in combination with apply

Juฮปian (he/him) 2021-06-12T19:56:36.106500Z

btw, I reverted back to the reduce function from the beginning, because I got stack overflows when there were too many functions

2021-06-12T21:48:56.106800Z

group-by is sometimes just the right tool for the job