public static void BindFormalTree(KObject formal, KObject vals, KEnvironment env, KObject ctxt = null) { if (ctxt == null) { ctxt = formal; } if (formal is KSymbol) { env.Bind(((KSymbol)formal).Value, vals); } else if (formal is KIgnore) { return; } else if (formal is KNil && vals is KNil) { return; } else if (formal is KPair && vals is KPair) { KPair f = formal as KPair; KPair v = vals as KPair; BindFormalTree(f.Car, v.Car, env, ctxt); BindFormalTree(f.Cdr, v.Cdr, env, ctxt); } else { throw new RuntimeException("Can't bind formal tree of " + ctxt.Write()); } }
private static RecursionResult <KObject> combineOp(KOperative op, KObject operands, KEnvironment env, Continuation <KObject> cont) { if (null == op.Expr) { if (op is ICombinable) { return((op as ICombinable).Combine(operands, env, cont)); } return(CPS.Error <KObject>("Primitive without implementation!" + op.Write(), cont)); } KEnvironment local = new KEnvironment(op.staticenv); if (!(op.EFormal is KIgnore)) { local.Bind(((KSymbol)op.EFormal).Value, env); } BindFormalTree(op.Formals, operands, local); return(CPS.PassTo <KObject>(() => Evaluator.rceval(op.Expr, local, cont))); }
private static void ExtendGroundEnv(string symbol, KObject value) { init(); GroundEnv.Bind(symbol, value); }