Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;This macro was intended to create a looping function
- ;It defines a function "repeat-once" which may be called by itself
- ;But it fails "Unable to resolve symbol: repeat-once"
- (defmacro do-once [expr]
- "expr is of the form {:bind [bindings] :body body}. apply bindings once to body.
- success example:
- (do-once {:bind [x 1 y 2] :body (+ x y)})
- ;;=> 3
- fail example:
- (do-once {:bind [x 5 y 2] :body (if (> x y) (repeat-once (dec x) y) true)})
- ;;=> CompilerException java.lang.RuntimeException: Unable to resolve symbol: repeat-once in this context, compiling:
- "
- (let [
- body (expr :body)
- bind-symbols (take-nth 2 (expr :bind))
- bind-values (take-nth 2 (rest (expr :bind)))
- ]
- `(let [
- ~'repeat-once (fn ~(vec bind-symbols) ~body)
- ]
- (apply ~'repeat-once ~(vec bind-values)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement