Artifact 94485181e809cc7b0fcf748b3ee57855399df9a0
- File
sample/ast.pmy
- 2010-11-23 10:37:54 - part of checkin [5e924caac9] on branch trunk - added AST-rewriting macro sample. (user: kinaba) [annotate]
def reverse(lst, acc) { case(lst) when( {car:a, cdr: d} ) { reverse(d, {car:a, cdr:acc}) } when( {} ) { acc } }; @macro reverseArgs(e) {@value( var ev = @macro(e); case(ev) when( {is:"app", fun:f, args:a} ) { ev {args: reverse(a, {})} } when( _ ) { ev } )}; def main() { print( reverseArgs(1 + 2) ); print( reverseArgs(1 - 2) ); }; main()