Skip to content

tonsky/sane-math

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sane Math

Write Clojure/Script mathematical expressions in infix notation, like a normal person!

Using

Add this to deps.edn:

io.github.tonsky/sane-math {:mvn/version "0.1.0"}

Require:

(require '[sane-math.core :as sane])

Use:

; Values
(sane/math 1 + 2)             ;; => (+ 1 2)

; Variables
(sane/math x + y * z - t)     ;; => (- (+ x (* y z)) t)

; Parentheses
(sane/math (x + y) * (z - t)) ;; => (* (+ x y) (- z t))

; Power
(sane/math (a + b) ** 2)      ;; => (clojure.math/pow (+ a b) 2)

; Unary minus
(sane/math a + - b)           ;; => (+ a (- b))

Same works with reader tag:

#sane-math (1 + 2)             ;; => (+ 1 2)

#sane-math (x + y * z - t)     ;; => (- (+ x (* y z)) t)

#sane-math ((x + y) * (z - t)) ;; => (* (+ x y) (- z t))

#sane-math ((a + b) ** 2)      ;; => (clojure.math/pow (+ a b) 2)

#sane-math (a + - b)           ;; => (+ a (- b))

License

Copyright © 2024 Nikita Prokopov

Licensed under MIT.

About

Clojure/Script library for infix (normal) math expressions

Resources

License

Stars

Watchers

Forks

Packages

No packages published