Fork me on GitHub
#beginners
<
2019-11-04
>
valerauko07:11:51

how exactly are clojure values "copied" when for example assoc'd into a map?

andy.fingerhut12:11:33

@UAEH11THP Most often by making a new reference (aka pointer) to that value from a data structure added to the map.

andy.fingerhut12:11:14

An immutable value can have an arbitrary number of references to it from dozens or hundreds of places, which is perfectly fine since it is never going to change its value.

andy.fingerhut12:11:30

If you would like to generate pictures of what some of these data structures look like in memory, I created a library called cljol that can do so: https://github.com/jafingerhut/cljol . Its 'gallery' has some figures created using the library: https://github.com/jafingerhut/cljol/blob/master/doc/README-gallery.md

Joco08:11:58

Hello everyone! I'm trying to call a function with 4 pairs of arguments, and I'm looking for a more idiomatic way to do it than this:

(do-something "A" :a)
(do-something "B" :b)
(do-something "C" :c)
(do-something "D" :d)

Joco08:11:53

I was looking into apply, but couldn't get it to work. Any suggestions?

schmee08:11:02

can you show you would like it to look?

Joco08:11:42

I think I just found my answer

Joco08:11:37

I kind of want it to look something like

(<thing-im-looking-for> do-something ("A" :a "B" :b "C" :c "D" :d))

Joco08:11:11

or

(<thing-im-looking-for> do-something [["A" :a] ["B" :b] ["C" :c] ["D" :d]])

Joco08:11:19

but it looks like I should be able to do this:

(doseq [char ["A" "B" "C" "D"]
        key [:a :b :c :d]]
  (do-something char key))

Joco08:11:40

wait, no

Joco08:11:46

not what i want.

Joco08:11:01

I got it (edited with @schmee's correction below):

(doseq [[char key] [["A" :a] ["B" :b] ["C" :c] ["D" :d]]]
  (do-something char key))

schmee08:11:39

nice! should be an extra pair of brackets though:

(doseq [[char key] [["A" :a] ["B" :b] ["C" :c] ["D" :d]]]
  (do-something char key))

schmee08:11:00

also, are you using this for something side effect-y or do you need the results of do-something?

Joco08:11:03

yes, thanks. manual copy/paste fail

Joco08:11:12

this is definitely side-effecty

Joco08:11:34

it's setting up keyboard event listeners for Phaser 3

schmee08:11:45

neat, then doseq is appropriate :thumbsup:

Joco08:11:53

cool, thank you for the confirmation 🙂

Mehdi H.10:11:17

hi everyone : struggling with vase here. I am using 'lein new vase service' to try the template out, but then if I follow the readme, 'lein repl' then (def srv (run-dev)) doesn't work, compiler saying it can't resolve run-dev in this context (I am in the right ns though!). What am I doing wrong?

herald12:11:50

What are you using to switch to the correct namespace? You should be calling in-ns and not ns.

Mehdi H.14:11:24

thanks for your feedback. I found it was a known issue with the template and have since moved on to starting using updated samples. But there as well I ran into an issue while trying to use datomic-pro instead of datomic-free using the deps as in samples using datomic-pro, but I get a Failed to construct terminal error...

Misha10:11:28

What library or framework would you recommend for web scraping?¿

Misha10:11:48

Im using selenium in java and want to "migrate" to clojure

MorongÖa14:11:53

Hi guys, I am learning clojure spec

indy14:11:07

Hi All, why is the first case false while second case is true?

indy14:11:22

Is it because quoting primitives is the same as the primitives themselves?

indy14:11:53

Like the following:

Alex Miller (Clojure team)15:11:47

‘9 is the number 9, the latter is a symbol that prints as 9. Symbols are not equal to numbers.

indy15:11:45

Thanks Alex, apologies if it is a basic question but why is '9 the number 9?

Alex Miller (Clojure team)15:11:13

‘ means read but don’t evaluate the next thing. 9 is read as the number 9

Alex Miller (Clojure team)15:11:08

Numbers (like almost everything in Clojure) evaluates to itself though

Alex Miller (Clojure team)15:11:33

Quoting is mostly only useful on the exceptions to that - symbols and lists

Alex Miller (Clojure team)15:11:38

In evaluation, symbols do a lookup to what they refer to, lists invoke the first element using the rest as args

indy15:11:52

Okay, I guess I got it, every primitive is read as the primitive itself but if it is anything else it is a symbol

indy15:11:11

I mean after '

Alex Miller (Clojure team)15:11:18

Well not everything, but mostly yes

indy15:11:29

Okay great! Thanks!

Andre Medeiros17:11:51

👋 what's a good book to learn clojurescript and functional paradigms in general?

papachan21:11:27

personally i recomend Web Development with clojure third edition by Dmitri Sotnikov

papachan21:11:25

Clojure reactive programming by leonardo borges as well

Gerome17:11:36

Hi everyone! Is there a way in clojure to wait for a vector of promises and do something once all promises have returned?

petterik17:11:19

@gerome.bochmann You could map eagerly with run!, mapv, (dorun (map ... )) or (doall (map ...)), calling deref on every promise. For example:

(run! deref promises)
;; Then <do something>

Gerome17:11:23

Cool! I’ve had a similar idea but wasn’t sure where to start. Thanks @petterik

👍 4