public MalVal get(MalSymbol key) { Env e = find(key); if (e == null) { throw new Mal.types.MalException( "'" + key.getName() + "' not found"); } else { return e.data[key.getName()]; } }
public MalVal get(MalSymbol key) { Env e = find(key); if (e == null) { throw new Mal.types.MalException( "'" + key.getName() + "' not found"); } else { return(e.data[key.getName()]); } }
// eval static MalVal eval_ast(MalVal ast, Dictionary <string, MalVal> env) { if (ast is MalSymbol) { MalSymbol sym = (MalSymbol)ast; return((MalVal)env[sym.getName()]); } else if (ast is MalList) { MalList old_lst = (MalList)ast; MalList new_lst = ast.list_Q() ? new MalList() : (MalList) new MalVector(); foreach (MalVal mv in old_lst.getValue()) { new_lst.conj_BANG(EVAL(mv, env)); } return(new_lst); } else if (ast is MalHashMap) { var new_dict = new Dictionary <string, MalVal>(); foreach (var entry in ((MalHashMap)ast).getValue()) { new_dict.Add(entry.Key, EVAL((MalVal)entry.Value, env)); } return(new MalHashMap(new_dict)); } else { return(ast); } }
public Env find(MalSymbol key) { if (data.ContainsKey(key.getName())) { return this; } else if (outer != null) { return outer.find(key); } else { return null; } }
// eval static MalVal EVAL(MalVal orig_ast, Dictionary <string, MalVal> env) { MalVal a0; // Console.WriteLine("EVAL: " + printer._pr_str(orig_ast, true)); if (orig_ast is MalSymbol) { MalSymbol sym = (MalSymbol)orig_ast; return((MalVal)env[sym.getName()]); } else if (orig_ast is MalVector) { MalVector old_lst = (MalVector)orig_ast; MalVector new_lst = new MalVector(); foreach (MalVal mv in old_lst.getValue()) { new_lst.conj_BANG(EVAL(mv, env)); } return(new_lst); } else if (orig_ast is MalHashMap) { var new_dict = new Dictionary <string, MalVal>(); foreach (var entry in ((MalHashMap)orig_ast).getValue()) { new_dict.Add(entry.Key, EVAL((MalVal)entry.Value, env)); } return(new MalHashMap(new_dict)); } else if (!(orig_ast is MalList)) { return(orig_ast); } // apply list MalList ast = (MalList)orig_ast; if (ast.size() == 0) { return(ast); } a0 = ast[0]; if (!(a0 is MalSymbol)) { throw new Mal.types.MalError("attempt to apply on non-symbol '" + Mal.printer._pr_str(a0, true) + "'"); } MalFunc f = (MalFunc)EVAL(ast[0], env); MalList arguments = new MalList(); foreach (MalVal mv in ast.rest().getValue()) { arguments.conj_BANG(EVAL(mv, env)); } return(f.apply(arguments)); }
// eval public static bool starts_with(MalVal ast, string sym) { if (ast is MalList && !(ast is MalVector)) { MalList list = (MalList)ast; if (list.size() == 2 && list[0] is MalSymbol) { MalSymbol a0 = (MalSymbol)list[0]; return(a0.getName() == sym); } } return(false); }
public Env find(MalSymbol key) { if (data.ContainsKey(key.getName())) { return(this); } else if (outer != null) { return(outer.find(key)); } else { return(null); } }
public Env set(MalSymbol key, MalVal value) { data[key.getName()] = value; return this; }
public Env set(MalSymbol key, MalVal value) { data[key.getName()] = value; return(this); }