Artifact 7e23af883e94d99022443b551157e24afa3375ba
- File
sample/ast.pmy
- 2010-11-24 13:22:04 - part of checkin [f9c31f3cd8] on branch trunk - Fixed the null dereference bug when directly wrote "case 1 when 2: 3" in REPL. It was due to null LexPosition in the AST. Now AST.pos !is null is an invariant of AST. (user: kinaba) [annotate]
1 def reverse(lst, acc) 2 { 3 case(lst) 4 when {car:a, cdr: d}: reverse(d, {car:a, cdr:acc}) 5 when {}: acc 6 }; 7 8 @macro reverseArgs(e) {@value( 9 var ev = @macro(e); 10 case(ev) 11 when {is:"App", fun:f, args:a}: 12 ( 13 ev {args: reverse(a, {})} 14 # {is:"App", fun:f, args:reverse(a, {})} 15 ) 16 when _ : 17 ( 18 ev 19 ) 20 )}; 21 22 def main() 23 { 24 print( reverseArgs(1 + 2) ); 25 print( reverseArgs(1 - 2) ); 26 }; 27 28 main()