You must eval the whole fn form:

(defn compile-rule [body]
  (eval (list `fn '[a b] body)))

user=> (let [f (compile-rule '(+ a b))]
  (f 18 56))
74


Zak Wilson a écrit :
> So as it turns out, I was mistaken about it working. I had something
> that ran, but the results were nonsense. What I'm trying now looks
> like this:
>
> (defmacro rulefn [r]
>   (let [er (eval r)]
>   `(fn [devid# raveid#]
>      (binding [device-id devid#
>                     rave-id raveid#]
>        ~er))))
>
> This works when used like this:
>
> (def rfn (rulefn '(+ (* 1024 device-id) rave-id)))
>
> but throws "Can't eval locals" when used in a let form:
>
> (let [rfn (rulefn '(+ (* 1024 device-id) rave-id))]
>    ...)
>
> There are zero google hits for "Can't eval locals".
> >
>
>   



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to