コード例 #1
0
ファイル: Applier.cs プロジェクト: TommyPersson/Yalla
        public object ApplyDefMacro(IList<object> arguments, Environment environment)
        {
            if (arguments.Count != 3)
            {
                throw new ArgumentException("Wrong number of arguments given to defmacro! Expected: " + 3);
            }

            var symbol = arguments.ElementAt(0) as SymbolNode;
            if (symbol == null)
            {
                throw new ArgumentException("First argument to defmacro not a symbol!");
            }

            var parameterList = arguments.ElementAt(1) as IList<object>;
            if (parameterList == null)
            {
                throw new ArgumentException("Second argument to defmacro not a parameterlist!");
            }

            var body = arguments.ElementAt(2);

            var macro = new ProcedureNode(parameterList.Cast<SymbolNode>(), new[] { body }, environment.CreateChildEnvironment(), true);

            environment.DefineSymbol(symbol, macro);

            return symbol;
        }
コード例 #2
0
ファイル: Applier.cs プロジェクト: TommyPersson/Yalla
        public object ApplyDef(IList<object> arguments, Environment environment)
        {
            if (arguments.Count != 2)
            {
                throw new ArgumentException("Wrong number of arguments given to def! Expected: " + 2);
            }

            var symbol = arguments.ElementAt(0) as SymbolNode;

            if (symbol == null)
            {
                throw new ArgumentException("First argument to def not a symbol!");
            }

            var valueForm = arguments.ElementAt(1);

            var result = evaluator.Evaluate(valueForm, environment);

            environment.DefineSymbol(symbol, result);

            return symbol;
        }