/// <summary> /// Gets an <see cref="OpenLispSymbol"/> from <see cref="Env"/>. /// </summary> /// <param name="key"></param> /// <returns></returns> public OpenLispVal Get(OpenLispSymbol key) { Env e = Find(key); if (e == null) { throw new OpenLispException("'" + key.Value + "' not found"); } return(e._data[key.Value]); }
/// <summary> /// Expands a macro. /// /// TODO: refactor to move to <see cref="OpenLisp.Core.StaticClasses.CoreNameSpace"/>. /// </summary> /// <param name="abstractSyntaxTree"></param> /// <param name="environment"></param> /// <returns></returns> public static OpenLispVal MacroExpand(OpenLispVal abstractSyntaxTree, Env environment) { while (IsMacroCall(abstractSyntaxTree, environment)) { OpenLispSymbol caputPrimus = (OpenLispSymbol)((OpenLispList)abstractSyntaxTree)[0]; OpenLispFunc macro = (OpenLispFunc)environment.Get(caputPrimus); abstractSyntaxTree = macro.Apply(((OpenLispList)abstractSyntaxTree).Rest()); } return(abstractSyntaxTree); }
/// <summary> /// Sets an <see cref="OpenLispSymbol"/> key's value to an instance of <see cref="OpenLispVal"/>. /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <returns></returns> public Env Set(OpenLispSymbol key, OpenLispVal value) { _data[key.Value] = value; return(this); }
/// <summary> /// Finds an <see cref="OpenLispSymbol"/> in <see cref="Env._data"/>. /// </summary> /// <param name="key"></param> /// <returns></returns> public Env Find(OpenLispSymbol key) { return(_data.ContainsKey(key.Value) ? this : _outer?.Find(key)); }