Fork me on GitHub
#beginners
<
2018-07-25
>
Chase00:07:44

could someone help me understand the symmetrizer function at: https://www.braveclojure.com/do-things/#Symmetrizer ? one thing that is confusing me is the (loop [remaining-asym-parts asym-body-parts final-body-parts []] ,,,) part. So the parts in the brackets after the loop call are "bindings"? How do you know what order to put those 3 bindings and what are the empty brackets at the end for? i know the loop is breaking the seq down into its head and tail but i'm still confused about the ordering of those bindings and how i would have come up with it.

Chase01:07:42

ok, i think i'm grasping it now. the loop bindings seem to follow: loop [what-i-will-be-creating initial-value-of-that-creation 2nd-thing-i-will-be-binding initial-value-of-2nd-creation] In the synthesizer function we are creating the tail of a sequence using the parameters fed into the function (asym-hobbit-body parts) and then also creating the final body parts list which is initially an empty vector. Not bad chasote! hahaha

sundarj13:07:35

the order of the bindings isn't special, it's just what they decided

eggsyntax15:07:48

Nor is the meaning, for that matter -- it's just whatever you decide to use as the info to keep track of from loop iteration to loop iteration.

1
jonahbenton03:07:54

that's right. that's a common pattern for bindings- let, for and other forms use it as well

Uday19:07:42

Hey people! Can somebody help me with this piece of code? I am expecting a new map with deleted a deleted value("c") in the vector associated with :a but I get an object.

Uday19:07:23

I don't need to use partial I suppose 😛

Uday19:07:51

My bad. Sorry!

Uday19:07:44

Hate it when I figure out the solution just after asking for help.

lilactown20:07:08

is there a clever way to take a list of (foo :bar baz 123) and get just (foo baz)?

seancorfield21:07:13

@lilactown Depends what pattern of selection you're imagining? Every other element? Symbols?

lilactown21:07:59

every other element. I just went with (map first (partition 2 coll)) but wondering if there's something built-in

noisesmith21:07:40

user=> (take-nth 2 '(foo :bar baz 123))
(foo baz)

👍 2
noisesmith21:07:45

(if drop-nth existed and did the intuitive thing that would work too...)

seancorfield21:07:45

TIL! Always discovering new core functions!

yogidevbear22:07:52

Hi everyone. Does anyone know what the ~' in this defn syntax means?

(defn ~'spec ...)

yogidevbear22:07:58

Is it creating an unqualified symbol?

cjmurphy22:07:19

If I see some code like this: (:elm-html m "some-str"), where m is a map, does it mean that if :elm-html is not found in m, "some-str" is returned? I would have googed, but seems like a hard thing to google 😜

cjmurphy22:07:43

Easier to REPL than google...

💯 1
mfikes23:07:38

@yogidevbear In that case, yes. But in general it can be used to put a quoted form literally in the result. Take a look at what this produces

(let [x '(inc 2)] `(list ~'x ~x 'x x ~'(1 2) '(1 2)))

mfikes23:07:30

It seems that the most common use for that pattern is to produce an unqualified symbol.

yogidevbear23:07:00

Cool, thanks @mfikes 👍

Jordan Yee23:07:51

I'm working on a macro that has me stumped. Does anyone know how to get this: (-> {:val1 1} (fn1 arg2) (fn2 arg2)) If I have this?: ({:val1 1} (fn1 arg2) (fn2 arg2))

hiredman23:07:21

cons is usually how you add to the front of a seq