eq?
This commit is contained in:
parent
f6d047e3b8
commit
faed1d6f25
@ -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),
|
||||||
|
Loading…
Reference in New Issue
Block a user