Some primitive implementations
This commit is contained in:
parent
72097fa125
commit
adc7be30a9
@ -49,28 +49,35 @@ impl EvaluatorState {
|
|||||||
fn new() -> EvaluatorState { EvaluatorState { } }
|
fn new() -> EvaluatorState { EvaluatorState { } }
|
||||||
fn eval(&mut self, expr: Sexp) -> Result<Sexp, String> {
|
fn eval(&mut self, expr: Sexp) -> Result<Sexp, String> {
|
||||||
use self::Sexp::*;
|
use self::Sexp::*;
|
||||||
println!("Eval'd sexp: {:?}", expr);
|
|
||||||
Ok(match expr {
|
Ok(match expr {
|
||||||
SymbolAtom(sym) => unimplemented!(),
|
SymbolAtom(sym) => unimplemented!(),
|
||||||
expr @ StringAtom(_) => expr,
|
expr @ StringAtom(_) => expr,
|
||||||
expr @ NumberAtom(_) => expr,
|
expr @ NumberAtom(_) => expr,
|
||||||
Cons(box car, box cdr) => {
|
Cons(box operator, box operands) => {
|
||||||
match car {
|
match operator {
|
||||||
SymbolAtom(ref sym) => match &sym[..] {
|
SymbolAtom(ref sym) => match &sym[..] {
|
||||||
"quote" => cdr,
|
"quote" => operands,
|
||||||
"eq?" => unimplemented!(),
|
"eq?" => unimplemented!(),
|
||||||
"cons" => match cdr {
|
"cons" => match operands {
|
||||||
Cons(box cadr, box Cons(box caddr, box Nil)) => {
|
Cons(box cadr, box Cons(box caddr, box Nil)) => {
|
||||||
println!("NEWL {:?}|| NEWR {:?}", cadr, caddr);
|
|
||||||
let newl = self.eval(cadr)?;
|
let newl = self.eval(cadr)?;
|
||||||
let newr = self.eval(caddr)?;
|
let newr = self.eval(caddr)?;
|
||||||
Cons(Box::new(newl), Box::new(newr))
|
Cons(Box::new(newl), Box::new(newr))
|
||||||
},
|
},
|
||||||
_ => return Err(format!("Bad arguments for cons")),
|
_ => return Err(format!("Bad arguments for cons")),
|
||||||
},
|
},
|
||||||
"car" => unimplemented!(),
|
"car" => match operands {
|
||||||
"cdr" => unimplemented!(),
|
Cons(box car, _) => car,
|
||||||
"atom?" => unimplemented!(),
|
_ => return Err(format!("called car with a non-pair argument")),
|
||||||
|
},
|
||||||
|
"cdr" => match operands {
|
||||||
|
Cons(_, box cdr) => cdr,
|
||||||
|
_ => return Err(format!("called cdr with a non-pair argument")),
|
||||||
|
},
|
||||||
|
"atom?" => match operands {
|
||||||
|
Cons(_, _) => SymbolAtom(format!("#f")),
|
||||||
|
_ => SymbolAtom(format!("#t")),
|
||||||
|
},
|
||||||
"define" => unimplemented!(),
|
"define" => unimplemented!(),
|
||||||
"lambda" => unimplemented!(),
|
"lambda" => unimplemented!(),
|
||||||
"cond" => unimplemented!(),
|
"cond" => unimplemented!(),
|
||||||
|
Loading…
Reference in New Issue
Block a user