Package org.jatha.dynatype

Examples of org.jatha.dynatype.LispValue


    public MacroexpandPrimitive(final Jatha lisp) {
        super(lisp, "MACROEXPAND", 1);
    }
   
    public void Execute(final SECDMachine machine) {
        final LispValue form = machine.S.pop();
        LispValue now = expand(form);
        LispValue lastOne = form;
        while(now != lastOne && now.basic_consp() && !(now == f_lisp.NIL)) {
            lastOne = now;
            now = expand(now);
        }
        machine.S.push(now);
View Full Code Here


        machine.S.push(now);
        machine.C.pop();
    }

    private LispValue expand(final LispValue form) {
        final LispValue carForm = form.car();
        if(carForm.fboundp() == f_lisp.T && carForm.symbol_function() != null && carForm.symbol_function().basic_macrop()) {
            return f_lisp.eval(f_lisp.makeCons(f_lisp.EVAL.intern("%%%" + carForm.symbol_name().toStringSimple(),(LispPackage)f_lisp.findPackage("SYSTEM")),quoteList(form.cdr())));
        } else {
            return form;
        }
    }
View Full Code Here

            return form;
        }
    }

    private LispValue quoteList(final LispValue intern) {
        LispValue ret = f_lisp.NIL;
        for(final java.util.Iterator iter = intern.iterator();iter.hasNext();) {
            final LispValue curr = (LispValue)iter.next();
            ret = f_lisp.makeCons(f_lisp.makeList(f_lisp.QUOTE,curr),ret);
        }
        return ret.nreverse();
    }
View Full Code Here

        list6_b_default = null;
        list7_b_default = null;
    }

    public void testNormalArguments() {
        final LispValue arg1 = lisp.makeInteger(17);
        final LispValue arg2 = lisp.makeString("Ojsan sa");
       
        final LispValue argList1 = lisp.makeList(arg1,arg2);
        final Map outp = list1.parse(argList1);
        assertEquals("Argument 1 should be correct",arg1,outp.get(a_sym));
        assertEquals("Argument 2 should be correct",arg2,outp.get(b_sym));
    }
View Full Code Here

        assertEquals("Argument 1 should be correct",arg1,outp.get(a_sym));
        assertEquals("Argument 2 should be correct",arg2,outp.get(b_sym));
    }

    public void testOptionalArguments() {
        final LispValue arg1 = lisp.makeInteger(17);
        final LispValue arg2 = lisp.makeString("Ojsan sa");
        final LispValue argList1 = lisp.makeList(arg1,arg2);
        final LispValue argList2 = lisp.makeList(arg1);
        final LispValue argList3 = lisp.makeList(arg1,list2_b_default);
        final Map outp1 = list2.parse(argList1);
        final Map outp2 = list2.parse(argList2);
        final Map outp3 = list2.parse(argList3);
        assertEquals("Argument 1 should be correct",arg1,outp1.get(a_sym));
        assertEquals("Argument 2 should be correct",arg2,outp1.get(b_sym));
View Full Code Here

        assertEquals("Argument 1 should be correct",arg1,outp3.get(a_sym));
        assertEquals("Argument 2 should be correct",list2_b_default,outp3.get(b_sym));
    }

    public void testOptionalArgumentsWithInternalDefaults() {
        final LispValue arg1 = lisp.makeInteger(17);
        final LispValue argList = lisp.makeList(arg1);
        final Map outp = list2_x.parse(argList);
        assertEquals("Argument 1 should be correct",arg1,outp.get(a_sym));
        assertEquals("Argument 2 should be correct",arg1,outp.get(b_sym));
    }   
View Full Code Here

        assertEquals("Argument 1 should be correct",arg1,outp.get(a_sym));
        assertEquals("Argument 2 should be correct",arg1,outp.get(b_sym));
    }   

    public void testOptionalArgumentsWithInternalDefaultForm() {
        final LispValue arg1 = lisp.makeInteger(17);
        final LispValue expected = lisp.makeInteger(20);
        final LispValue argList = lisp.makeList(arg1);
        final Map outp = list2_y.parse(argList);
        assertEquals("Argument 1 should be correct",arg1,outp.get(a_sym));
        assertEquals("Argument 2 should be correct",expected.toStringSimple(),((LispValue)outp.get(b_sym)).toStringSimple());
    }   
