Exemplo n.º 1
0
        public static void Neq(Evaluator eval, StackFrame frame)
        {
            var args = frame.args;

            //  Особый механизм - сравнение всего
            for (Atom iter = args; iter != null && iter.next != null; iter = iter.next)
            {
                if (StructureUtils.Compare((Atom)iter.value, (Atom)iter.next.value))
                {
                    eval.Return(Atoms.FALSE);
                    return;
                }
            }

            eval.Return(Atoms.TRUE);
        }
Exemplo n.º 2
0
        private static void SetCdr(Evaluator eval, StackFrame frame)
        {
            var  args = frame.args;
            Atom list = (Atom)args?.value;

            if (list.type != AtomType.Pair)
            {
                throw new ArgumentException("Argument must be List!");
            }

            if (StructureUtils.Compare(list, Atoms.EMPTY))
            {
                throw new ArgumentException("Can't modyficate base EMPTY list!");
            }

            list.next = (Atom)args.next.value;

            eval.Return(list.next);
        }
Exemplo n.º 3
0
        private static void Contains(Evaluator eval, StackFrame frame)
        {
            var  args  = frame.args;
            Atom list  = args?.atom;
            Atom value = args?.next?.atom;

            if (list == null || !list.IsPair)
            {
                throw new ArgumentException("First argument must be list!");
            }

            bool contains = false;

            for (Atom iter = list; iter != null; iter = iter.next)
            {
                if (StructureUtils.Compare(value, iter.atom))
                {
                    contains = true;
                    break;
                }
            }

            eval.Return(contains ? Atoms.TRUE : Atoms.FALSE);
        }