help with a sexp to function macro ...

9 views
Skip to first unread message

Sunil S Nandihalli

unread,
Oct 12, 2010, 3:35:16 AM10/12/10
to clo...@googlegroups.com, cloju...@googlegroups.com
Hello everybody,
 I would like some help in writing a macro which accepts the return value from mathematica and create a function in clojure which can be called. I am kind of inexperienced writing macros.. I will try to describe what I have done (does not work ) and request you all to help me modify it to do what I was expecting of it.

I have set up clojure and clojuratica properly.

the results of evaluation of sexps are appended to the sexp 

(mathematica-eval "D[x*x+y*x,x]") =>  (+ (* 2 x) y)  ;sexp1

(math (Variables (+ (* 2 x)  y))  => [x y] ;sexp2

and I was expecting the evaluation of the following

(math (Variables (mathematica-eval "D[x*x+y*x,x]"))) 

to return [x y] .. but I guess I am making a mistake with handling the symbols.. I would like you to help me to make this work.

Finally, when I get a sexp from mathematica I would like to create a function whose body is the returned sexp with all the unbound variables as the arguments to the function. The following was my first attempt at achieving the goal. which does not work.

(defmacro sexp2fn [sexp]
 `(fn ~(math `(Varaibles ~sexp))
        ~sexp))

assuming the above macro were correct .. I would like the macro expantion of the following 

(sexp2fn (mathematica-eval "D[x*x+y*x,x]"))

to return

(fn [x y] (+ (* 2 x) y) 

can anybody help me achieve this.
Thanks for reading.
Sunil.
Reply all
Reply to author
Forward
0 new messages