Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert user-friendly infix math code to Clojure code?

I want user to be able to input like this:

5+6*t+sin(2*t)

, so it will get converted to this:

(+ 5 (* 6 t) (sin (* 2 t)))

, so I can eval it to some function that will be JITted and executed efficiently later.

Are there already available libraries (with operator priorities) that works in up-to-date Clojure already?

like image 727
Vi. Avatar asked Aug 08 '12 22:08

Vi.


1 Answers

the Incanter package include a module for doing infix math

user> ($= 7 + 8 - 2 * 6 / 2)
9

and others have written packages.

like image 95
Arthur Ulfeldt Avatar answered Sep 30 '22 07:09

Arthur Ulfeldt