View Full Code Here

        assertEquals("Argument 1 should be correct",arg1,outp.get(a_sym));
        assertEquals("Argument 2 should be correct",expected.toStringSimple(),((LispValue)outp.get(b_sym)).toStringSimple());
    }   

    public void testOptionalArgumentsWithSupplied() {
        final LispValue arg1 = lisp.makeInteger(17);
        final LispValue arg2 = lisp.makeString("Ojsan sa");
        final LispValue argList1 = lisp.makeList(arg1,arg2);
        final LispValue argList2 = lisp.makeList(arg1);
        final LispValue argList3 = lisp.NIL;
        final Map outp1 = list3.parse(argList1);
        final Map outp2 = list3.parse(argList2);
        final Map outp3 = list3.parse(argList3);

        assertEquals("Argument 1 should be correct",arg1,outp1.get(a_sym));
View Full Code Here

        assertEquals("Argument 1 supplied should be correct",lisp.NIL,outp3.get(b_sym));
        assertEquals("Argument 2 supplied should be correct",lisp.NIL,outp3.get(d_sym));
    }

    public void testOptionalArgumentsWithSuppliedAndRest() {
        final LispValue arg1 = lisp.makeInteger(17);
        final LispValue arg2 = lisp.makeString("Ojsan sa");
        final LispValue argList1 = lisp.makeList(arg1,arg2);
        final LispValue argList2 = lisp.makeList(arg1);
        final LispValue argList3 = lisp.NIL;
        final Map outp1 = list4.parse(argList1);
        final Map outp2 = list4.parse(argList2);
        final Map outp3 = list4.parse(argList3);

        assertEquals("Argument 1 should be correct",arg1,outp1.get(a_sym));
        assertEquals("Argument 2 should be correct",arg2,outp1.get(c_sym));
        assertEquals("Argument 1 supplied should be correct",lisp.T,outp1.get(b_sym));
        assertEquals("Argument 2 supplied should be correct",lisp.T,outp1.get(d_sym));
        assertEquals("Rest argument should be correct",lisp.NIL,outp1.get(x_sym));

        assertEquals("Argument 1 should be correct",arg1,outp2.get(a_sym));
        assertEquals("Argument 2 should be correct",list4_c_default,outp2.get(c_sym));
        assertEquals("Argument 1 supplied should be correct",lisp.T,outp2.get(b_sym));
        assertEquals("Argument 2 supplied should be correct",lisp.NIL,outp2.get(d_sym));
        assertEquals("Rest argument should be correct",lisp.NIL,outp2.get(x_sym));

        assertEquals("Argument 1 should be correct",list4_a_default,outp3.get(a_sym));
        assertEquals("Argument 2 should be correct",list4_c_default,outp3.get(c_sym));
        assertEquals("Argument 1 supplied should be correct",lisp.NIL,outp3.get(b_sym));
        assertEquals("Argument 2 supplied should be correct",lisp.NIL,outp3.get(d_sym));
        assertEquals("Rest argument should be correct",lisp.NIL,outp3.get(x_sym));

        final LispValue argList4 = lisp.makeList(arg1,arg2,arg1);
        final LispValue argList5 = lisp.makeList(arg1,arg2,arg1,arg2);
        final LispValue argList6 = lisp.makeList(arg1,arg2,arg1).append(lisp.makeList(arg2,arg1));
        final LispValue expected4 = lisp.makeList(arg1);
        final LispValue expected5 = lisp.makeList(arg1,arg2);
        final LispValue expected6 = lisp.makeList(arg1,arg2,arg1);

        final Map outp4 = list4.parse(argList4);
        final Map outp5 = list4.parse(argList5);
        final Map outp6 = list4.parse(argList6);

        assertEquals("Argument 1 should be correct",arg1,outp4.get(a_sym));
        assertEquals("Argument 2 should be correct",arg2,outp4.get(c_sym));
        assertEquals("Argument 1 supplied should be correct",lisp.T,outp4.get(b_sym));
        assertEquals("Argument 2 supplied should be correct",lisp.T,outp4.get(d_sym));
        assertTrue("Rest argument should be correct",expected4.equal((LispValue)outp4.get(x_sym)) == lisp.T);

        assertEquals("Argument 1 should be correct",arg1,outp5.get(a_sym));
        assertEquals("Argument 2 should be correct",arg2,outp5.get(c_sym));
        assertEquals("Argument 1 supplied should be correct",lisp.T,outp5.get(b_sym));
        assertEquals("Argument 2 supplied should be correct",lisp.T,outp5.get(d_sym));
        assertTrue("Rest argument should be correct",expected5.equal((LispValue)outp5.get(x_sym)) == lisp.T);

        assertEquals("Argument 1 should be correct",arg1,outp6.get(a_sym));
        assertEquals("Argument 2 should be correct",arg2,outp6.get(c_sym));
        assertEquals("Argument 1 supplied should be correct",lisp.T,outp6.get(b_sym));
        assertEquals("Argument 2 supplied should be correct",lisp.T,outp6.get(d_sym));
        assertTrue("Rest argument should be correct",expected6.equal((LispValue)outp6.get(x_sym)) == lisp.T);
    }
View Full Code Here

        assertEquals("Argument 2 supplied should be correct",lisp.T,outp6.get(d_sym));
        assertTrue("Rest argument should be correct",expected6.equal((LispValue)outp6.get(x_sym)) == lisp.T);
    }

    public void testNormalKeyParameters() {
        final LispValue arg1 = lisp.makeInteger(17);
        final LispValue arg2 = lisp.makeString("Ojsan sa");
        final LispValue arg3 = lisp.makeInteger(42);
        final LispValue arg4 = lisp.makeString("well well well");
       
        final LispValue argList1 = lisp.makeList(arg1,arg2);
        final LispValue argList2 = lisp.makeList(arg1,arg2,c_key,arg3);
        final LispValue argList3 = lisp.makeList(arg1,arg2,c_key).append(lisp.makeList(arg3,d_key,arg4));
        final LispValue argList4 = lisp.makeList(arg1,arg2,d_key).append(lisp.makeList(arg4,c_key,arg3));

        final Map outp1 = list5.parse(argList1);
        final Map outp2 = list5.parse(argList2);
        final Map outp3 = list5.parse(argList3);
        final Map outp4 = list5.parse(argList4);
View Full Code Here

TOP

Related Classes of org.jatha.dynatype.LispValue

Copyright © 2018 www.massapicom. 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.