public static Object Cond(Cons args, Environment environment) { Cons clauses = args; while (clauses.Length() > 0) { if (clauses.Length() == 1) { // This is a default (else) clause, so just execute it return(Runtime.Eval(clauses.First(), environment)); } if (clauses.Length() >= 2) { if (Conversions.ObjectToBoolean(Runtime.Eval(clauses.First(), environment))) { return(Runtime.Eval(clauses.Second(), environment)); } else { clauses = (Cons)clauses.Cddr(); } } } return(null); }
public static Object And(Cons args, Environment environment) { foreach (Object item in args) { if (Conversions.ObjectToBoolean(Runtime.Eval(item, environment)) == false) { return(false); } } return(true); }
public static Object While(Cons args, Environment environment) { object test; while ((Conversions.ObjectToBoolean(test = Runtime.Eval(args.First(), environment)))) { foreach (object item in (Cons)args.Rest()) { Runtime.Eval(item, environment); } } return(test); }
public static Object For(Cons args, Environment environment) { Environment localEnvironment = new Environment(environment); Runtime.Eval(args.First(), localEnvironment); object test; while ((Conversions.ObjectToBoolean(test = Runtime.Eval(args.Second(), localEnvironment)))) { foreach (object item in (Cons)args.Cdddr()) { Runtime.Eval(item, localEnvironment); } Runtime.Eval(args.Third(), localEnvironment); } return(test); }
public static Object If(Cons args, Environment environment) { if (Conversions.ObjectToBoolean(Runtime.Eval(args.First(), environment))) { // Evaluate the then part return(Runtime.Eval(args.Second(), environment)); } else if (args.Length() > 2) { // Evaluate the optional else part return(Runtime.Eval(args.Third(), environment)); } else { return(null); } }
public static Object Not(Cons args, Environment environment) { return(!(Conversions.ObjectToBoolean(args.First()))); }