Subject: green's functions, passing functions to a routine
From: John Lapeyre
Date: Mon, 8 Sep 2008 10:50:19 -0700
> The compiler and the interpreter should do the same thing, namely:
>
> -- when interpreting a symbol in variable context (e.g. y+1 or apply(y,z)),
> to use the locally-bound value if there is one and otherwise the global
> value;
>
> -- when interpreting a symbol in function context (e.g. y(...)), use the
> function value if there is one, otherwise treat it as a variable
I was unclear. It works fine at runtime, but there is a compiletime
warning:
test.mac:
-------------------
funca(f,x) := apply(funcb,[f,x]);
funcb(f,x) := f(x);
-------------------
(%i1) compile_file("test.mac");
...
(%o1) [test.mac, test.LISP, test.UNLISP, #ptest.o]
(%i2) funca(sqrt,4);
(%o2) 2
produces
test.UNLISP
-------------------
Translating: funca
Warning-> funcb is an undefined global variable.
Translating: funcb
f
in the form f(x)
has been used as a function, yet is a bound variable
in this context. This code being translated as :apply(f,[x])
-------------------
John