I wrote this reader for M-expression syntax as an abbreviation for S-Expressions. It may not be very useful for experienced Arc-/Lisp-ers, but it may serve as either syntactical training wheels for imperative programmers who want to learn Arc, or as an ugly example of why S-Expressions are a much better syntax for Lisp. Description of the Syntax: McCarthy's M-Expressions in the original paper looked like this: "cons[a;b];", which is in S-expression form (cons a b).
So in general the grammar is (not real ebnf, but you get the idea): m-expr = <car of s-expr as symbol> <cdr of sexpr as list>
m-expr = <atom>
m-expr = <infix-math>
m-expr = <list>
list = "[]"
list = "[" <mexpr> <list-tail>
list-tail = "]"
list-tail = ";" <mexpr> <list-tail> "]"
Examples for this syntax M-expr S-expr
cons[a;b]; (cons a b)
list[1;2;3]; (list 1 2 3)
n + 1; (+ n 1)
n + 3 * 4; (+ n (* 3 4))
(n + 1) * 3; (* (+ n 1) 3)
[1;2;3;4]; (1 2 3 4)
One generalisation of this syntax is that juxtaposition means consing(left-associative), so the resulting S-exprs can have lists as cars: only[fun][arg]; ((only fun) arg)
But is impossible to write dotted lists this way, so we need additional syntax for them. : a b c; (a b . c)
: a b [c;d;e]; (a b c d e)
This is also useful for binding forms and all macros with (arg arg2 foo . body) arglists : let var val [ (let var val
m-expr; s-expr
m-expr; s-expr
m-expr s-expr)
];
All infix-operators are n-ary, a < b < c; (< a b c)
this may not be what you want, but I don't want to second-guess programmers who override their fixed-arity functions, so use caution: a is b is c; (is a b c d)
- a - b; (- a b)
(-[a])- b; (- (- a) b)
You can work around this by writing a macro that wraps a fixed-arity function and changing the m-opswap function to replace it with your macro.Implementation details: 1.mzscheme-read is used to read the symbols and everything that is not delimited by () or []. This means that #\newline, `(a ',b), and {a b c} are read with mzscheme-read.
However, this does not disable restructuring of expressions which have subexpressions of this kind, so: m-expr read as
cons{a b}; (cons a b)
{x}y; ((x) . y)
2.Developed with anarki, not tested on arc2URL: http://placebo.hpi.uni-potsdam.de/~robert.pfeiffer/arc/ |