Created
December 10, 2020 11:51
-
-
Save mutsune/b4887dd69461c95becd02042e33e34bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(PartialEq)] | |
pub enum Class { | |
Var, | |
Function, | |
List, | |
Str, | |
Int, | |
Double, | |
} | |
struct Cons { | |
class: Class, | |
symbol: String, | |
cdr: Option<Box<Cons>>, | |
} | |
impl Cons { | |
pub fn new(class: Class, symbol: String, cdr: Option<Cons>) -> Cons { | |
Cons { | |
class, | |
symbol, | |
cdr: match cdr { | |
Some(x) => Some(Box::new(x)), | |
None => None, | |
}, | |
} | |
} | |
} | |
fn main() { | |
let v = Cons::new(Class::Str, "foo".to_string(), None); | |
let v = Cons::new(Class::Str, "bar".to_string(), Some(v)); | |
println!("{}", v.symbol) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment