Next: , Previous: , Up: iklib syntaxes   [Index]


6.8.16 Infix to prefix transformer

Syntax: infix ?obj

The infix macro converts the traditional infix notation for mathematical expressions to the equivalent Scheme’s prefix notation. infix expands to a prefix expression to be evaluated at run–time, in the lexical context of the macro use; as a special case (infix) is equivalent to (values).

The macro allows us to evaluate forms like:

(infix atan(1, 2))      → (atan 1 2)
(infix 1 + 2 + 3)       → (+ (+ 1 2) 3)
(infix 1 + 2 * 3)       → (+ 1 (* 2 3))
(infix (1 + 2) * 3)     → (* (+ 1 2) 3)

(infix 2 expt 3 expt 4) → (expt 2 (expt 3 4))
(infix 2 ** 3 ** 4)     → (expt 2 (expt 3 4))

(infix - 5)             → (- 5)
(infix + 5)             → (+ 5)
(infix 5 !)             → (factorial 5)

(infix 1 > 2 ? 3 + 4 : 5 * 6)
→ (if (> 1 2) (+ 3 4) (* 5 6))

(define a 1)
(define b 2)
(define c 3)
(infix cos(a) * tan(b) / c)
→ (/ (* (cos a) (tan b)) c)