01: package jsint;
02:
03: /**
04: A macro.
05:
06: @author Peter Norvig, Copyright 1998, peter@norvig.com, <a href="license.txt">license</a>
07: subsequently modified by Jscheme project members
08: licensed under zlib licence (see license.txt)
09: **/
10:
11: public class Macro extends Closure {
12:
13: /** Make a macro from a parameter list, body, and environment. **/
14: public Macro(Object parms, Object body, LexicalEnvironment lexenv) {
15: super (parms, body, lexenv);
16: }
17:
18: public static Object expand(Pair x) {
19: Object f = U.first(x);
20: Object fval = (f instanceof Symbol) ? (((Symbol) f).isDefined() ? ((Symbol) f)
21: .getGlobalValue()
22: : null)
23: : null;
24: if (fval instanceof Macro)
25: return ((Macro) fval).apply(U.toList(x.rest));
26: else
27: return x;
28: }
29:
30: public String toString() {
31: return "(macro " + this .name + " " + U.stringify(parms)
32: + "...)";
33: }
34: }
|