Package org.jatha.dynatype

Examples of org.jatha.dynatype.LispValue


        jatha.start();
    }

    public XLoper execute(IFunctionContext context, String name, XLoper[] args) throws RequestException {
        try {
            LispValue inValue = makeList(args, findSize(args));
            LispValue result = jatha.eval(inValue);
            XLoper outValue = makeResult(result);
            return outValue;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RequestException(e);
View Full Code Here


            return makeValue(args[0]);
        } else {
            ArrayList l = new ArrayList();
            boolean quote = false;
            for (int i = 0; i < size; i++) {
                LispValue v = makeValue(args[i]);
                if (v != null)
                    l.add(v);
                if (i == 0 && !(v instanceof StandardLispSymbol)) {
                    quote = true;
                }
View Full Code Here

    }

    private LispValue makeValue(XLoper value) throws EOFException {
        if (value instanceof XLString) {
            String str = ((XLString) value).str;
            LispValue l = (LispValue) registry.get(str);
            if (l != null) {
                return l;
            } else {
                return jatha.parse(str);
            }
View Full Code Here


    // TEST SYMBOLS
    LispSymbol  x1 = lisp.makeSymbol("Mike");

    LispValue   l1 = lisp.makeCons(x1,  lisp.T);
    LispValue   l2 = lisp.makeCons(lisp.NIL, l1);

    show("L2: ", l2);

    LispValue   l3 = lisp.makeCons(x1, lisp.NIL);
    LispValue   l4 = lisp.makeCons(lisp.T,  l3);

    show("L4: ", l4);

    LispValue   l5 = lisp.makeCons(x1, lisp.NIL);
    LispValue   l6 = lisp.makeCons(l3, l1);

    show("L6: ", l6);


    // TEST Numbers

    LispInteger  i1 = lisp.makeInteger();
    LispInteger  i2 = lisp.makeInteger(5);
    LispInteger  i3 = lisp.makeInteger(273);

    LispValue   l7 = lisp.makeCons(i3, lisp.makeList(i2, i1));
    show("L7: ", l7);

    LispReal  r1 = lisp.makeReal();
    LispReal  r2 = lisp.makeReal(5.5);
    LispReal  r3 = lisp.makeReal(273.273273);

    LispValue   l8 = lisp.makeList(r3, r2, r1);
    show("L8: ", l8);

    // TEST Strings

    LispString  s1 = lisp.makeString("BAZ");
    LispString  s2 = lisp.makeString("bar");
    LispString  s3 = lisp.makeString("foo");

    LispValue   l9 = lisp.makeCons(s3,
            lisp.makeCons(s2,
               lisp.makeCons(s1, lisp.makeList(r3, r2, r1))));
    show("L9: ", l9);

    LispValue   l10 = lisp.makeList(s3, s2);
    show("L10: ", l10);

    // Added 23 Feb 2006 (mh)
//    try {
//      String expr = "(* 5 B)";
//      LispValue a = lisp.makeSymbol("A");
//      a.set_special(true);
//      a.setf_symbol_value(lisp.makeInteger(7));
//      System.out.println("A = " + a.symbol_value());
//
//      LispValue B       = lisp.eval("B");
//      LispValue globals = lisp.makeList(lisp.makeList(lisp.makeCons(lisp.makeSymbol("B"), lisp.makeInteger(7))));
//      LispValue input  = lisp.parse(expr);
//      LispValue result = lisp.eval(input, globals);
//      System.out.println(input + " = " + result);
//    } catch (IOException ioe) {
//      System.err.println("Exception during test ");
//    }

    // Test #1
    System.out.println(lisp.eval("(let ((x 7)) (* 5 x)))"));
    System.out.println(lisp.eval("(progn (setq x 7) (* 5 x))"));
    System.out.println(lisp.eval("(setq x 7)"));
    System.out.println(lisp.eval("(* 5 x)"));

    // Test #2
    try {
      String expr = "(let ((x 7)) (* 5 x)))";
      LispValue input = lisp.parse(expr);
      LispValue result = lisp.eval(input);
      System.out.println(input + " = " + result);
    } catch (IOException ioe) {
      System.err.println("Exception during test ");
    }

View Full Code Here

    public Macroexpand1Primitive(final Jatha lisp) {
        super(lisp, "MACROEXPAND-1", 1);
    }
   
    public void Execute(final SECDMachine machine) {
        final LispValue form = machine.S.pop();
        final LispValue carForm = form.car();
        if(carForm.fboundp() == f_lisp.T && carForm.symbol_function() != null && carForm.symbol_function().basic_macrop()) {
            machine.S.push(f_lisp.eval(f_lisp.makeCons(f_lisp.EVAL.intern("%%%" + carForm.symbol_name().toStringSimple(),(LispPackage)f_lisp.findPackage("SYSTEM")),quoteList(form.cdr()))));
        } else {
            machine.S.push(form);
        }
        machine.C.pop();
    }
View Full Code Here

        }
        machine.C.pop();
    }

    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

    super(lisp, "STRING-LEFT-TRIM", 1, 2);
  }

  public void Execute(SECDMachine machine)
  {
    LispValue arg2 = machine.S.pop();
    LispValue arg1 = machine.S.pop();

    if (arg1 != f_lisp.NIL)
      machine.S.push(arg1.stringLeftTrim(arg2));
    else
      machine.S.push(arg2.stringLeftTrim());
    machine.C.pop();
  }
View Full Code Here

    while (true)
    {
      String baseFilename = fileNF.format(fileNumber++) + fileSuffix;
      String filename = filePrefix + baseFilename;
      try {
        LispValue result = loadFromJar(filename);
        if (result == T)
        {
            if(useConsole) {
                System.out.println("  loaded " + baseFilename);
            }
View Full Code Here

      JarFile jarFile = new JarFile(jarFileString);
      JarEntry je = jarFile.getJarEntry(filename);
      if (je == null)
        return NIL;

      LispValue result = load(new InputStreamReader(jarFile.getInputStream(je)));
      jarFile.close();
      return result;
    } catch (IOException ioe) {
      return makeString(ioe.getMessage());
    } catch (SecurityException se) {
View Full Code Here

   *   eval("(* 5 x)");
   * </pre>
   */
  public LispValue eval(String expr)
  {
    LispValue input = NIL;

    // READ
    try {
      PARSER.setInputString(expr);
      input = PARSER.parse();
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.