コード例 #1
0
        private static void Preprocessor(Evaluator eval, StackFrame frame)
        {
            var  args = frame.args;
            Atom vars = StructureUtils.CloneTree((Atom)args?.value);
            Atom body = StructureUtils.CloneTree(args?.next);

            if (vars.type != AtomType.Pair && vars.type != AtomType.Symbol)
            {
                throw new ArgumentException("Args must be list or symbol!");
            }

            var ctx     = frame.context.value as Context;
            var closure = new Closure(ctx, vars, body, "preprocessor");

            closure.EvalArgs   = false;
            closure.EvalResult = false;

            eval.Return(new Atom(AtomType.Function, closure));
        }
コード例 #2
0
        private static void Syntax(Evaluator eval, StackFrame frame)
        {
            var args = frame.args;

            //  [tag before after]
            var(tag, before, after) = StructureUtils.Split3(args.atom);

            if (!tag.IsSymbol && !tag.IsString)
            {
                throw new ArgumentException("Tag must be string or symbol!");
            }
            if (!before.IsBool)
            {
                throw new ArgumentException("Eval args flag must be boolean!");
            }
            if (!after.IsBool)
            {
                throw new ArgumentException("Eval result flag must be boolean!");
            }

            Atom vars = StructureUtils.CloneTree(args?.next?.atom);
            Atom body = StructureUtils.CloneTree(args?.next?.next);

            if (vars.type != AtomType.Pair && vars.type != AtomType.Symbol)
            {
                throw new ArgumentException("Args must be list or symbol!");
            }

            var ctx     = frame.context.value as Context;
            var closure = new Closure(ctx, vars, body, (string)tag.value);

            closure.EvalArgs   = (bool)before.value;
            closure.EvalResult = (bool)after.value;

            eval.Return(new Atom(AtomType.Function, closure));
        }