I've posted a new file, "curly-infix.cl". This Common Lisp program is intended
for those who just want a little improvement in infix handling, without many
complications or a big change.
It modifies the Common Lisp reader so that anything in {...} is considered
infix. Similar to the sweet-expression 0.2 rule, if the expression has 3 or
more parameters, an odd number of parameters, and the even ones are identical
symbols, it becomes (even-parameter odd-parameters). Otherwise, it becomes
(nfx ...), which invokes a compile/execution-time macro process you provide
(like Alan Manuel K. Gloria's macro).
Sample mappings:
{2 * n} maps to (* 2 n)
{x eq y} maps to (eq x y)
{2 + 3 + 4} maps to (+ 2 3 4) - chaining/fungibility works
{2 + {3 * 4}} maps to (+ 2 (* 3 4)) - Nesting works + keeps things simple
{2 + 3 * 4} maps to (nfx 2 + 3 * 4) - non-simple.
Here are some code examples:
(defun fibfast (n)
(if {n < 2}
n
(fibup n 2 1 0)))
(defun fibup (max count n-1 n-2)
(if {max = count}
{n-1 + n-2}
(fibup max {count + 1} {n-1 + n-2} n-1)))
(setf y {3 + {4 * 5}})
(setf z {{1 <= x <= 10} and {x > 0}})
One complication: it can be very confusing to invoke an "nfx" macro that
CHANGES the meaning of an operator. E.G., Alan Manuel K. Gloria's infix macros
by default changes "=" to setf. This would mean that {x = 5} would become the
comparison (= x 5), but {x = 5 * 3} would become (nfx x = 5 * 3) and eventually
the ASSIGNMENT (setf x (* 5 3)).
Alan Manuel K. Gloria: What do you think about using "<-" instead of "="
everywhere for assignment? It's confusing that "=" doesn't map to "=".
You can get it, and its test suite, from the SourceForge subversion site:
http://sourceforge.net/svn/?group_id=169247
--- David A. Wheeler