Hacker News new | ask | show | jobs
by maicro 1580 days ago
Not sure I "get" Clojure yet, but I appreciate the effort and will poke at it further.

One piece of feedback - "Range of N" should clarify that "range" is generating N numbers starting at 0, so N won't actually be included ("0 to N exclusive"). I know this is fairly common for most programming languages, but "So (range 5) will return numbers from 0 to 5." is still ambiguous enough that I think it should be clarified.

Also can't copy the text from the instructions or REPL (at least in Vivaldi on Windows 10).

edit: I'm not a huge fan of the "multiples of 11" algorithm ("100" and "11" never actually show up in the expression...), so I ended up with this abomination which I think strongly reiterates that I don't get Clojure yet...:

> (let [multiplier 11 limit 100] (map (fn [n] (if (> limit (* n multiplier)) (* n multiplier))) (range 1 (/ limit multiplier))))

(11 22 33 44 55 66 77 88 99)

The conditional is probably not needed, but I was curious how they worked... Also glad that range accepts a float for the second value, as I forgot to wrap that in "int" (and "Math/round" didn't seem to work). And yeah, tested and this works just as well for at least the basic version:

> (let [multiplier 11 limit 100] (map (fn [n] (* n multiplier)) (range 1 (/ limit multiplier))))

1 comments

Try typing (doc range) and the docstring will appear.
Thanks. I guess the docs are correct about "end" defaulting to infinity, as "(range)" by itself in the REPL just locked everything up (for about 2 minutes, then resulted in an error of "Invalid string length")