(def factor ...) immediately gets the value of the body to assign to
the var #'factor. (choice ...) is a function, so has to get the
values of it's arguments before invoking. This means it gets the
value of expr, which unbound and uses that.
>
> But this will:
>
> (def factor*
> (choice (bind (match \() (fn [_]
> (bind expr (fn [e]
> (bind (match \)) (fn [_] (result e)))))))
> integer))
This occurs similar to the above, except it hits a fn. fn is a
"special form" defined to wait to get the value of its body until it
is executed. By that time the (def expr ...) has occurred and #'expr
has a bound value. A similar effect can be achieved with
(def factor
(choice (between (match \() (match \)) (fn [x] (expr x)))
integer))
I ran into the same thing re-exploring that paper in clojure.