-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME
45 lines (33 loc) · 1.5 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# clojure-infix
A simple numerical infix parser for clojure, mimicing the behaviour of clojure's read-string and load-string for simple numerical expressions writen in standard infix notation.
supports most numerical opperations
i.e. + - * /, "power of" operator as either ** or ^, and brackets.
any function calls (e.g. sqrt(x)) are prefixed with Math/
allows the use of symbols, and read-infix-string returns any found in the meta of the returned code
## DISCLAIMER
I have updated the code so it runs on clojure 1.6 using leiningen to start the repl, but as I've not worked on this or even clojure since v1.1, I cannot garantee the code makes any sense in the clojure 1.6 world, nor provide any support for it.
## Usage
The functions `read-infix-string` and `load-infix-string` provide the same interface and functionality as the core clojure functions `read-string` and `load-string` respectively.
## Example Usage
$ lein repl
user=> (require 'clojure-infix)
nil
user=> (clojure-infix/load-infix-string "1 + 1 * 2")
3
user=> (clojure-infix/read-infix-string "(1 + 1) * 2")
(* (+ 1 1) 2)
user=> (clojure-infix/read-infix-string "a + a")
(+ a a)
user=> ((fn [a] (eval (clojure-infix/read-infix-string "a + a"))) 5)
10
user=> (meta (clojure-infix/read-infix-string "a + a"))
{:variables [a]}
user=> (clojure-infix/read-infix-string "sqrt(2) ** 2")
(Math/pow (Math/sqrt 2) 2)
## TODO
* bitwise operations
* allow functions to accept more than 1 input
* keyword support?
* TESTS!!!
## License
FIXME: write