Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(trace_macros)]
- #![feature(macro_literal_matcher)]
- //trace_macros!(true);
- macro_rules! lisp{
- {(define $a:tt $b:tt)} => {let lisp!($a) = lisp!($b)};
- {(begin $($a:tt)*)} => {{$(lisp!{$a});*}};
- {(lambda ($($a:tt)*) $b:tt)} => {(|$($a),*|lisp!{$b})};
- {(($($a:tt)*) $($b:tt)*)} => {lisp!{($($a)*)}($(lisp!{$b}),*)};
- {($a:tt $($b:tt)*)} => {lisp!($a)($(lisp!{$b}),*)};
- {$a:literal} => {$a};
- {$a:ident} => {$a};
- }
- fn plus(x:i32,y:i32) -> i32 {
- println!("{}+{}={}",x,y,x+y);
- x+y
- }
- fn main() {
- println!("{}",lisp!{
- (begin
- (define plus3
- (lambda (x y z)
- (plus x (plus y z))))
- (define a 1)
- (define b (plus a 2))
- (define c (plus3 a b 3))
- (plus3 (plus a b) (plus b c) (plus c a)))
- });
- }
Add Comment
Please, Sign In to add comment