Skip to content

Instantly share code, notes, and snippets.

@mutsune
Created December 10, 2020 11:51
Show Gist options
  • Save mutsune/b4887dd69461c95becd02042e33e34bd to your computer and use it in GitHub Desktop.
Save mutsune/b4887dd69461c95becd02042e33e34bd to your computer and use it in GitHub Desktop.
#[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