Skip to content

Instantly share code, notes, and snippets.

@pjhades
Created February 1, 2018 22:09
Show Gist options
  • Save pjhades/b0bb8ea764b12d439ccc0ab7b2d4e269 to your computer and use it in GitHub Desktop.
Save pjhades/b0bb8ea764b12d439ccc0ab7b2d4e269 to your computer and use it in GitHub Desktop.
use std::boxed::Box;
#[derive(Debug, PartialEq)]
enum N {
V(Vec<Box<N>>),
S(Box<N>),
C(i32),
}
macro_rules! t {
( [ $( $n:tt ),+ ] ) => { Box::new(N::V( vec![ $( t!($n) ),+ ])) };
( ( $n:tt ) ) => { Box::new(N::S( t!($n) )) };
( $i:expr ) => { Box::new(N::C($i)) };
}
fn main() {
let n = Box::new(N::V(vec![
Box::new(N::S(Box::new(N::C(1)))),
Box::new(N::S(Box::new(N::C(2)))),
Box::new(N::S(Box::new(N::C(3))))
]));
let m = t! {
[
(1), (2), (3)
]
};
assert_eq!(n, m);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment