[virtmach] lambda

David Rush kumo@bellsouth.net
08 Dec 1999 12:20:38 +0000


Ceri Storey <cez@nomorespam.freeserve.co.uk> writes:

> in a bytecode based VM, is it possible to have a lambda opcode? (as in
> scheme/lisp/lambda calculus) woud it be a case of pushing a pre
> comipled function onto the stack (from a vector of constants, as in
> emacs) or can you create one from the nomal 'stream' of instructions?
> (i apologise for the pointless question, and for apologising. [stack
> overflow from exessive recursion])

Others may disagree, but I don't think so. At least not in the way
that you have phrased the question (Although Forth machines in
particular probably *can*, compiler interaction is strange and
wonderful in their world). The problem is that identifying a string of
instructions as a well-formed function is a non-trivial task; it may
even be undecidable. Really only the compiler knows where the function
boundaries lie, and it got it's knowledge from the program source
code, written by a human.

OTOH, in a VM I built fairly recently, functions were first class
VM objects and I had a generalized 'apply' operator that took a number
of arguments off the stack and created a closure based on the function
argument. The closure would then be executed. The cool thing was that
the value of a closure whose arguments were underdetermined was itself
(closures were implementationally identical objects to functions with
a different life-cycle).

So I got partial application of functions with very little effort; I
could create functions on the fly from other functions without having
tremendous compiler support. If this is what you're looking for from a
'lambda' operation then I'd say, yes it can be done. YMMV.

david rush
-- 
>From the start...the flute has been associated with pure (some might
say impure) energy. Its sound releases something naturally untamed, as
if a squirrel were let loose in a church." --Seamus Heaney