public override LispObject Eval(Cons body, LispEnvironment env) { var testForm = Car.Of(body); var thenForm = Car.Of(Cdr.Of(body)); var elseForm = Car.Of(Cdr.Of(Cdr.Of(body))); if (env.Eval(testForm).IsTrue) { return env.Eval(thenForm); } return env.Eval(elseForm); }
public override LispObject Eval(Cons body, LispEnvironment env) { var varForms = body.Car.As<Cons>(); var varSymbols = varForms.Select(x => x.As<Cons>().Car.As<Symbol>()).ToList(); var varInitForms = varForms.Select(x => x.As<Cons>().Cdr.As<Cons>().Car).ToList(); var varStepForms = varForms.Select(x => x.As<Cons>().Cdr.As<Cons>().Cdr.As<Cons>().Car).ToList(); var cadr = body.Cdr.As<Cons>().Car.As<Cons>(); var testForm = cadr.Car; var resultForms = cadr.Cdr.As<Cons>(); var doBody = body.Cdr.As<Cons>().Cdr.As<Cons>(); var doEnv = new LispEnvironment(env); SetInitValues(doEnv, varSymbols, varInitForms); while (doEnv.Eval(testForm).IsNil) { new Progn().Eval(doBody, doEnv); SetStepValues(doEnv, varSymbols, varStepForms); } return new Progn().Eval(resultForms, doEnv); }
protected override void SetStepValues(LispEnvironment doEnv, List<Symbol> varSymbols, List<LispObject> varStepForms) { for (int i = 0; i < varSymbols.Count; i++) { var val = doEnv.Eval(varStepForms[i]); doEnv.SetValue(varSymbols[i], val); } }
protected override void SetInitValues(LispEnvironment doEnv, List<Symbol> varSymbols, List<LispObject> varInitForms) { for (int i = 0; i < varSymbols.Count; i++) { var val = doEnv.Eval(varInitForms[i]); doEnv.AddBinding(varSymbols[i], val); } }
public override LispObject Eval(Cons body, LispEnvironment env) { var symbol = Car.Of(body).As<Symbol>(); var value = env.Eval(Car.Of(Cdr.Of(body))); env.SetValue(symbol, value); return value; }
public override LispObject Apply(Cons arguments, LispEnvironment env) { return env.Eval(arguments.Car); }