This commit is contained in:
greg 2017-12-07 19:54:53 -08:00
parent f6d047e3b8
commit faed1d6f25
1 changed files with 13 additions and 4 deletions

View File

@ -59,7 +59,15 @@ impl EvaluatorState {
match operator { match operator {
SymbolAtom(ref sym) => match &sym[..] { SymbolAtom(ref sym) => match &sym[..] {
"quote" => operands, "quote" => operands,
"eq?" => unimplemented!(), "eq?" => match operands {
Cons(box lhs, box Cons(box rhs, _)) => {
match lhs == rhs {
true => True,
false => False,
}
},
_ => True,
},
"cons" => match operands { "cons" => match operands {
Cons(box cadr, box Cons(box caddr, box Nil)) => { Cons(box cadr, box Cons(box caddr, box Nil)) => {
let newl = self.eval(cadr)?; let newl = self.eval(cadr)?;
@ -77,8 +85,8 @@ impl EvaluatorState {
_ => return Err(format!("called cdr with a non-pair argument")), _ => return Err(format!("called cdr with a non-pair argument")),
}, },
"atom?" => match operands { "atom?" => match operands {
Cons(_, _) => SymbolAtom(format!("#f")), Cons(_, _) => False,
_ => SymbolAtom(format!("#t")), _ => True,
}, },
"define" => unimplemented!(), "define" => unimplemented!(),
"lambda" => unimplemented!(), "lambda" => unimplemented!(),
@ -113,7 +121,8 @@ enum Token {
NumLiteral(u64), NumLiteral(u64),
} }
#[derive(Debug)] //TODO make this notion of Eq more sophisticated
#[derive(Debug, PartialEq)]
enum Sexp { enum Sexp {
SymbolAtom(String), SymbolAtom(String),
StringAtom(String), StringAtom(String),