示例#1
0
        private List <KGuard> assignGuards(KObject clauses)
        {
            List <KGuard> result = new List <KGuard>();

            if (clauses is KPair)
            {
                KPair.Foreach(x =>
                {
                    int length = KPair.Length(x);
                    if (length == 2)
                    {
                        KContinuation selector   = First(x) as KContinuation;
                        KApplicative interceptor = Second(x) as KApplicative;
                        if (selector == null || interceptor == null)
                        {
                            throw new RuntimeException("guard-continuation: invalid clause, wrong types");
                        }
                        result.Add(new KGuard {
                            Selector = selector, Interceptor = interceptor
                        });
                    }
                    else
                    {
                        throw new RuntimeException("guard-continuation: invalid clause");
                    }
                }, clauses);
            }
            return(result);
        }
示例#2
0
 private static RecursionResult <KObject> combineApp(KApplicative app, KObject operands, KEnvironment env, Continuation <KObject> cont)
 {
     while (app.Combiner is KApplicative)
     {
         app = app.Combiner as KApplicative;
     }
     return(combineOp(app.Combiner as KOperative, operands, env, cont));
 }
示例#3
0
        public override object Do(KObject args, KEnvironment env, Continuation <KObject> cont)
        {
            CPara(args, 0);
            this.id = counter++;
            KApplicative e  = new KApplicative(new PEncapE(id));
            KApplicative p  = new KApplicative(new PEncapP(id));
            KApplicative d  = new KApplicative(new PEncapD(id));
            KPair        p3 = new KPair(d, new KNil());
            KPair        p2 = new KPair(p, p3);
            KPair        p1 = new KPair(e, p2);

            return(p1);
        }
示例#4
0
        public override RecursionResult <KObject> Combine(KObject args, KEnvironment env, Continuation <KObject> cont)
        {
            var res = CheckParameter(args, 0, "make-encapsulation-type");

            if (res != null)
            {
                return(CPS.Error(res, cont));
            }
            this.id = counter++;
            KApplicative e  = new KApplicative(new PEncapE(id));
            KApplicative p  = new KApplicative(new PEncapP(id));
            KApplicative d  = new KApplicative(new PEncapD(id));
            KPair        p3 = new KPair(d, new KNil(), true);
            KPair        p2 = new KPair(p, p3, true);
            KPair        p1 = new KPair(e, p2, true);

            return(Return(p1, cont));
        }
示例#5
0
        public override RecursionResult <KObject> Combine(KObject args, KEnvironment env, Continuation <KObject> cont)
        {
            int len = KPair.Length(args);

            if (len < 2 || len > 3)
            {
                return(CPS.Error("extend-continuation: argument mismatch", cont));
            }
            KContinuation argC = First(args) as KContinuation;
            KApplicative  argA = Second(args) as KApplicative;
            KEnvironment  argE = len == 3 ? Third(args) as KEnvironment : new KEnvironment();

            if (argC == null || argA == null || argE == null)
            {
                return(CPS.Error("extend-continuation: mismatching arguments", cont));
            }

            var nc = new Continuation <KObject>((val, ctxt) =>
            {
                return(CPS.Next(() => Evaluator.rceval(new KPair(argA.Combiner, val, true), argE, argC.Value), argC.Value));
            }, argC.Value, argA);

            return(Return(new KContinuation(nc), cont));
        }