Examples of RippleList


Examples of net.fortytwo.ripple.model.RippleList

    }

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        NumericValue a, b, result;

        b = mc.toNumericValue(stack.getFirst());
        stack = stack.getRest();
        a = mc.toNumericValue(stack.getFirst());
        stack = stack.getRest();

        // Note: mod by zero simply does not yield a result.
        if (!b.isZero()) {
            result = a.mod(b);

            solutions.put(
                    stack.push(result));
        }
    }
View Full Code Here

Examples of net.fortytwo.ripple.model.RippleList

    }

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        // Note: a bad numeric value will cause an error.  However, an
        // out-of-range numeric value (e.g. -1 or a value which exceeds the
        // length of the list) will simply fail to produce a result.
        final int n = mc.toNumericValue(stack.getFirst()).intValue();
        if (0 > n) {
            return;
        }

        stack = stack.getRest();
        final RippleValue l = stack.getFirst();
        final RippleList rest = stack.getRest();

        Sink<RippleList> listSink = new Sink<RippleList>() {
            public void put(final RippleList list) throws RippleException {
                RippleList result = drop(list, n);
                if (null != result) {
                    solutions.put(
                            rest.push(result));
                }
            }
View Full Code Here

Examples of net.fortytwo.ripple.model.RippleList

    }

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        RippleValue a = stack.getFirst();
        stack = stack.getRest();

        String result = StringUtils.percentEncode(mc.toString(a));
        solutions.put(
                stack.push(StringLibrary.value(result, mc, a)));
    }
View Full Code Here

Examples of net.fortytwo.ripple.model.RippleList

        mc.toList(l, listSink);
    }

    private RippleList drop(final RippleList list,
                            final int n) {
        RippleList cur = list;

        for (int i = 0; i < n; i++) {
            if (cur.isNil()) {
                return null;
            }

            cur = cur.getRest();
        }

        return cur;
    }
View Full Code Here

Examples of net.fortytwo.ripple.model.RippleList

    }

    private void reduce(final RippleList stack) throws RippleException {

        //System.out.println("evaluating: " + stack);
        RippleList left = stack;
        RippleList right = mc.list();

        while (true) {
            //System.out.println("--");
            //System.out.println("\tleft: " + left);
            //System.out.println("\tright: " + right);

            if (left.isNil()) {
                if (right.isNil()) {
                    //System.out.println("adding solution: " + left);
                    solutions.add(left);
                }

                return;
            }
            RippleValue first = left.getFirst();
            final StackMapping f = first.getMapping();

            if (null == f) {
                if (right.isNil()) {
                    //System.out.println("adding solution: " + left);
                    solutions.add(left);
                    return;
                } else {
                    Closure c = new Closure(right.getFirst().getMapping(), first);
                    right = right.getRest();
                    left = left.getRest().push(new Operator(c));
                }
            } else {
                if (0 == f.arity()) {
                    Collector<RippleList> results = new Collector<RippleList>();
                    // Note: synchronous evaluation is required
                    // Note: stack context is trivial
                    f.apply(left.getRest(), results, mc);
                    for (RippleList s : results) {
                        RippleList i = s;
                        RippleList cur = right;
                        while (!cur.isNil()) {
                            i = i.push(cur.getFirst());
                            cur = cur.getRest();
                        }

                        //System.out.println("adding intermediate: " + i);
                        intermediates.add(i);
                    }
View Full Code Here

Examples of net.fortytwo.ripple.model.RippleList

        public void apply(final RippleList arg,
                          final Sink<RippleList> solutions,
                          final ModelConnection mc) throws RippleException {

            RippleList stack = arg;
            Decider decider = new Decider(stack);

            // Apply the criterion, sending the result into the Decider.
            solutions.put(stack.push(criterion).push(new Operator(decider)));
        }
View Full Code Here

Examples of net.fortytwo.ripple.model.RippleList

    }

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        String str, substr;
        int result;

        substr = mc.toString(stack.getFirst());
        stack = stack.getRest();
        str = mc.toString(stack.getFirst());
        stack = stack.getRest();

        result = str.lastIndexOf(substr);
        solutions.put(
                stack.push(mc.valueOf(result)));
    }
View Full Code Here

Examples of net.fortytwo.ripple.model.RippleList

    }

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        // Note: a bad numeric value will cause an error.  However, an
        // out-of-range numeric value (e.g. -1 or a value which exceeds the
        // length of the list) will simply fail to produce a result.
        final int n = mc.toNumericValue(stack.getFirst()).intValue();
        if (0 > n) {
            return;
        }

        stack = stack.getRest();
        final RippleValue l = stack.getFirst();
        final RippleList rest = stack.getRest();

        Sink<RippleList> listSink = new Sink<RippleList>() {
            public void put(final RippleList list) throws RippleException {
                RippleList result = take(list, n, mc.list());
                if (null != result) {
                    solutions.put(
                            rest.push(result));
                }
            }
View Full Code Here

Examples of net.fortytwo.ripple.model.RippleList

    }

    private RippleList take(final RippleList list,
                            final int n,
                            final RippleList nil) throws RippleException {
        RippleList cur = list;
        RippleList inverted = nil;

        for (int i = 0; i < n; i++) {
            if (cur.isNil()) {
                return null;
            }

            inverted = inverted.push(cur.getFirst());
            cur = cur.getRest();
        }

        return inverted.invert();
    }
View Full Code Here

Examples of net.fortytwo.ripple.model.RippleList

        public void apply(final RippleList arg,
                          final Sink<RippleList> solutions,
                          final ModelConnection mc) throws RippleException {

            RippleValue b;
            RippleList stack = arg;

            b = stack.getFirst();
            stack = stack.getRest();

            if (mc.toBoolean(b)) {
                solutions.put(rest);
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.