Fork me on GitHub
#beginners
<
2020-01-12
>
seancorfield00:01:44

@michael.e.loughlin Normally, in Clojure/Script, you'd just have a single atom with in your case a hash map of file paths to values. You can swap! in new "file" contents with (swap! db assoc "path/to/file" new-contents) and you can add new elements to files like this (swap! db assoc-in ["path/to/file" file-key] sub-content)

seancorfield00:01:48

And your db would be (atom {"path/to/file/1" {:a 1, :b 2} "path/to/another/file" {:x 22 :y 33}})

andy.fingerhut00:01:44

In general, the designed use case for atoms, refs, and agents is that if they contain immutable values, you are safe. If they themselves contain mutable values, I would think 7 times carefully about corner cases before relying on it.

matthew.pettis02:01:16

Hi, is there a way to use quote/splice/eval to evaluate a defrecord definition if I have a list of symbols? I have the following toy example:

didibus02:01:31

Yes, you almost got it:

`(defrecord ~'Myrec [[email protected]])
That's with a backtick at the front

didibus02:01:36

You shouldn't quote defrecord

iagwanderson02:01:48

yeah, the expansion will produce clojure.core/defrecord without the quote.

didibus02:01:19

And that's probably correct

didibus02:01:55

It depends if you want to use the defrecord defined in the namespace which is doing the expansion, or the one which is being expanded into.

matthew.pettis02:01:09

I think I want the first one -- it expands to clojure.core/defrecord, but I'm not sure which of those two options that fulfills...

didibus02:01:47

Then you want:

`(defrecord ~'Myrec [[email protected]])

didibus02:01:37

That means that even if there is a defrecord defined in the namespace being expanded into, it will still use the defrecord macro from clojure.core

matthew.pettis02:01:12

Though the second answer above gives no namespace, so I think I'm seeing what you mean. So I think in my particular case it doesn't matter, since I don't redefine defrecord, and will ultimately both resolve to clojure.core. But this helps me sort some of this stuff...

didibus02:01:54

Ya, its going to be rare, but say you gave it away as a library, you can't assume that the consumer didn't shadow defrecord (even if that be pretty weird in this case).

lukas.block09:01:53

Hey guys, i would like to evaluate expressions in cursive ide similar to how it's done in this picture. Could anyone explain to me how this works?

andy.fingerhut10:01:48

I do not use Cursive and do not know the answer to your question. You may get an answer here, but in case not I wanted to mention that there is a #cursive channel in this Slack that the Cursive developer and others often answer questions

lukas.block10:01:12

ty i'll give it a try

ben.chorin16:01:17

What you’re looking for is Cmd+shift+p

iagwanderson18:01:25

what you guys recommend as a math library? I need to use some optimizer such as Newton Raphson method,

didibus03:01:48

Which does make use of Apache Commons Math and others under the hood

iagwanderson03:01:22

greaat!! Thanks @ o///