On Wed, Feb 11, 2009 at 4:18 PM, Ville Voutilainen
> On Wed, Feb 11, 2009 at 3:53 PM, Erik Huelsmann <ehuels@...> wrote:
>> * be smarter about argument and return-value passing: try to create
>> functions - local functions and recursive function calls - which can
>> receive and return unboxed values.
> Quick question: why do we box/unbox values when calling lisp functions
> from within lisp? I'd think it's really necessary only when lisp code is
> called from java. Just wondering..
To record my answer (as given to you yesterday on IRC) for posterity
and a wider interested audience (if there is any):
Without declarations, we simply don't know what will be passed in. The
only way to pass around generic objects is to pass around boxed
values. When a function contains declaration forms, the value's type
can be checked and the value can be unboxed (although nothing actually
*requires* it to be unboxed).
When a function is known to have arguments of specific types which can
be unboxed, Ville asked then why don't we use the unboxed values? The
answer is this: the fact that the values can be unboxed is probably an
implementation detail in the function itself. In CL, a single function
can be recompiled, meaning that other functions cannot depend on
implementation details like these, unless the implementor is willing
to trace back in the call graph and recompile all functions depending
on this one. I don't think we should be willing to take that hit
This leaves a few situations where there's nothing wrong with taking
advantage of known implementation details: compilation of local
funtions, for example: they will be recompiled upon recompilation of
the enclosing function anyway. Another is recursive calls: when a
function is calling itself recursively, it should be able to take
advantage of some of its implementation details.
With kind regards,