[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [lua-l] Digest Number 734
- From: Philippe Lhoste <PhiLho@...>
- Date: Tue, 28 May 2002 10:28:55 +0200 (MEST)
Note: I feel I can comment on the subject, because I have done the same
error in the past (and can do it again :-)
Ralf, you should remember to copy the subject from the message you are
replying to, it will be more informative...
And don't feel stupid, I never heard of closures before coming to this
mailing list, and I still have some trouble to grab the concept...
> > I feel awfully stupid, but could anyone explain (or give a reference
> > for) what a "closure" is?
> In Lua, from the C API point of view, a closure is an object created by
> the association of a function object and a set of data values. To create
> a closure, use the lua_pushcclosure API function. When the closure is
> called, the associated function is called and these values (called
> upvalues) can then be accessed directly from the top of the stack (Lua
> 4.0), or with special indexes (Lua 4.1 on).
> The question was if it was possible to extract the upvalues from a
> closure without calling the closure.
> For some nice uses of closures, check the Wiki or Roberto's book.
> Best regards,
> >>From FOLDOC:
> 1. <programming> In a reduction system, a closure is a data structure
> that holds an expression and an environment of variable bindings in
> which that expression is to be evaluated. The variables may be local or
> global. Closures are used to represent unevaluated expressions when
> implementing functional programming languages with lazy evaluation. In a
> real implementation, both expression and environment are represented by
Thank you for the explaination. I love this mailing list because I learn a
lot of things, like some functionnal programming concepts to the basis of
I may be wrong, but I see a little discrepancy between your definition
(which is right regarding Lua, of course) and the FOLDOC one.
If I understand correctly, closure variables in Lua are frozen, ie. their
values when the closure is defined are fixed. The function uses these constants
as additional parameters.
Closures values as per FOLDOC point to variables, ie. the function uses the
live values at the time of execution. Or not?
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
GMX - Die Kommunikationsplattform im Internet.