There is a nice example of something similar to this in Joy of Clojure (2nd 
edition anyway; not sure about first). It only shows you how to do 
contextual-evaluation, and doesn't return a function if some set of the 
symbols are not mapped in the context, but I'll bet you could modify the 
example to infer when one of the variables is missing in the context 
specification, and return a function in that case. It is right at the 
beginning of the section on macros. Good book, BTW.

Can maybe share more later if you aren't interested in getting the book or 
need more guidance on this.

Chris


On Friday, June 13, 2014 2:46:56 PM UTC-7, Dilvan wrote:
>
>    Hi all,
>
>    I'm a novice to Clojure (but not to programming). 
>    I'm looking for an implementation of an eval function to eval 
> expression like Mathematica does.
>    For instance, in Mathematica the expression:
>
>    8 + a + 9 (2 + b) + 2
>
>    if a and b are not bound, translates to
>
> Plus[10, a, Times[9, Plus[2, b]]]
>
>    if a and b become bounded later (let say to 1 and 2) and the expression 
> is evaluated again, it returns 47.
>
>    I would like to be able to run:
>      (eval-partial '(+ (+ 8 2) a (* 9 (+ 2 b))))
>    and get, if a and b are unbound:
>      (fn [x y] (+ 10 x (* 9 (+ 2 y))))
>    or (better still)
>          ['(a b) (fn [x y] (+ 10 x (* 9 (+ 2 y))))]
>    Notice that, whenever possible, the eval takes place and parts of the 
> expression are evaluated (in the example above, the expression (+ 8 2) is 
> evaluated to 10).  
>
>    If you know of any implementation or have any ideas on the subject, 
> please let me know.
>
>    Cheers,
> Dilvan.
>  
>

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to