-
Notifications
You must be signed in to change notification settings - Fork 7
Infix notation
martintrojer edited this page Mar 18, 2012
·
3 revisions
Finj (0.1.4-SNAPSHOT) supports a macro for infix notation for calculations (in the frinj.infix namespace). This is works similar to the $= macro in incanater but with fjvs.
So instead of doing (fj_ 1 (fj :water))
you can do ($= 1 / (fj :water))
.
A more complicated example;
(-> (fj-div (fj 12.5 :kilotons :TNT)
(fj :natural_gas)
(fj+ (fj 6 :years) (fj 9 :months))
(fj* (fj :pi) (fj** (fj 0.5 :in) 2)))
(fj* 10)
(to :mph) str)
becomes
(-> ($= (fj 12.5 :kilotons :TNT) /
($= (fj :natural_gas) * ($= (fj 6 :years) + (fj 9 :months)) * (fj :pi) * (fj 0.5 :in) ** 2)
* 10)
(to :mph) str)
The infix example calculations shows this macro in action.