Package org.jatha.dynatype

Examples of org.jatha.dynatype.LispValue


   * @param vars a nested list of global variables and values, such as (((a . 3) (b . 5)) ((c . 10)))
   * @see #parse(String)
  */
  public LispValue eval(LispValue inValue, final LispValue vars)
  {
    LispValue code, value;

    final LispValue varNames = parseVarNames(vars);
    final LispValue varValues = parseVarValues(vars);

    try {
      // compile
      code  = COMPILER.compile(MACHINE, inValue, varNames);

View Full Code Here


  /**
   * Expects a list with this format (((A 13) (C 7))((X "Zeta"))) and returns a list with this format ((A C)(X))
   */
  private LispValue parseVarNames(final LispValue vars) {
    LispValue outp = NIL;
    if (vars.basic_null())
      return outp;

    for(final Iterator iter = vars.iterator();iter.hasNext();) {
      final LispValue current = (LispValue)iter.next();
      LispValue inner = NIL;
      for(final Iterator iter2 = current.iterator();iter2.hasNext();) {
        final LispValue currInt = (LispValue)iter2.next();
        inner = makeCons(currInt.car(),inner);
      }
      outp = makeCons(inner.nreverse(),outp);
    }
    return outp.nreverse();
  }
View Full Code Here

   * This one expects variables of the form ((A . 7) (B . 13) (C . (foo)))
   * the CAR of each pair is the variable and the CDR of each pair is the value.
   */
  private LispValue parseVarNames_new(final LispValue vars)
  {
    LispValue outp = NIL;
    if (vars.basic_null())
      return outp;

    for (final Iterator iter = vars.iterator(); iter.hasNext();)
    {
      final LispValue current = (LispValue)iter.next();
      outp = makeCons(current.car(), outp);
    }
    return outp.nreverse();
  }
View Full Code Here

   * This one expects variables of the form ((A . 7) (B . 13) (C . (foo)))
   * the CAR of each pair is the variable and the CDR of each pair is the value.
   */
  private LispValue parseVarValues_new(final LispValue vars)
  {
    LispValue outp = NIL;
    if (vars.basic_null())
      return outp;

    for (final Iterator iter = vars.iterator(); iter.hasNext();)
    {
      final LispValue current = (LispValue)iter.next();
      outp = makeCons(current.cdr(), outp);
    }
    return outp.nreverse();
  }
View Full Code Here

  /**
   * Expects a list with this format (((A 13) (C 7))((X "Zeta"))) and returns a list with this format ((13 7)("Zeta"))
   */
  private LispValue parseVarValues(final LispValue vars) {
    LispValue outp = NIL;
    if (vars.basic_null())
      return outp;

    for(final Iterator iter = vars.iterator();iter.hasNext();) {
      final LispValue current = (LispValue)iter.next();
      LispValue inner = NIL;
      for(final Iterator iter2 = current.iterator();iter2.hasNext();) {
        final LispValue currInt = (LispValue)iter2.next();
        inner = makeCons(currInt.cdr(),inner);
      }
      outp = makeCons(inner.nreverse(),outp);
    }
    return outp.nreverse();
  }
View Full Code Here



  void readEvalPrintLoop()
  {
    LispValue input, code, value, prompt;
    LispValue STAR, STARSTAR, STARSTARSTAR;
    boolean   validInput;
    LispValue oldPackageSymbolValue = PACKAGE_SYMBOL.symbol_value();

    // Need to allow *TOP-LEVEL-PROMPT* to change this.
    prompt = makeString("Jatha " + PACKAGE_SYMBOL.symbol_value().toString() + "> ");

    STAR         = EVAL.intern("*");
 
View Full Code Here

    // System.err.println("Loading: verbose is " + verbose);

    BufferedReader buff = new BufferedReader(in);

    LispParser fileparser = new LispParser(this, buff);
    LispValue  input, code;
    boolean    atLeastOneResult = false;

    LispPackage oldPackage = (LispPackage)PACKAGE_SYMBOL.symbol_value();
    // Read and Eval stream until EOF.
    try {
      while (true)
      {
        input = fileparser.parse();

        code  = COMPILER.compile(MACHINE, input, NIL);

        LispValue value = MACHINE.Execute(code, NIL);
        atLeastOneResult = true;

        if (verbose)
        {
          if (useGUI)
            LISTENER.message(value, false);
          else
            System.out.println(value.toString());
        }
      }
    } catch (IOException ioe) {
      try {
        in.close();
View Full Code Here

  public LispValue findPackage(String packageNameStr)
  {
    if (packages == null)
      return NIL;

    LispValue     pList = packages;
    LispValue     nickNameList;
    LispPackage   pkg;

    while (pList != NIL)
    {
      pkg = (LispPackage)(pList.car());

      // Try to match the package name
      if (packageNameStr.equalsIgnoreCase(pkg.getName().getValue()))
        return pkg;

      // Try to match the nicknames
      nickNameList = pkg.getNicknames();
      while (nickNameList != NIL)
      {
        if (packageNameStr.equalsIgnoreCase(((LispString)(nickNameList.car())).getValue()))
          return pkg;
        nickNameList = nickNameList.cdr();
      }

      // Try the next package.
      pList = pList.cdr();
    }
View Full Code Here

    // Loop through the packages, printing all symbols that match.
    // The symbols come out unsorted, but oh well.

    String matchStr = ((LispString)(str)).getValue().toUpperCase();
    Iterator    iter;
    LispValue   symb;
    LispString  sname;
    String      symbstr;

    while (pkg != NIL)
    {
      iter = ((LispPackage)(pkg.car())).getSymbolTable().values().iterator();

      while (iter.hasNext())
      {
        symb     = ((LispValue)(iter.next()));
        sname    = (LispString)(symb.symbol_name());
        symbstr  = sname.getValue().toUpperCase();

        if (symbstr.indexOf(matchStr) >= 0)
          symb.apropos_print(out);
      }
      pkg = pkg.cdr();
    }

    out.flush();
View Full Code Here

     * @param nickNames a list of nicknames. the content must be strings or symbols
     * @param use a list of package names to use. may be strings or symbols.
     * @return Jatha.PACKAGE
     */
    public LispValue makePackage(final LispValue name, final LispValue nickNames, final LispValue use) {
        LispValue firstPkg = findPackage(name);
        if(NIL != firstPkg) {
            throw new LispAlreadyDefinedPackageException(((LispString)name.string()).getValue());
        }
        firstPkg = new StandardLispPackage(this, name, nickNames, use);
        packages = makeCons(firstPkg,packages);
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.