Re: user math expression evaluation

2013-05-28 Thread SpiderPig
Here is some example code http://pastebin.com/HG2bWWms This allows you to evaluate infix or rpn expressions. It also demonstrates the use of eval to turn the expression into a clojure function which should give more performance. It is very simple though, so all the elements in the expressions hav

Re: user math expression evaluation

2013-05-28 Thread SpiderPig
You could just write this yourself. It's easier than it looks. First start with an evaluator for rpn (reverse polish notation) expressions. "x + sin(y)" in rpn would be "y sin x +". First you split that string and make it into a list. Then you can evaluate that with a few lines of code using a stac

advantage of clojure over non lisp languages

2010-12-07 Thread SpiderPig
Hi, I was wondering if there are any good examples that show what advantages clojure/lisp has over most other programming languages. I mean a piece of code that couldn't be easily translated into e.g. scala or java. A program that would take much longer to develop in other languages due to the uniq

Re: strange bug in range or lazy-seq?

2010-10-12 Thread SpiderPig
Thank you all for explaining this to me but I still don't understand clojures behavior in this case, Try running this code: (def nums (drop 2 (range))) (def primes (cons (first nums) (lazy-seq (->> (rest nums) (remove (fn [x]

strange bug in range or lazy-seq?

2010-10-11 Thread SpiderPig
Hi, I tried experimenting with lazy sequences and wrote this program (def nums (cons 2 (lazy-seq (map inc nums (def primes (cons (first nums) (lazy-seq (->> (rest nums) (remove (fn [x] (let [dividors (take-whil

OO design in clojure

2010-10-03 Thread SpiderPig
I was wondering what's a good way to use OO concepts in clojure. Just using multimethods and maps? Or maybe protocols? Let's say I write a program that deals with many graphical elements e.g. a game or a vector graphic editor. I could represent each graphic/sprite/shape etc. as a map and define mul

Can't figure out how to use binding

2010-04-28 Thread SpiderPig
Hi, I wrote this code to redirect a repl to a JFrame. I used the JConsole class from Beanshell (def console (bsh.util.JConsole.)) (def frame (doto (javax.swing.JFrame.) (.add console) (.setSize 500 500) (.setVisible true) )) (binding [*out* (java.io.OutputStreamWriter. (.getOut console))]