2023-02-07 02:07:53 -05:00
|
|
|
use std::rc::Rc;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub enum Form {
|
|
|
|
|
Int(i32),
|
|
|
|
|
Symbol(String),
|
|
|
|
|
Pair(Rc<Form>,Rc<Form>),
|
2023-02-07 13:00:15 -05:00
|
|
|
DeriComb { se: Rc<Form>, de: Option<String>, params: Rc<Form>, body: Rc<Form> },
|
2023-02-07 02:07:53 -05:00
|
|
|
PrimComb(String, fn(Rc<Form>, Rc<Form>) -> Rc<Form>),
|
|
|
|
|
Nil,
|
|
|
|
|
}
|
|
|
|
|
impl Form {
|
|
|
|
|
pub fn int(&self) -> Option<i32> {
|
|
|
|
|
match self {
|
|
|
|
|
Form::Int(i) => Some(*i),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pub fn sym(&self) -> Option<&str> {
|
|
|
|
|
match self {
|
|
|
|
|
Form::Symbol(s) => Some(s),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pub fn car(&self) -> Option<Rc<Form>> {
|
|
|
|
|
match self {
|
|
|
|
|
Form::Pair(car, cdr) => Some(Rc::clone(car)),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pub fn cdr(&self) -> Option<Rc<Form>> {
|
|
|
|
|
match self {
|
|
|
|
|
Form::Pair(car, cdr) => Some(Rc::clone(cdr)),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|