Arc Forumnew | comments | leaders | submitlogin
2 points by DmitriLebedev 6073 days ago | link | parent

Great, thank you very much. I didn't know the keyword "infix".


3 points by eds 6073 days ago | link

Just FYI, 'infix is not a keyword. (Arc doesn't really have keywords in the same way as other languages, the closest it has are words like 'quote, 'fn, and 'if, which need to be dealt with explicitly in the compiler. Things like 'def and '= which look like keywords in other languages are actually macros, allowing them to be (re)defined by the user inside of arc.)

Also note that there is an infix syntax (besides the custom DSL solution mentioned above), which would probably do what you want. (See http://arclanguage.org/item?id=2610.) You can

  arc> (load "lib/infix.arc")
  nil
after which, the infix form

  (- (log (tan (pi / 4 + (radians lat) / 2)))
would be equivalent to

  (- (log (tan (+ (/ pi 4) (/ (radians lat) 2)))))))
Note that using infix.arc, you don't even need an 'infix keyword around infix math. (This works as long as the object in functional position is a number.) Also note that the syntax of function calls is still exactly the same, it is just infix notation that is implemented.

Because infix notation doesn't interfere with the rest of the language, it actually used to be loaded by default on Anarki, but it was removed because it incurs a fairly hefty runtime overhead, even when using normal (prefix) math.

-----