* Re: Lexical binding and macros. [not found] <mailman.40.1292017369.4804.help-gnu-emacs@gnu.org> @ 2010-12-12 4:10 ` Barry Margolin 2010-12-12 17:14 ` LanX 0 siblings, 1 reply; 12+ messages in thread From: Barry Margolin @ 2010-12-12 4:10 UTC (permalink / raw) To: help-gnu-emacs In article <mailman.40.1292017369.4804.help-gnu-emacs@gnu.org>, Alin Soare <alinsoar@voila.fr> wrote: > Are the macros and closures equivalent ? No. Emacs Lisp has macros, it doesn't have closures. But in dialects of Lisp that have both, they're completely different. > The set of macros is greater than the set of closures? > > The set of closures is greater than the set of macros? These questions don't even make sense. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group *** ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Lexical binding and macros. 2010-12-12 4:10 ` Lexical binding and macros Barry Margolin @ 2010-12-12 17:14 ` LanX 2010-12-12 17:23 ` Pascal J. Bourguignon 0 siblings, 1 reply; 12+ messages in thread From: LanX @ 2010-12-12 17:14 UTC (permalink / raw) To: help-gnu-emacs On 12 Dez., 05:10, Barry Margolin <bar...@alum.mit.edu> wrote: > In article <mailman.40.1292017369.4804.help-gnu-em...@gnu.org>, > Alin Soare <alins...@voila.fr> wrote: > > > Are the macros and closures equivalent ? > > No. Emacs Lisp has macros, it doesn't have closures. But in dialects > of Lisp that have both, they're completely different. ehm ... isn't "lexical-let" from the common lisp extension supposed to support closures? ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Lexical binding and macros. 2010-12-12 17:14 ` LanX @ 2010-12-12 17:23 ` Pascal J. Bourguignon 2010-12-15 4:24 ` Stefan Monnier 0 siblings, 1 reply; 12+ messages in thread From: Pascal J. Bourguignon @ 2010-12-12 17:23 UTC (permalink / raw) To: help-gnu-emacs LanX <lanx.perl@googlemail.com> writes: > On 12 Dez., 05:10, Barry Margolin <bar...@alum.mit.edu> wrote: >> In article <mailman.40.1292017369.4804.help-gnu-em...@gnu.org>, >> Alin Soare <alins...@voila.fr> wrote: >> >> > Are the macros and closures equivalent ? >> >> No. Emacs Lisp has macros, it doesn't have closures. But in dialects >> of Lisp that have both, they're completely different. > > > ehm ... isn't "lexical-let" from the common lisp extension supposed to > support closures? They're not really closures. Closures are equivalent to objects, so you can simulate them by creating a kind of object, and this is what lexical-let does. But given emacs lisp VM, it cannot do it quite efficiently. -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Lexical binding and macros. 2010-12-12 17:23 ` Pascal J. Bourguignon @ 2010-12-15 4:24 ` Stefan Monnier 2010-12-15 9:15 ` Elena 0 siblings, 1 reply; 12+ messages in thread From: Stefan Monnier @ 2010-12-15 4:24 UTC (permalink / raw) To: help-gnu-emacs >> ehm ... isn't "lexical-let" from the common lisp extension supposed to >> support closures? > They're not really closures. Actually, they are closures. Admittedly, they're not as efficient as one might like, but other than that, they work very well, thank you. Stefan ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Lexical binding and macros. 2010-12-15 4:24 ` Stefan Monnier @ 2010-12-15 9:15 ` Elena 2010-12-15 12:38 ` Pascal J. Bourguignon 2010-12-15 15:40 ` Stefan Monnier 0 siblings, 2 replies; 12+ messages in thread From: Elena @ 2010-12-15 9:15 UTC (permalink / raw) To: help-gnu-emacs On Dec 15, 4:24 am, Stefan Monnier <monn...@iro.umontreal.ca> wrote: > >> ehm ... isn't "lexical-let" from the common lisp extension supposed to > >> support closures? > > They're not really closures. > > Actually, they are closures. Admittedly, they're not as efficient as > one might like, but other than that, they work very well, thank you. > > Stefan Do they still leak memory? From http://c2.com/cgi/wiki?EmacsLisp : "Note that variables bound with lexical-let are never released, even if they are never used. Try (loop for i from 1 to 100000 collect (lexical-let ((x i)) '())) and watch it eat memory. So making infinity (ZeroOneInfinity) lexical variables is out of the question except for very small values of infinity." ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Lexical binding and macros. 2010-12-15 9:15 ` Elena @ 2010-12-15 12:38 ` Pascal J. Bourguignon 2010-12-15 15:40 ` Stefan Monnier 1 sibling, 0 replies; 12+ messages in thread From: Pascal J. Bourguignon @ 2010-12-15 12:38 UTC (permalink / raw) To: help-gnu-emacs Elena <egarrulo@gmail.com> writes: > On Dec 15, 4:24 am, Stefan Monnier <monn...@iro.umontreal.ca> wrote: >> >> ehm ... isn't "lexical-let" from the common lisp extension supposed to >> >> support closures? >> > They're not really closures. >> >> Actually, they are closures. Admittedly, they're not as efficient as >> one might like, but other than that, they work very well, thank you. >> >> Stefan > > Do they still leak memory? From http://c2.com/cgi/wiki?EmacsLisp : > > "Note that variables bound with lexical-let are never released, even > if they are never used. Try > > (loop for i from 1 to 100000 collect (lexical-let ((x i)) '())) > > and watch it eat memory. Just wait till the garbage collector kicks in. The variables are named by un-interned symbols. The should be garbage collected as soon as the 'closures' using them are collected. In your example, that's immediately, since no closure is created. -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Lexical binding and macros. 2010-12-15 9:15 ` Elena 2010-12-15 12:38 ` Pascal J. Bourguignon @ 2010-12-15 15:40 ` Stefan Monnier 2010-12-15 16:16 ` David Kastrup 1 sibling, 1 reply; 12+ messages in thread From: Stefan Monnier @ 2010-12-15 15:40 UTC (permalink / raw) To: help-gnu-emacs > Do they still leak memory? From http://c2.com/cgi/wiki?EmacsLisp : > "Note that variables bound with lexical-let are never released, even > if they are never used. Try > (loop for i from 1 to 100000 collect (lexical-let ((x i)) '())) > and watch it eat memory. So making infinity (ZeroOneInfinity) lexical > variables is out of the question except for very small values of > infinity." Additionally to what Pascal already explained, I'll add that, lexical-let, like `loop' are relatively heavy macros, so you definitely don't want to run them interpreted (where the macro is re-expanded each time). If you byte-compile the code above, the memory use will be identical to what you get with (loop for i from 1 to 100000 collect (let ((x i)) '())) Stefan ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Lexical binding and macros. 2010-12-15 15:40 ` Stefan Monnier @ 2010-12-15 16:16 ` David Kastrup 2010-12-15 17:37 ` Pascal J. Bourguignon ` (2 more replies) 0 siblings, 3 replies; 12+ messages in thread From: David Kastrup @ 2010-12-15 16:16 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: >> Do they still leak memory? From http://c2.com/cgi/wiki?EmacsLisp : > >> "Note that variables bound with lexical-let are never released, even >> if they are never used. Try > >> (loop for i from 1 to 100000 collect (lexical-let ((x i)) '())) > >> and watch it eat memory. So making infinity (ZeroOneInfinity) lexical >> variables is out of the question except for very small values of >> infinity." > > Additionally to what Pascal already explained, I'll add that, > lexical-let, like `loop' are relatively heavy macros, so you definitely > don't want to run them interpreted (where the macro is re-expanded each > time). Why would they be reexpanded each time? They are macros. Their expansion is done once and merely evalled each time. Or do I misunderstand something here? -- David Kastrup ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Lexical binding and macros. 2010-12-15 16:16 ` David Kastrup @ 2010-12-15 17:37 ` Pascal J. Bourguignon 2010-12-15 17:54 ` Elena 2010-12-16 21:59 ` Stefan Monnier 2 siblings, 0 replies; 12+ messages in thread From: Pascal J. Bourguignon @ 2010-12-15 17:37 UTC (permalink / raw) To: help-gnu-emacs David Kastrup <dak@gnu.org> writes: > Stefan Monnier <monnier@iro.umontreal.ca> writes: > >>> Do they still leak memory? From http://c2.com/cgi/wiki?EmacsLisp : >> >>> "Note that variables bound with lexical-let are never released, even >>> if they are never used. Try >> >>> (loop for i from 1 to 100000 collect (lexical-let ((x i)) '())) >> >>> and watch it eat memory. So making infinity (ZeroOneInfinity) lexical >>> variables is out of the question except for very small values of >>> infinity." >> >> Additionally to what Pascal already explained, I'll add that, >> lexical-let, like `loop' are relatively heavy macros, so you definitely >> don't want to run them interpreted (where the macro is re-expanded each >> time). > > Why would they be reexpanded each time? They are macros. Their > expansion is done once and merely evalled each time. > > Or do I misunderstand something here? In the case of Common Lisp, implementations providing an interpreter are allowed to macro expand everytime. Most implementations do cache the expansion however. (A lot of CL implementations just compile everything automatically anyways). For example, clisp performs the macroexpansions when defining the function, and one time again when compiling it: CL-USER> (defmacro m (x) (format t "(m ~S) is expanded" x) `(list ',x ',x)) M CL-USER> (defun f () (m 1)) (m 1) is expanded F CL-USER> (list (f) (f) (f)) ((1 1) (1 1) (1 1)) CL-USER> (compile 'f) (m 1) is expanded F NIL NIL CL-USER> In the case of emacs 23.2.1, (defmacro m (x) (message "(m %S) is expanded" x) `(list ',x ',x)) (defun f () (m 1)) (list (f) (f) (f)) --> ((1 1) (1 1) (1 1)) produces in *Messages*: (m 1) is expanded [3 times] So it looks like the emacs lisp interpreter doesn't not cache the macro expansions. emacs lisp expands it once more when compiling the function too: (byte-compile 'f) --> #[nil "\300\211D\207" [1] 2] *Messages*: (m 1) is expanded -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Lexical binding and macros. 2010-12-15 16:16 ` David Kastrup 2010-12-15 17:37 ` Pascal J. Bourguignon @ 2010-12-15 17:54 ` Elena 2010-12-16 21:59 ` Stefan Monnier 2 siblings, 0 replies; 12+ messages in thread From: Elena @ 2010-12-15 17:54 UTC (permalink / raw) To: help-gnu-emacs On Dec 15, 5:16 pm, David Kastrup <d...@gnu.org> wrote: > Stefan Monnier <monn...@iro.umontreal.ca> writes: > >> Do they still leak memory? Fromhttp://c2.com/cgi/wiki?EmacsLisp: > > >> "Note that variables bound with lexical-let are never released, even > >> if they are never used. Try > > >> (loop for i from 1 to 100000 collect (lexical-let ((x i)) '())) > > >> and watch it eat memory. So making infinity (ZeroOneInfinity) lexical > >> variables is out of the question except for very small values of > >> infinity." > > > Additionally to what Pascal already explained, I'll add that, > > lexical-let, like `loop' are relatively heavy macros, so you definitely > > don't want to run them interpreted (where the macro is re-expanded each > > time). > > Why would they be reexpanded each time? They are macros. Their > expansion is done once and merely evalled each time. Macros expansion can change if such macros depend on some other macros which have been redefined after last expansion. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Lexical binding and macros. 2010-12-15 16:16 ` David Kastrup 2010-12-15 17:37 ` Pascal J. Bourguignon 2010-12-15 17:54 ` Elena @ 2010-12-16 21:59 ` Stefan Monnier 2 siblings, 0 replies; 12+ messages in thread From: Stefan Monnier @ 2010-12-16 21:59 UTC (permalink / raw) To: help-gnu-emacs >> Additionally to what Pascal already explained, I'll add that, >> lexical-let, like `loop' are relatively heavy macros, so you >> definitely don't want to run them interpreted (where the macro is >> re-expanded each time). > Why would they be reexpanded each time? Because it's easier to implement it that way in a pure interpreter. > They are macros. Their expansion is done once and merely evalled > each time. > Or do I misunderstand something here? Their expansion *can be* done once (which is what happens when you byte-compile), but the interpreter doesn't bother with such optimizations. Stefan ^ permalink raw reply [flat|nested] 12+ messages in thread
* Lexical binding and macros. @ 2010-12-10 21:42 Alin Soare 0 siblings, 0 replies; 12+ messages in thread From: Alin Soare @ 2010-12-10 21:42 UTC (permalink / raw) To: help-gnu-emacs Are the macros and closures equivalent ? The set of macros is greater than the set of closures? The set of closures is greater than the set of macros? Alin ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2010-12-16 21:59 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <mailman.40.1292017369.4804.help-gnu-emacs@gnu.org> 2010-12-12 4:10 ` Lexical binding and macros Barry Margolin 2010-12-12 17:14 ` LanX 2010-12-12 17:23 ` Pascal J. Bourguignon 2010-12-15 4:24 ` Stefan Monnier 2010-12-15 9:15 ` Elena 2010-12-15 12:38 ` Pascal J. Bourguignon 2010-12-15 15:40 ` Stefan Monnier 2010-12-15 16:16 ` David Kastrup 2010-12-15 17:37 ` Pascal J. Bourguignon 2010-12-15 17:54 ` Elena 2010-12-16 21:59 ` Stefan Monnier 2010-12-10 21:42 Alin Soare
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.