On May 3, 2014, at 6:42 AM, Roelof Wobben <[email protected]> wrote:
>
> (fn [default initial-keys]
> (loop [remaining-keys initial-keys
> result-map {}]
> (if (empty? remaining-keys)
> result-map
> (let [key (first remaining-keys)
> remaining-keys' (rest remaining-keys)
> result-map' (assoc result-map key default)]
> (recur remaining-keys' result-map')))))
>
> This also passes the unit tests.
>
> Maybe that's a bit clearer as to what's going on. Maybe the new names help a
> bit. Notice the ticks on some of the names (the ' characters). This is just a
> convention some programmers use. The ticks are part of the name, nothing
> magic, and are used to indicate that the value of the name is derived from
> the value of the name with one less tick. Some programmers use numbers
> instead. Other programmers don't care and just use the same name.
>
> When you've understood the solution you've come up with, you might want to
> try using reduce to do this. It'll be both shorter and much easier to
> understand. If you look carefully at your code the only part that isn't
> boiler-plate is the (assoc result-map key default) -- the boiler-plate
> corresponds closely to what reduce does.
>
>
> Thanks,
>
> Now It more clearer what loop does.
> I can look at a reduce solution but then I have to look which reduce I have
> to use.
> I know reduce + and reduce - which does calculations on the collection.
This reduce: http://clojuredocs.org/clojure_core/clojure.core/reduce is what
you need.
Cheers,
Bob
>
> Roelof
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.