Value normalizeSyntax(CompileContext ctx, Value s) { if (!s.Car.IsSymbol) { return(s); } Value v; if (rootEnv_.TryGet(s.Car.AsSymbol, out v)) { if (!v.IsClosure) { return(s); } Closure closure = v.AsClosure; if (!closure.IsSyntax) { return(s); } var expanded = vm_.Apply(closure, s, C.Nil, C.Nil); return(normalizeSexp(ctx, expanded)); } else { return(s); } }
public void ExportFromEnv(Env env) { foreach (var symbol in Exports) { Value val; if (env.TryGet(symbol, out val)) { Bindings[symbol] = val; } else { throw new LispException($"Not exported {symbol}"); } } }
public bool TryGet(Symbol symbol, out Value val) { Value found; if (dict_.TryGetValue(symbol, out found)) { val = found; return(true); } else if (up_ != null) { return(up_.TryGet(symbol, out val)); } else { val = C.Nil; return(false); } }