Changeset 4090
- Timestamp:
- 09/28/03 00:47:10 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/lisp/Primitives.java
r4084 r4090 3 3 * 4 4 * Copyright (C) 2002-2003 Peter Graves 5 * $Id: Primitives.java,v 1.44 5 2003-09-27 18:31:20 piso Exp $5 * $Id: Primitives.java,v 1.446 2003-09-28 00:47:10 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 456 456 }; 457 457 458 // ### quote459 private static final SpecialOperator QUOTE = new SpecialOperator("quote") {460 public LispObject execute(LispObject args, Environment env)461 throws ConditionThrowable462 {463 return args.car();464 }465 };466 467 458 // ### atom 468 459 private static final Primitive1 ATOM = new Primitive1("atom") { … … 590 581 return result; 591 582 } 592 }593 }594 };595 596 // ### if597 private static final SpecialOperator IF = new SpecialOperator("if") {598 public LispObject execute(LispObject args, Environment env)599 throws ConditionThrowable600 {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"));615 583 } 616 584 } … … 2786 2754 }; 2787 2755 2788 private static final SpecialOperator LET = new SpecialOperator("let") {2789 public LispObject execute(LispObject args, Environment env)2790 throws ConditionThrowable2791 {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 ConditionThrowable2799 {2800 return _let(args, env, true);2801 }2802 };2803 2804 private static final LispObject _let(LispObject args, Environment env,2805 boolean sequential)2806 throws ConditionThrowable2807 {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 } else2824 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 2845 2756 private static final LispObject _flet(LispObject args, Environment env, 2846 2757 boolean recursive) throws ConditionThrowable
Note: See TracChangeset
for help on using the changeset viewer.