Guest User

Untitled

a guest
May 21st, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #![feature(trace_macros)]
  2. #![feature(macro_literal_matcher)]
  3.  
  4. //trace_macros!(true);
  5.  
  6. macro_rules! lisp{
  7. {(define $a:tt $b:tt)} => {let lisp!($a) = lisp!($b)};
  8. {(begin $($a:tt)*)} => {{$(lisp!{$a});*}};
  9. {(lambda ($($a:tt)*) $b:tt)} => {(|$($a),*|lisp!{$b})};
  10. {(($($a:tt)*) $($b:tt)*)} => {lisp!{($($a)*)}($(lisp!{$b}),*)};
  11. {($a:tt $($b:tt)*)} => {lisp!($a)($(lisp!{$b}),*)};
  12. {$a:literal} => {$a};
  13. {$a:ident} => {$a};
  14. }
  15.  
  16. fn plus(x:i32,y:i32) -> i32 {
  17. println!("{}+{}={}",x,y,x+y);
  18. x+y
  19. }
  20.  
  21. fn main() {
  22. println!("{}",lisp!{
  23. (begin
  24. (define plus3
  25. (lambda (x y z)
  26. (plus x (plus y z))))
  27. (define a 1)
  28. (define b (plus a 2))
  29. (define c (plus3 a b 3))
  30. (plus3 (plus a b) (plus b c) (plus c a)))
  31. });
  32. }
Add Comment
Please, Sign In to add comment