public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) { bool deffun = false; if ((args.Car as ScheminPair) != null) { deffun = true; } if (!deffun) { ScheminAtom symbol = (ScheminAtom) args.ElementAt(0); IScheminType definition = args.ElementAt(1); if (env.bindings.ContainsKey(symbol.Name)) { env.RemoveBinding(symbol); env.AddBinding(symbol, definition); } else { env.AddBinding(symbol, definition); } return new ScheminPair(); } else { ScheminPair arguments = (ScheminPair) args.Car; ScheminPair expression = args.ListCdr(); ScheminAtom name = (ScheminAtom) arguments.Car; IScheminType lamParams = arguments.Cdr; if (lamParams == null) lamParams = new ScheminPair(); ScheminPair lamArgs = new ScheminPair(lamParams, expression); ScheminLambda lam = new ScheminLambda(lamArgs, env); if (env.bindings.ContainsKey(name.Name)) { env.RemoveBinding(name); env.AddBinding(name, lam); } else { env.AddBinding(name, lam); } return new ScheminPair(); } }
public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) { ScheminAtom symbol = (ScheminAtom) args.Car; ScheminLambda definition = (ScheminLambda) args.ElementAt(1); ScheminRewriter rewriter = new ScheminRewriter(definition, env); if (env.bindings.ContainsKey(symbol.Name)) { env.RemoveBinding(symbol); env.AddBinding(symbol, rewriter); } else { env.AddBinding(symbol, rewriter); } return new ScheminPair(); }
public override IScheminType Execute(Environment env, Evaluator eval, ScheminList args) { bool deffun = false; if ((args.Car() as ScheminList) != null) { deffun = true; } if (!deffun) { ScheminAtom symbol = (ScheminAtom) args.Car(); IScheminType definition = args.Cdr().Car(); if (env.bindings.ContainsKey(symbol.Name)) { env.RemoveBinding(symbol); env.AddBinding(symbol, definition); } else { env.AddBinding(symbol, definition); } return new ScheminList(false); } else { ScheminList arguments = (ScheminList) args.Car(); ScheminList expression = args.Cdr(); ScheminAtom name = (ScheminAtom) arguments.Car(); ScheminList argSymbols = arguments.Cdr(); ScheminList lamArgs = new ScheminList(argSymbols, expression); lamArgs.UnQuote(); ScheminLambda lam = new ScheminLambda(lamArgs, env); if (env.bindings.ContainsKey(name.Name)) { env.RemoveBinding(name); env.AddBinding(name, lam); } else { env.AddBinding(name, lam); } return new ScheminList(false); } }