// // Macro.java : Lisp Macro オブジェクトクラス定義 // // This is a part of miolisp sourcefile // Copyright (C) 1998 Nishiyama, Naoki / Mio software lab. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // import java.util.* ; class LambdaArg { public static final String AUXSTR = "&aux" ; // &aux keyword public static final String RESTSTR = "&rest" ; // &rest keyword public static SAtom aux , rest ; static { aux = SAtom.getSAtom(AUXSTR) ; rest = SAtom.getSAtom(RESTSTR) ; } } public class Macro { public Environment ec = null ; // 作成時の外縁環境 (Closure) public Object[] arg ; // 引数リスト public int minargs,maxargs ; // 最小引数数 public Object body ; // 本体 Macro(Environment ev,Object a,Object b) throws Exception { int i = 0 ; body = b ; arg = Evalutil.listtoarg(a) ; for (i=0;i 0) { Hashtable h = bindlist(arg.length,arg,a) ; env.addNewDic(h) ; // 引数を束縛 } Object o1 = Evalutil.evprogn(body,env) ; //System.out.println("MacroExpand ->"+Sexpr.toStr(o1)) ; return Eval.eval(o1,e) ; // 2度目の評価は、もとの環境で行うことに注意。 } }