Re: spec 3.1.2.1.2 and the lambda exception

From: Marcin 'Qrczak' Kowalczyk (qrczak_at_knm.org.pl)
Date: 08/24/04


Date: Tue, 24 Aug 2004 21:43:33 +0200

On Tue, 24 Aug 2004 00:31:51 +0200, Pascal Bourguignon wrote:

> Note however that you can still play some tricks:
>
> CL-USER> (defun make-adder (x) `(lambda (y) (+ ,x y)))
> MAKE-ADDER
> CL-USER> (#.(make-adder 1) 1)
> 2
>
> Of course, the adder will be created at read time instead of run time.

Its source will be created at read time, but the actual function object
will be created at runtime. If you want to use a closure created at read
time, it must be applied using something like funcall.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


Relevant Pages

  • Re: D gets it right
    ... > This function, written in Scheme, returns a closure. ... > storage for the value of k would be freed when make-adder returned. ... Public Function MakeAdder(ByVal K As Double) As Adder ... Dim Temp As Adder ...
    (comp.programming)
  • Re: Relative merits of Lisp-1 vs. Lisp-2?
    ... style is somewhat more convenient with a Lisp-1. ... (funcall (f x) ... programming you might want to ... object in the list, (make-adder 10) returns a function, which it does. ...
    (comp.lang.lisp)
  • Re: A function that returns a function that adds x to its argument
    ... denoted below by explicit "magic" -- one might write something like ... is something that those languages usually call a "closure". ... in each "new_adder"-created adder, and when one calls the functions ... Reading email is like searching for food in the garbage, ...
    (comp.lang.c)