* Re: run-with-timer does not display message [not found] <mailman.5454.1405432029.1147.help-gnu-emacs@gnu.org> @ 2014-07-15 14:34 ` Joost Kremers 2014-07-15 15:18 ` jduthen 0 siblings, 1 reply; 32+ messages in thread From: Joost Kremers @ 2014-07-15 14:34 UTC (permalink / raw) To: help-gnu-emacs Matthias Pfeifer wrote: > Hi there, > > this may be a dump question but i could not find a good reason why it > should not work as expected... > > I try to write a message to the messages buffer at some time in the future > via run-with-timer > > (run-with-timer 5 nil '(lambda () (message "hello"))) > > however messge buffer does not get the message. Hints welcome... messages in the message buffer dissappear as soon as the user interacts with Emacs. Perhaps the message does appear but you press a key so quickly that you don't see it. -- Joost Kremers joostkremers@fastmail.fm Selbst in die Unterwelt dringt durch Spalten Licht EN:SiS(9) ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-15 14:34 ` run-with-timer does not display message Joost Kremers @ 2014-07-15 15:18 ` jduthen 2014-07-15 15:20 ` Joost Kremers 0 siblings, 1 reply; 32+ messages in thread From: jduthen @ 2014-07-15 15:18 UTC (permalink / raw) To: help-gnu-emacs Le mardi 15 juillet 2014 16:34:54 UTC+2, Joost Kremers a écrit : > messages in the message buffer dissappear as soon as the user interacts > with Emacs. Perhaps the message does appear but you press a key so > quickly that you don't see it. Have a look at the messages buffer: C-x b *Messages* RET ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-15 15:18 ` jduthen @ 2014-07-15 15:20 ` Joost Kremers 2014-07-15 15:40 ` Drew Adams [not found] ` <mailman.5461.1405438875.1147.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 32+ messages in thread From: Joost Kremers @ 2014-07-15 15:20 UTC (permalink / raw) To: help-gnu-emacs jduthen@gmail.com wrote: > Le mardi 15 juillet 2014 16:34:54 UTC+2, Joost Kremers a écrit : >> messages in the message buffer dissappear as soon as the user interacts >> with Emacs. Perhaps the message does appear but you press a key so >> quickly that you don't see it. > > Have a look at the messages buffer: C-x b *Messages* RET C-h e -- Joost Kremers joostkremers@fastmail.fm Selbst in die Unterwelt dringt durch Spalten Licht EN:SiS(9) ^ permalink raw reply [flat|nested] 32+ messages in thread
* RE: run-with-timer does not display message 2014-07-15 15:20 ` Joost Kremers @ 2014-07-15 15:40 ` Drew Adams [not found] ` <mailman.5461.1405438875.1147.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 32+ messages in thread From: Drew Adams @ 2014-07-15 15:40 UTC (permalink / raw) To: Joost Kremers, help-gnu-emacs > > Have a look at the messages buffer: C-x b *Messages* RET > > C-h e Or just click mouse-1 in the echo area (aka inactive minibuffer). ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <mailman.5461.1405438875.1147.help-gnu-emacs@gnu.org>]
* Re: run-with-timer does not display message [not found] ` <mailman.5461.1405438875.1147.help-gnu-emacs@gnu.org> @ 2014-07-15 15:52 ` Joost Kremers 2014-07-15 15:57 ` Emanuel Berg [not found] ` <mailman.5463.1405440423.1147.help-gnu-emacs@gnu.org> [not found] ` <<slrnlsaji8.a5k.joost.m.kremers@j.kremers4.news.arnhem.chello.nl> 1 sibling, 2 replies; 32+ messages in thread From: Joost Kremers @ 2014-07-15 15:52 UTC (permalink / raw) To: help-gnu-emacs Drew Adams wrote: >> > Have a look at the messages buffer: C-x b *Messages* RET >> >> C-h e > > Or just click mouse-1 in the echo area (aka inactive minibuffer). .....^^^^.^^^^^ In Emacs, there is nothing "just" about "clicking" a mouse button. :P -- Joost Kremers joostkremers@fastmail.fm Selbst in die Unterwelt dringt durch Spalten Licht EN:SiS(9) ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-15 15:52 ` Joost Kremers @ 2014-07-15 15:57 ` Emanuel Berg [not found] ` <mailman.5463.1405440423.1147.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 32+ messages in thread From: Emanuel Berg @ 2014-07-15 15:57 UTC (permalink / raw) To: help-gnu-emacs Joost Kremers <joost.m.kremers@gmail.com> writes: > In Emacs, there is nothing "just" about "clicking" a > mouse button. :P You mean you can actually use the mouse in Emacs? o_O -- underground experts united ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <mailman.5463.1405440423.1147.help-gnu-emacs@gnu.org>]
* Re: run-with-timer does not display message [not found] ` <mailman.5463.1405440423.1147.help-gnu-emacs@gnu.org> @ 2014-07-15 16:07 ` Emanuel Berg 2014-07-15 16:12 ` Joost Kremers [not found] ` <<slrnlsakmh.a5k.joost.m.kremers@j.kremers4.news.arnhem.chello.nl> 2 siblings, 0 replies; 32+ messages in thread From: Emanuel Berg @ 2014-07-15 16:07 UTC (permalink / raw) To: help-gnu-emacs Drew Adams <drew.adams@oracle.com> writes: > Nonsense. It all depends what you are doing at the > time, and whether you use a mouse at all. Users and > use cases differ. > > If you must blather such nonsense, please at least do > not pretend to speak for Emacs ("in Emacs...") when > doing so. > > Emacs is not limited to any particular input > mechanism, whether it be keyboard, mouse, touchpad, > phone, *pad,... And that's a good thing. Yes... I think (know) that was a joke. -- underground experts united ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message [not found] ` <mailman.5463.1405440423.1147.help-gnu-emacs@gnu.org> 2014-07-15 16:07 ` Emanuel Berg @ 2014-07-15 16:12 ` Joost Kremers [not found] ` <mailman.5466.1405442248.1147.help-gnu-emacs@gnu.org> [not found] ` <<slrnlsakmh.a5k.joost.m.kremers@j.kremers4.news.arnhem.chello.nl> 2 siblings, 1 reply; 32+ messages in thread From: Joost Kremers @ 2014-07-15 16:12 UTC (permalink / raw) To: help-gnu-emacs Drew Adams wrote: >> In Emacs, there is nothing "just" about "clicking" a mouse button. :P > > Nonsense. It all depends what you are doing at the time, and whether > you use a mouse at all. Users and use cases differ. Erm... Note smiley... Apologies if I offended you, I was just making a joke. -- Joost Kremers joostkremers@fastmail.fm Selbst in die Unterwelt dringt durch Spalten Licht EN:SiS(9) ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <mailman.5466.1405442248.1147.help-gnu-emacs@gnu.org>]
* Re: run-with-timer does not display message [not found] ` <mailman.5466.1405442248.1147.help-gnu-emacs@gnu.org> @ 2014-07-16 1:12 ` Joost Kremers 2014-07-17 10:03 ` Matthias Pfeifer 0 siblings, 1 reply; 32+ messages in thread From: Joost Kremers @ 2014-07-16 1:12 UTC (permalink / raw) To: help-gnu-emacs Drew Adams wrote: > You don't offend me. Ok. The (IMHO) rather aggressive tone of your reaction suggested otherwise. > You mislead other Emacs users. Perhaps. Personally, though, I think those Emacs users will understand that it's just a joke and therefore either a) a personal opinion offered not as an argument but as an anecdote; or b) a subtle way of ridiculing the very attitude it appears to advocate; or c) a cheeky but ultimately harmless attempt to provoke a reaction. Anyways, I hope the OP got their run-with-timer working. -- Joost Kremers joostkremers@fastmail.fm Selbst in die Unterwelt dringt durch Spalten Licht EN:SiS(9) ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-16 1:12 ` Joost Kremers @ 2014-07-17 10:03 ` Matthias Pfeifer 0 siblings, 0 replies; 32+ messages in thread From: Matthias Pfeifer @ 2014-07-17 10:03 UTC (permalink / raw) To: help-gnu-emacs Thanks everybody for your advice. Misteriously it works now... 2014-07-16 3:12 GMT+02:00 Joost Kremers <joost.m.kremers@gmail.com>: > Drew Adams wrote: > > You don't offend me. > > Ok. The (IMHO) rather aggressive tone of your reaction suggested > otherwise. > > > You mislead other Emacs users. > > Perhaps. Personally, though, I think those Emacs users will understand > that it's just a joke and therefore either a) a personal opinion offered > not as an argument but as an anecdote; or b) a subtle way of ridiculing > the very attitude it appears to advocate; or c) a cheeky but ultimately > harmless attempt to provoke a reaction. > > Anyways, I hope the OP got their run-with-timer working. > > > -- > Joost Kremers joostkremers@fastmail.fm > Selbst in die Unterwelt dringt durch Spalten Licht > EN:SiS(9) > ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <<slrnlsakmh.a5k.joost.m.kremers@j.kremers4.news.arnhem.chello.nl>]
* RE: run-with-timer does not display message [not found] ` <<slrnlsakmh.a5k.joost.m.kremers@j.kremers4.news.arnhem.chello.nl> @ 2014-07-15 16:37 ` Drew Adams 0 siblings, 0 replies; 32+ messages in thread From: Drew Adams @ 2014-07-15 16:37 UTC (permalink / raw) To: Joost Kremers, help-gnu-emacs > >> In Emacs, there is nothing "just" about "clicking" a mouse button. :P > > > > Nonsense. It all depends what you are doing at the time, and whether > > you use a mouse at all. Users and use cases differ. > > Erm... Note smiley... Apologies if I offended you, I was just making a > joke. You don't offend me. You mislead other Emacs users. It's good to let users know of alternative behaviors, regardless of whether or when you or I might prefer to use them. It is important that there is not just one Emacs Way. In-Emacs-we-don't-use-a-mouse is not the right message, IMO. Even - or especially - when passed off as a snarky joke. FWIW: Had you written "Click mouse-1 in the echo area" I would likely have added "Or just use `C-h e'". It is good to know about both alternatives - each can be useful. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <<slrnlsaji8.a5k.joost.m.kremers@j.kremers4.news.arnhem.chello.nl>]
* RE: run-with-timer does not display message [not found] ` <<slrnlsaji8.a5k.joost.m.kremers@j.kremers4.news.arnhem.chello.nl> @ 2014-07-15 16:06 ` Drew Adams 0 siblings, 0 replies; 32+ messages in thread From: Drew Adams @ 2014-07-15 16:06 UTC (permalink / raw) To: Joost Kremers, help-gnu-emacs > >> > Have a look at the messages buffer: C-x b *Messages* RET > >> > >> C-h e > > > > Or just click mouse-1 in the echo area (aka inactive minibuffer). > .....^^^^.^^^^^ > > In Emacs, there is nothing "just" about "clicking" a mouse button. :P Nonsense. It all depends what you are doing at the time, and whether you use a mouse at all. Users and use cases differ. If you must blather such nonsense, please at least do not pretend to speak for Emacs ("in Emacs...") when doing so. Emacs is not limited to any particular input mechanism, whether it be keyboard, mouse, touchpad, phone, *pad,... And that's a good thing. ^ permalink raw reply [flat|nested] 32+ messages in thread
* run-with-timer does not display message @ 2014-07-15 13:47 Matthias Pfeifer 2014-07-15 13:53 ` Thorsten Jolitz [not found] ` <mailman.5455.1405432451.1147.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 32+ messages in thread From: Matthias Pfeifer @ 2014-07-15 13:47 UTC (permalink / raw) To: help-gnu-emacs Hi there, this may be a dump question but i could not find a good reason why it should not work as expected... I try to write a message to the messages buffer at some time in the future via run-with-timer (run-with-timer 5 nil '(lambda () (message "hello"))) however messge buffer does not get the message. Hints welcome... thanks in advance. Matthias ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-15 13:47 Matthias Pfeifer @ 2014-07-15 13:53 ` Thorsten Jolitz 2014-07-18 16:26 ` Stefan Monnier [not found] ` <mailman.5631.1405701027.1147.help-gnu-emacs@gnu.org> [not found] ` <mailman.5455.1405432451.1147.help-gnu-emacs@gnu.org> 1 sibling, 2 replies; 32+ messages in thread From: Thorsten Jolitz @ 2014-07-15 13:53 UTC (permalink / raw) To: help-gnu-emacs Matthias Pfeifer <mpfeifer77@gmail.com> writes: > Hi there, > > this may be a dump question but i could not find a good reason why it > should not work as expected... > > I try to write a message to the messages buffer at some time in the future > via run-with-timer > > (run-with-timer 5 nil '(lambda () (message "hello"))) > > however messge buffer does not get the message. Hints welcome... works for me using M-: (run-with-timer 5 nil '(lambda () (message "hello"))) ,---- | [nil 21445 12740 521048 nil (lambda nil (message "hello")) nil nil | 860000] | | hello `---- -- cheers, Thorsten ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-15 13:53 ` Thorsten Jolitz @ 2014-07-18 16:26 ` Stefan Monnier [not found] ` <mailman.5631.1405701027.1147.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 32+ messages in thread From: Stefan Monnier @ 2014-07-18 16:26 UTC (permalink / raw) To: help-gnu-emacs >> (run-with-timer 5 nil '(lambda () (message "hello"))) > M-: (run-with-timer 5 nil '(lambda () (message "hello"))) Please don't quote your lambdas! Stefan ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <mailman.5631.1405701027.1147.help-gnu-emacs@gnu.org>]
* Re: run-with-timer does not display message [not found] ` <mailman.5631.1405701027.1147.help-gnu-emacs@gnu.org> @ 2014-07-18 21:34 ` Emanuel Berg 2014-07-19 15:09 ` Sebastian Wiesner [not found] ` <mailman.5686.1405782584.1147.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 32+ messages in thread From: Emanuel Berg @ 2014-07-18 21:34 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: > Please don't quote your lambdas! Do you mean in that case or never? I have had problems with lambdas and both parameters and `let' bindings. For example, this works but not without the backtick/backquote (and the commas): (defun shortcut-to-file (key-prefix key file-prefix file) (global-set-key (format "%s%s" key-prefix key) `(lambda () (interactive) (do-show-file (format "%s%s" ,file-prefix ,file)) ))) And, at least (equal '(1 2 3) `(1 2 3)) => t (equal '(1 2) `(1 2 3)) => nil But I believe you, of course, just if you could elaborate some... -- underground experts united ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-18 21:34 ` Emanuel Berg @ 2014-07-19 15:09 ` Sebastian Wiesner 2014-07-19 15:27 ` Eli Zaretskii [not found] ` <mailman.5686.1405782584.1147.help-gnu-emacs@gnu.org> 1 sibling, 1 reply; 32+ messages in thread From: Sebastian Wiesner @ 2014-07-19 15:09 UTC (permalink / raw) To: Emanuel Berg; +Cc: help-gnu-emacs Am 18.07.2014 um 23:34 schrieb Emanuel Berg <embe8573@student.uu.se>: > Stefan Monnier <monnier@iro.umontreal.ca> writes: > >> Please don't quote your lambdas! > > Do you mean in that case or never? > > I have had problems with lambdas and both parameters > and `let' bindings. Enable lexical-binding in your Emacs Lisp files to avoid these. See https://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html and https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Lexical-Binding.html for details. > For example, this works but not without the > backtick/backquote (and the commas): With lexical binding it does. > (defun shortcut-to-file (key-prefix key file-prefix file) > (global-set-key > (format "%s%s" key-prefix key) > `(lambda () > (interactive) > (do-show-file (format "%s%s" ,file-prefix ,file)) ))) With lexical binding it works without any quoting: (defun shortcut-to-file (key-prefix key file-prefix file) (global-set-key (format "%s%s" key-prefix key) (lambda () (interactive) (do-show-file (format "%s%s" file-prefix file))))) The arguments are captured in a closure, and thus preserved when the lambda body is evaluated. This is more efficient than your variant. Lexical bindings are generally more efficient than dynamic ones, because local variables can be elided entirely, and the byte compiler can now inspect and byte-compile the lambda form. It’s also safer, because the byte compiler can now warn you about unused variables or free variables, which helps you to catch misspelled variable names. ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-19 15:09 ` Sebastian Wiesner @ 2014-07-19 15:27 ` Eli Zaretskii 2014-07-19 17:08 ` Stefan Monnier [not found] ` <mailman.5702.1405789759.1147.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 32+ messages in thread From: Eli Zaretskii @ 2014-07-19 15:27 UTC (permalink / raw) To: help-gnu-emacs > From: Sebastian Wiesner <swiesner@lunaryorn.com> > Date: Sat, 19 Jul 2014 17:09:32 +0200 > Cc: help-gnu-emacs@gnu.org > > > (defun shortcut-to-file (key-prefix key file-prefix file) > > (global-set-key > > (format "%s%s" key-prefix key) > > `(lambda () > > (interactive) > > (do-show-file (format "%s%s" ,file-prefix ,file)) ))) > > With lexical binding it works without any quoting: > > (defun shortcut-to-file (key-prefix key file-prefix file) > (global-set-key > (format "%s%s" key-prefix key) > (lambda () > (interactive) > (do-show-file (format "%s%s" file-prefix file))))) I don't think Stefan meant backtick-type of quoting. He meant this: > M-: (run-with-timer 5 nil '(lambda () (message "hello"))) ^^^^^^^^ ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-19 15:27 ` Eli Zaretskii @ 2014-07-19 17:08 ` Stefan Monnier 2014-07-19 18:04 ` Drew Adams [not found] ` <mailman.5702.1405789759.1147.help-gnu-emacs@gnu.org> 1 sibling, 1 reply; 32+ messages in thread From: Stefan Monnier @ 2014-07-19 17:08 UTC (permalink / raw) To: help-gnu-emacs > I don't think Stefan meant backtick-type of quoting. He meant this: >> M-: (run-with-timer 5 nil '(lambda () (message "hello"))) > ^^^^^^^^ Indeed. Of course, it's also good to avoid backquoting lambdas (typically by using lexical-binding instead), but I'm focusing on trying to kill the nasty '(lambda ...) habit that people keep reproducing all over the place because it appears in so many examples. Stefan ^ permalink raw reply [flat|nested] 32+ messages in thread
* RE: run-with-timer does not display message 2014-07-19 17:08 ` Stefan Monnier @ 2014-07-19 18:04 ` Drew Adams 0 siblings, 0 replies; 32+ messages in thread From: Drew Adams @ 2014-07-19 18:04 UTC (permalink / raw) To: Stefan Monnier, help-gnu-emacs > >> M-: (run-with-timer 5 nil '(lambda () (message "hello"))) > > ^^^^^^^^ > > I'm focusing on trying to kill the nasty '(lambda ...) habit that > people keep reproducing all over the place because it appears in > so many examples. And we might as well say *why* it should be killed: When you quote a lambda form, the code simply creates a *list* (whose car is `lambda' etc.) when it is evaluated. That list can then be interpreted as a function (or not, depending on the context - it is just a list). But if you do not quote, then the lambda form is understood immediately as being a *function*. And that means that occurrences of that function can be byte-compiled etc. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <mailman.5702.1405789759.1147.help-gnu-emacs@gnu.org>]
* Re: run-with-timer does not display message [not found] ` <mailman.5702.1405789759.1147.help-gnu-emacs@gnu.org> @ 2014-07-19 17:43 ` Emanuel Berg 2014-07-19 18:12 ` Stefan Monnier ` (3 more replies) 0 siblings, 4 replies; 32+ messages in thread From: Emanuel Berg @ 2014-07-19 17:43 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: >> I don't think Stefan meant backtick-type of quoting. >> He meant this: >> >> M-: (run-with-timer 5 nil '(lambda ... > > Indeed. Yes, of course I understood that because that was the only quoting going on. That's why I supplied the `equal' example that seems to indicate that quoting and backticking (without commas) are equal (?). Here is what I remember from this - I'm shooting from the holster (a bit) here, feel free to correct misconceptions/-assumptions: OK, dynamic scope is when everything is looked up only when needed, that's the dynamic (time) thing to it, because things can be different at different times. This is what makes the whole dynamic environment in Emacs possible which, by comparison, makes even cool languages like C a pain to work with for large, interactive systems... Lexical scope is when things are encoded once and then they don't change because they are passed around as they are. Because they can be encoded different things it makes sense calling this lexical (because the value is simply read, not looked up) and not "static". This corresponds to an extent to call-by-value/call-by-reference, and in compiled languages there are super-advanced use of pointers and heap data structures to make up for the lack of "the dynamic". Questions: 1. How do I put Emacs in lexical mode? Do I do that temporarily (?!) with a Elisp block around certain code? Or is it a global option? If so, won't that screw up everything else in unpredictable ways? Also, isn't there some hybrid mode where this gets sorted out in the background? 2. Interestingly, what I can see, my method, with backticks and commas, isn't that "lexical" - because then, there, the actual values are inserted? -- underground experts united ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-19 17:43 ` Emanuel Berg @ 2014-07-19 18:12 ` Stefan Monnier 2014-07-20 12:15 ` Sebastian Wiesner ` (2 subsequent siblings) 3 siblings, 0 replies; 32+ messages in thread From: Stefan Monnier @ 2014-07-19 18:12 UTC (permalink / raw) To: help-gnu-emacs > Because they can be encoded different things it makes sense calling > this lexical (because the value is simply read, not looked up) and not > "static". It's also called "static scoping". And the name doesn't have much to do with the implementation technique used. It's called "lexical" because the way a particular identifier use is matched to a particular variable only depends on the shape of the program text rather than depending on its run-time behavior. > This corresponds to an extent to > call-by-value/call-by-reference, No. CBV/CBR/CBN are orthogonal concepts to static/dynamic scoping. > 1. How do I put Emacs in lexical mode? Do I do that Put -*- lexical-binding:t -*- somewhere on the first line of your Elisp file. Stefan ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-19 17:43 ` Emanuel Berg 2014-07-19 18:12 ` Stefan Monnier @ 2014-07-20 12:15 ` Sebastian Wiesner 2014-07-21 13:26 ` Stefan Monnier [not found] ` <mailman.5708.1405793578.1147.help-gnu-emacs@gnu.org> [not found] ` <mailman.5754.1405858540.1147.help-gnu-emacs@gnu.org> 3 siblings, 1 reply; 32+ messages in thread From: Sebastian Wiesner @ 2014-07-20 12:15 UTC (permalink / raw) To: help-gnu-emacs; +Cc: Emanuel Berg Am Samstag, 19. Juli 2014, 19:43:16 schrieb Emanuel Berg: > 2. Interestingly, what I can see, my method, with > backticks and commas, isn't that "lexical" - because > then, there, the actual values are inserted? Note quite. The backquote is “static” in that it captures the *value* of the variable at the time the backquote is evaluated. “Lexical” binding captures the *variable itself*. This makes a difference if the variable is changed after capturing. Considering the following example: ELISP> (let ((i 10)) (setq f-lexical (lambda () i)) (setq f-backquote `(lambda () ,i)) (setq i 20)) 20 (#o24, #x14, ?\C-t) ELISP> (funcall f-lexical) 20 (#o24, #x14, ?\C-t) ELISP> (funcall f-backquote) 10 (#o12, #xa, ?\C-j) As you can see, changing "i" *after* creating the functions only affects the closure created by lexical binding. The function created by the backquote is left untouched. This specific behaviour is what makes lexical binding special: Capturing *lexical variables* in closures, as opposed to capturing values (by backquotes) or just using dynamic variables. You cannot easily and efficiently emulated this behaviour with macros and backquotes. ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-20 12:15 ` Sebastian Wiesner @ 2014-07-21 13:26 ` Stefan Monnier 0 siblings, 0 replies; 32+ messages in thread From: Stefan Monnier @ 2014-07-21 13:26 UTC (permalink / raw) To: help-gnu-emacs > This specific behaviour is what makes lexical binding special: Capturing > *lexical variables* in closures, as opposed to capturing values (by > backquotes) While this is used occasionally, most uses of lexical-scoping don't care about this "feature". E.g. *all* uses of lexical scoping in the ML family of languages (which don't have the equivalent of `setq'). > or just using dynamic variables. You cannot easily and > efficiently emulated this behaviour with macros and backquotes. As mentioned in another message, the byte-compiler faces the same problem. And the way it solves it can be applied to backquoted lambdas just as easily: just replace the variable with a cons cell whose `car' contains the value. IOW the byte-compiler will generate almost 100% exactly the same code for (let ((i 10)) (setq f-lexical (lambda () i)) (setq i 20)) as for (let ((i (list 10))) (setq f-lexical (lambda () (car i))) (setcar i 20)) and of course you can get the same result with backquote: (let ((i (list 10))) (setq f-lexical `(lambda () (car ',i))) (setcar i 20)) -- Stefan ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <mailman.5708.1405793578.1147.help-gnu-emacs@gnu.org>]
* Re: run-with-timer does not display message [not found] ` <mailman.5708.1405793578.1147.help-gnu-emacs@gnu.org> @ 2014-07-20 19:27 ` Emanuel Berg 2014-07-21 13:29 ` Stefan Monnier [not found] ` <mailman.5813.1405950328.1147.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 32+ messages in thread From: Emanuel Berg @ 2014-07-20 19:27 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: >> Because they can be encoded different things it >> makes sense calling this lexical (because the value >> is simply read, not looked up) and not "static". > > It's also called "static scoping". And the name > doesn't have much to do with the implementation > technique used. It's called "lexical" because the way > a particular identifier use is matched to a particular > variable only depends on the shape of the program text > rather than depending on its run-time behavior. > > ... > > No. CBV/CBR/CBN are orthogonal concepts to > static/dynamic scoping. Isn't CBR and dynamic alike in the sense than a value is looked up somewhere outside of the "scope", say a function in C, while CBV is lexical as the parameter is just a way to refer to a value for convenience? I don't know what CBN (call by name?) is but that in the above sense would be dynamic as the name, once put to use, is replaced by a value and that value has to be looked up at that time. If a reference is used as a reference, i.e., ignoring what it refers to, then of course it is all the same. It has to be looked up but otherwise why do it at all? >> 1. How do I put Emacs in lexical mode? Do I do that > > Put -*- lexical-binding:t -*- somewhere on the first > line of your Elisp file. So you can't do it for a specific function? I'm starting to lean toward me preferring the backtick-comma solution... -- underground experts united ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-20 19:27 ` Emanuel Berg @ 2014-07-21 13:29 ` Stefan Monnier [not found] ` <mailman.5813.1405950328.1147.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 32+ messages in thread From: Stefan Monnier @ 2014-07-21 13:29 UTC (permalink / raw) To: help-gnu-emacs >>> 1. How do I put Emacs in lexical mode? Do I do that >> Put -*- lexical-binding:t -*- somewhere on the first >> line of your Elisp file. > So you can't do it for a specific function? No. > I'm starting to lean toward me preferring the backtick-comma > solution... 99.9% of existing dynamically scoped Emacs Lisp will work just as well with lexical-binding. And the remaining 0.1% can usually be fixed very easily by adding a few (defvar <myvar>). Stefan ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <mailman.5813.1405950328.1147.help-gnu-emacs@gnu.org>]
* Re: run-with-timer does not display message [not found] ` <mailman.5813.1405950328.1147.help-gnu-emacs@gnu.org> @ 2014-07-21 22:17 ` Emanuel Berg 2014-07-24 8:25 ` Stefan Monnier 0 siblings, 1 reply; 32+ messages in thread From: Emanuel Berg @ 2014-07-21 22:17 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: > 99.9% of existing dynamically scoped Emacs Lisp will > work just as well with lexical-binding. And the > remaining 0.1% can usually be fixed very easily by > adding a few (defvar <myvar>). Do you think lexical scope is better for general purposes and the Joe Elisp Hacker? -- underground experts united ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: run-with-timer does not display message 2014-07-21 22:17 ` Emanuel Berg @ 2014-07-24 8:25 ` Stefan Monnier 0 siblings, 0 replies; 32+ messages in thread From: Stefan Monnier @ 2014-07-24 8:25 UTC (permalink / raw) To: help-gnu-emacs > Do you think lexical scope is better for general > purposes and the Joe Elisp Hacker? Absolutely. Stefan ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <mailman.5754.1405858540.1147.help-gnu-emacs@gnu.org>]
* Re: run-with-timer does not display message [not found] ` <mailman.5754.1405858540.1147.help-gnu-emacs@gnu.org> @ 2014-07-20 19:37 ` Emanuel Berg 2014-07-20 20:11 ` Drew Adams 0 siblings, 1 reply; 32+ messages in thread From: Emanuel Berg @ 2014-07-20 19:37 UTC (permalink / raw) To: help-gnu-emacs Sebastian Wiesner <swiesner@lunaryorn.com> writes: >> 2. Interestingly, what I can see, my method, with >> backticks and commas, isn't that "lexical" - because >> then, there, the actual values are inserted? > > Note quite. The backquote is “static” in that it > captures the *value* of the variable at the time the > backquote is evaluated. “Lexical” binding captures > the *variable itself*. Yes, the backtick-comma is to downright hard-code it, although it is code, and not a human, who do the hard-coding... > This makes a difference if the variable is changed > after capturing. Considering the following example > ... > > As you can see, changing "i" *after* creating the > functions only affects the closure created by lexical > binding. The function created by the backquote is > left untouched. Yes, that is clear, but this example shows (to me) the difference between using hard-coded values and using variables (in general). That example looks all-fine to me. Are you saying, with dynamic scope, the `i' in the lambda wouldn't have been affected by the `setq'? But to me, your example is the way it should be, natural... Why then, would you want to use dynamic scope, and why is it the default? -- underground experts united ^ permalink raw reply [flat|nested] 32+ messages in thread
* RE: run-with-timer does not display message 2014-07-20 19:37 ` Emanuel Berg @ 2014-07-20 20:11 ` Drew Adams 0 siblings, 0 replies; 32+ messages in thread From: Drew Adams @ 2014-07-20 20:11 UTC (permalink / raw) To: Emanuel Berg, help-gnu-emacs > Why...would you want to use dynamic scope, and why is it the default? RMS replied to your question (a quarter-century before you posed it): http://www.gnu.org/software/emacs/emacs-paper.html#SEC17 ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <mailman.5686.1405782584.1147.help-gnu-emacs@gnu.org>]
* Re: run-with-timer does not display message [not found] ` <mailman.5686.1405782584.1147.help-gnu-emacs@gnu.org> @ 2014-07-19 17:49 ` Emanuel Berg 0 siblings, 0 replies; 32+ messages in thread From: Emanuel Berg @ 2014-07-19 17:49 UTC (permalink / raw) To: help-gnu-emacs Sebastian Wiesner <swiesner@lunaryorn.com> writes: > Enable lexical-binding in your Emacs Lisp files to > avoid these ... Thank you for that information and the URLs. Check out my other post if you like. I'll read those links and try to get it to work - of course, it already works, but still, there aren't any advantages that are small enough not to explore. -- underground experts united ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <mailman.5455.1405432451.1147.help-gnu-emacs@gnu.org>]
* Re: run-with-timer does not display message [not found] ` <mailman.5455.1405432451.1147.help-gnu-emacs@gnu.org> @ 2014-07-15 15:35 ` Emanuel Berg 0 siblings, 0 replies; 32+ messages in thread From: Emanuel Berg @ 2014-07-15 15:35 UTC (permalink / raw) To: help-gnu-emacs Thorsten Jolitz <tjolitz@gmail.com> writes: > works for me using > > M-: (run-with-timer 5 nil '(lambda () (message "hello"))) Yes, works for me as well using the above code and `C-x C-e' or `eval-last-sexp' (which here should be equivalent to `M-:' or `eval-expression'). "hello" appears in the echo area as well as the message buffer. -- underground experts united ^ permalink raw reply [flat|nested] 32+ messages in thread
end of thread, other threads:[~2014-07-24 8:25 UTC | newest] Thread overview: 32+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <mailman.5454.1405432029.1147.help-gnu-emacs@gnu.org> 2014-07-15 14:34 ` run-with-timer does not display message Joost Kremers 2014-07-15 15:18 ` jduthen 2014-07-15 15:20 ` Joost Kremers 2014-07-15 15:40 ` Drew Adams [not found] ` <mailman.5461.1405438875.1147.help-gnu-emacs@gnu.org> 2014-07-15 15:52 ` Joost Kremers 2014-07-15 15:57 ` Emanuel Berg [not found] ` <mailman.5463.1405440423.1147.help-gnu-emacs@gnu.org> 2014-07-15 16:07 ` Emanuel Berg 2014-07-15 16:12 ` Joost Kremers [not found] ` <mailman.5466.1405442248.1147.help-gnu-emacs@gnu.org> 2014-07-16 1:12 ` Joost Kremers 2014-07-17 10:03 ` Matthias Pfeifer [not found] ` <<slrnlsakmh.a5k.joost.m.kremers@j.kremers4.news.arnhem.chello.nl> 2014-07-15 16:37 ` Drew Adams [not found] ` <<slrnlsaji8.a5k.joost.m.kremers@j.kremers4.news.arnhem.chello.nl> 2014-07-15 16:06 ` Drew Adams 2014-07-15 13:47 Matthias Pfeifer 2014-07-15 13:53 ` Thorsten Jolitz 2014-07-18 16:26 ` Stefan Monnier [not found] ` <mailman.5631.1405701027.1147.help-gnu-emacs@gnu.org> 2014-07-18 21:34 ` Emanuel Berg 2014-07-19 15:09 ` Sebastian Wiesner 2014-07-19 15:27 ` Eli Zaretskii 2014-07-19 17:08 ` Stefan Monnier 2014-07-19 18:04 ` Drew Adams [not found] ` <mailman.5702.1405789759.1147.help-gnu-emacs@gnu.org> 2014-07-19 17:43 ` Emanuel Berg 2014-07-19 18:12 ` Stefan Monnier 2014-07-20 12:15 ` Sebastian Wiesner 2014-07-21 13:26 ` Stefan Monnier [not found] ` <mailman.5708.1405793578.1147.help-gnu-emacs@gnu.org> 2014-07-20 19:27 ` Emanuel Berg 2014-07-21 13:29 ` Stefan Monnier [not found] ` <mailman.5813.1405950328.1147.help-gnu-emacs@gnu.org> 2014-07-21 22:17 ` Emanuel Berg 2014-07-24 8:25 ` Stefan Monnier [not found] ` <mailman.5754.1405858540.1147.help-gnu-emacs@gnu.org> 2014-07-20 19:37 ` Emanuel Berg 2014-07-20 20:11 ` Drew Adams [not found] ` <mailman.5686.1405782584.1147.help-gnu-emacs@gnu.org> 2014-07-19 17:49 ` Emanuel Berg [not found] ` <mailman.5455.1405432451.1147.help-gnu-emacs@gnu.org> 2014-07-15 15:35 ` Emanuel Berg
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).