|
|
|
|
|
by kenko
4911 days ago
|
|
"We don't address this in the post, but adding :while conditions is quite a fun challenge." Eurgh, I hate the common Clojure habit (you see it in for, doseq, etc. loops, and in domonad, which is annoying in other ways) of abusing binding vectors to add in extra stuff that doesn't, in itself, have anything to do with binding names to values. If you use a very slightly modified version of the macro defined at [1] (modified to use algo.monads), you can do list comprehensions like this: > (monads/with-monad
monads/sequence-m
(mdo x <- [1 2 3]
y <- [3 4 5]
let added = (+ x y)
(monads/m-result [x y added])))
([1 3 4] [1 4 5] [1 5 6] [2 3 5] [2 4 6] [2 5 7] [3 3 6] [3 4 7] [3 5 8])
The "let added = (+ x y)" is an unnecessary flourish: it would have worked just as well to wrap what followed in (let [added (+ x y)] ...). Likewise (as against domonad), you can just use regular old if; no need for :if.1: https://bitbucket.org/kenko/macroparser/src/7a492ef941db38db... |
|
I'm not familiar with the Clojure examples you mention, but it's interesting that Common Lisp provides directives like &rest for similar purposes.