Re: Implementing closures using first-class environments in LAMBDA
From: Nils M Holm (nmh_at_despammed.com)
Date: 09/30/04
- Next message: Joel Ray Holveck: "Re: Lambda Quine (and the Lisp it rode in on)"
- Previous message: Christophe Rhodes: "Re: How to prevent cdr from capitalizing symbols?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 30 Sep 2004 06:57:07 +0000 (UTC)
Matthew Danish <mrd+nospam@cmu.edu> wrote:
> Congratulations. This is how closures are usually implemented.
Thanks.
> Well, ok, not like that. At first, I didn't realize you meant
>
> (LAMBDA (Y) (CONS X Y) ((X . VALUE)))
In what way are closures implemented usually? Since you emphasize
the dot: using lists of lists rather than lists of pairs? That would
not make a big difference, would it?
> Rather than make it complicated by referring to ``escape'' why don't
> you just make this evaluation rule for LAMBDA:
I had thought about implementing it this way, but this method
would attempt to create closures in a lot of situations where
it is not really neccessary. In particular, functions of the form
(LABEL ((F (LAMBDA ...))
(G (LAMBDA ...))
...
EXPR))
would involve a lot of superflous computations when none of its
functions actually escapes.
And then, detecting an escaping function is not that hard. When
unbinding function arguments, you check whether the result
expression is a lambda function and if it is, you create a
closure.
In my implementation, these are two lines of code and save a
lot of unneccessary calls to the routine that creates closures.
Nils
-- Nils M Holm <nmh@despammed.com> -- http://www.t3x.org/nmh/
- Next message: Joel Ray Holveck: "Re: Lambda Quine (and the Lisp it rode in on)"
- Previous message: Christophe Rhodes: "Re: How to prevent cdr from capitalizing symbols?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|