git @ Cat's Eye Technologies Robin / 338b3ca
Add example code that traverses a Robin expression. Chris Pressey 4 years ago
1 changed file(s) with 22 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 (require let) (require choose) (require fold)
1
2 ;''Demonstration of some code that traverses an expression, in preparation for
3 writing some actual Robin static analysis code, in Robin.''
4
5 (define traverse-expr (fun (expr)
6 (bind traverse-r (fun (self expr acc)
7 (if (list? expr)
8 (let ((fname (head expr))
9 (args (tail expr))
10 (acc1 (prepend fname acc))
11 (visit (fun (x a) (self self x a)))
12 (acc2 (fold visit acc1 args)))
13 acc2)
14 (prepend expr acc)))
15 (traverse-r traverse-r expr ()))))
16
17 (define little-program (literal
18 (add (mul 7 8) (mul 5 9))
19 ))
20
21 (display (traverse-expr little-program))