Changeset 4090


Ignore:
Timestamp:
09/28/03 00:47:10 (20 years ago)
Author:
piso
Message:

Moved QUOTE, IF, LET, LET* to SpecialOperators?.java.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/Primitives.java

    r4084 r4090  
    33 *
    44 * Copyright (C) 2002-2003 Peter Graves
    5  * $Id: Primitives.java,v 1.445 2003-09-27 18:31:20 piso Exp $
     5 * $Id: Primitives.java,v 1.446 2003-09-28 00:47:10 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    456456    };
    457457
    458     // ### quote
    459     private static final SpecialOperator QUOTE = new SpecialOperator("quote") {
    460         public LispObject execute(LispObject args, Environment env)
    461             throws ConditionThrowable
    462         {
    463             return args.car();
    464         }
    465     };
    466 
    467458    // ### atom
    468459    private static final Primitive1 ATOM = new Primitive1("atom") {
     
    590581                    return result;
    591582                }
    592             }
    593         }
    594     };
    595 
    596     // ### if
    597     private static final SpecialOperator IF = new SpecialOperator("if") {
    598         public LispObject execute(LispObject args, Environment env)
    599             throws ConditionThrowable
    600         {
    601             final LispThread thread = LispThread.currentThread();
    602             switch (args.length()) {
    603                 case 2: {
    604                     if (eval(args.car(), env, thread) != NIL)
    605                         return eval(args.cadr(), env, thread);
    606                     return NIL;
    607                 }
    608                 case 3: {
    609                     if (eval(args.car(), env, thread) != NIL)
    610                         return eval(args.cadr(), env, thread);
    611                     return eval(args.cdr().cadr(), env, thread);
    612                 }
    613                 default:
    614                     throw new ConditionThrowable(new WrongNumberOfArgumentsException("IF"));
    615583            }
    616584        }
     
    27862754    };
    27872755
    2788     private static final SpecialOperator LET = new SpecialOperator("let") {
    2789         public LispObject execute(LispObject args, Environment env)
    2790             throws ConditionThrowable
    2791         {
    2792             return _let(args, env, false);
    2793         }
    2794     };
    2795 
    2796     private static final SpecialOperator LETX = new SpecialOperator("let*") {
    2797         public LispObject execute(LispObject args, Environment env)
    2798             throws ConditionThrowable
    2799         {
    2800             return _let(args, env, true);
    2801         }
    2802     };
    2803 
    2804     private static final LispObject _let(LispObject args, Environment env,
    2805                                          boolean sequential)
    2806         throws ConditionThrowable
    2807     {
    2808         LispObject varList = checkList(args.car());
    2809         final LispThread thread = LispThread.currentThread();
    2810         LispObject result = NIL;
    2811         if (varList != NIL) {
    2812             Environment oldDynEnv = thread.getDynamicEnvironment();
    2813             try {
    2814                 Environment ext = new Environment(env);
    2815                 Environment evalEnv = sequential ? ext : env;
    2816                 for (int i = varList.length(); i-- > 0;) {
    2817                     LispObject obj = varList.car();
    2818                     varList = varList.cdr();
    2819                     if (obj instanceof Cons) {
    2820                         bind(checkSymbol(obj.car()),
    2821                              eval(obj.cadr(), evalEnv, thread),
    2822                              ext);
    2823                     } else
    2824                         bind(checkSymbol(obj), NIL, ext);
    2825                 }
    2826                 LispObject body = args.cdr();
    2827                 while (body != NIL) {
    2828                     result = eval(body.car(), ext, thread);
    2829                     body = body.cdr();
    2830                 }
    2831             }
    2832             finally {
    2833                 thread.setDynamicEnvironment(oldDynEnv);
    2834             }
    2835         } else {
    2836             LispObject body = args.cdr();
    2837             while (body != NIL) {
    2838                 result = eval(body.car(), env, thread);
    2839                 body = body.cdr();
    2840             }
    2841         }
    2842         return result;
    2843     }
    2844 
    28452756    private static final LispObject _flet(LispObject args, Environment env,
    28462757        boolean recursive) throws ConditionThrowable
Note: See TracChangeset for help on using the changeset viewer.