/* xdefun - special form 'defun' */ LVAL xdefun() { LVAL sym,fargs,arglist; /* get the function symbol and formal argument list */ xlsave1(arglist); sym = xlgasymbol(); fargs = xlgalist(); arglist = makearglist(xlargc,xlargv); /* make the symbol point to a new function definition */ xlsetfunction(sym, xlclose(sym, s_lambda, fargs,arglist, xlenv,xlfenv)); /* restore the stack and return the function symbol */ xlpop(); return (sym); }defunは,クロージャを作るxlcloseを呼び, シンボルに関数定義を代入しています. xlsetfunctionは次のようになっています. 環境変数にそのシンボルがある場合には, そこへ代入し,そうでなければ大域変数の シンボルに代入します.
xlsetfunction(sym,val) LVAL sym,val; { register LVAL fp,ep; /* look for the symbol in the environment list */ for (fp = xlfenv; fp; fp = cdr(fp)) for (ep = car(fp); ep; ep = cdr(ep)) if (sym == car(car(ep))) { rplacd(car(ep),val); return; } /* store the global value */ setfunction(sym,val); }setfunctionはxldmem.hの中にマクロで次のように 定義されています.
#define setfunction(x,v) ((x)->n_vdata[1] = (v))