Associating names with closures
The easiest way to associate names with closures
is to extend the [[SEXP]] type to include a name with
each closure, and store the name when you interpret [[set]].
Note the change to [[CLOSXP]]:
<>=
SEXPREC = record
case sxptype: SEXPTYPE of
NILSXP: ();
NUMSXP: (intval: integer);
SYMSXP: (symval: NAME);
LISTSXP: (carval, cdrval: SEXP);
CLOSXP: (name: NAME; clofun: EXP; cloenv: ENV);
PRIMSXP: (primval: BUILTINOP)
end;
@
And you'll add the following to the implementation of [[set]]:
<>=
if s^.sxptype = CLOSXP then
s^.name := head^.varble;
@
And you'll want to create a suitable name for each closure initially:
<>=
result^.name := install('lambda... ');
@ and I had to declare
<>=
function install (nm: NAMESTRING): NAME; forward;
@ because [[mkCLOSXP]] is defined before [[install]].