* flet, cl-flet, cl-letf in 24.3
@ 2013-04-21 7:04 ndemmel
2013-04-21 7:41 ` Drew Adams
[not found] ` <mailman.24402.1366530089.855.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 9+ messages in thread
From: ndemmel @ 2013-04-21 7:04 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
it seems that from 24.3 on flet is marked as obsolete, to be replaced by cl-flet or cl-letf. If you are fine with lexical scope, cl-flet is your friend. However, I did not find explicit documentation on what to do when you want to keep relying on the dynamic scope as with the old flet. Is (cl-letf (((symbol-function 'foo) #'(lambda (...) ...))) ...) the suggested method? Does that give always have dynamic scope? I'm a bit confused.
Best,
Niko
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: flet, cl-flet, cl-letf in 24.3
2013-04-21 7:04 flet, cl-flet, cl-letf in 24.3 ndemmel
@ 2013-04-21 7:41 ` Drew Adams
[not found] ` <mailman.24402.1366530089.855.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 9+ messages in thread
From: Drew Adams @ 2013-04-21 7:41 UTC (permalink / raw)
To: ndemmel, help-gnu-emacs
> it seems that from 24.3 on flet is marked as obsolete, to be
> replaced by cl-flet or cl-letf. If you are fine with lexical
> scope, cl-flet is your friend. However, I did not find
> explicit documentation on what to do when you want to keep
> relying on the dynamic scope as with the old flet. Is
> (cl-letf (((symbol-function 'foo) #'(lambda (...) ...))) ...)
> the suggested method? Does that give always have dynamic
> scope? I'm a bit confused.
If you have read the doc and you feel it does not make things clear, consider
filing a doc bug: `M-x report-emacs-bug'.
^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <mailman.24402.1366530089.855.help-gnu-emacs@gnu.org>]
* Re: flet, cl-flet, cl-letf in 24.3
[not found] ` <mailman.24402.1366530089.855.help-gnu-emacs@gnu.org>
@ 2013-04-21 9:49 ` ndemmel
2013-04-21 16:07 ` Drew Adams
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: ndemmel @ 2013-04-21 9:49 UTC (permalink / raw)
To: help-gnu-emacs
On Sunday, April 21, 2013 9:41:11 AM UTC+2, Drew Adams wrote:
> > it seems that from 24.3 on flet is marked as obsolete, to be
>
> > replaced by cl-flet or cl-letf. If you are fine with lexical
>
> > scope, cl-flet is your friend. However, I did not find
>
> > explicit documentation on what to do when you want to keep
>
> > relying on the dynamic scope as with the old flet. Is
>
> > (cl-letf (((symbol-function 'foo) #'(lambda (...) ...))) ...)
>
> > the suggested method? Does that give always have dynamic
>
> > scope? I'm a bit confused.
>
>
>
> If you have read the doc and you feel it does not make things clear, consider
>
> filing a doc bug: `M-x report-emacs-bug'.
I don't even have emacs 24.3 installed. I'm referring to the documentation [1,2,3,4]. Together with the notification
`flet' is an obsolete macro (as of 24.3); use either `cl-flet' or `cl-letf'.
as reported here [5], this documentation does not really tell me what to do if I want to keep relying on the dynamic scoping of flet. A brief google search [6] leads me to believe that
(cl-letf (((symbol-function 'foo) #'(lambda (...) ...))) ...)
is the suggested solution, however I wanted to make sure that is the case.
In any case if that were the sugggested way, it should maybe be added to one of the documentation sites [1,2,3,4]. I'd be happy to file a report on that.
Cheers,
Niko
[1] http://www.gnu.org/software/emacs/manual/html_node/cl/Function-Bindings.html#index-cl_002dflet-24
[2] http://www.gnu.org/software/emacs/manual/html_node/cl/Obsolete-Macros.html#index-flet-173
[3] http://www.gnu.org/software/emacs/manual/html_node/cl/Obsolete-Macros.html#index-letf-175
[4] http://www.gnu.org/software/emacs/manual/html_node/cl/Modify-Macros.html#index-cl_002dletf-19
[5] https://github.com/moesenle/rosemacs-debs/issues/2
[6] https://groups.google.com/forum/#!msg/gnu.emacs.help/eaopyFH5hmY/emHfn-DYZZIJ
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: flet, cl-flet, cl-letf in 24.3
2013-04-21 9:49 ` ndemmel
@ 2013-04-21 16:07 ` Drew Adams
2013-04-22 13:32 ` Stefan Monnier
[not found] ` <mailman.24438.1366637539.855.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2013-04-21 16:07 UTC (permalink / raw)
To: ndemmel, help-gnu-emacs
> > If you have read the doc and you feel it does not make
> > things clear, consider filing a doc bug: `M-x report-emacs-bug'.
>
> I don't even have emacs 24.3 installed. I'm referring to the
> documentation [1,2,3,4]. Together with the notification
> `flet' is an obsolete macro (as of 24.3); use either
> `cl-flet' or `cl-letf'.
> as reported here [5], this documentation does not really tell
> me what to do if I want to keep relying on the dynamic
> scoping of flet. A brief google search [6] leads me to believe
> that (cl-letf (((symbol-function 'foo) #'(lambda (...) ...))) ...)
> is the suggested solution, however I wanted to make sure that
> is the case.
It is good to ask the question here, of course, and someone will likely post a
good answer soon.
> In any case if that were the sugggested way, it should maybe
> be added to one of the documentation sites [1,2,3,4]. I'd be
> happy to file a report on that.
Please do. That can help Emacs Dev understand what might need to be done to
make things clearer. If there is a misunderstanding wrt the references you
cite, Emacs Dev will likely let you know that too. Just becoming aware of a
misunderstanding can be helpful input to those trying to communicate better.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: flet, cl-flet, cl-letf in 24.3
2013-04-21 9:49 ` ndemmel
2013-04-21 16:07 ` Drew Adams
@ 2013-04-22 13:32 ` Stefan Monnier
2013-04-22 15:09 ` Andreas Röhler
[not found] ` <mailman.24438.1366637539.855.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2013-04-22 13:32 UTC (permalink / raw)
To: help-gnu-emacs
> as reported here [5], this documentation does not really tell me what to do
> if I want to keep relying on the dynamic scoping of flet. A brief google
> search [6] leads me to believe that
> (cl-letf (((symbol-function 'foo) #'(lambda (...) ...))) ...)
> is the suggested solution,
That's the case.
> Does that always have dynamic scope?
How could it not?
> however I wanted to make sure that is the case.
Even better in most cases is:
(defvar my-enable-foo-advice nil)
(defadvice foo (...)
(if my-enable-foo-advice ... ...))
and then replace (flet ((foo ...)) ...)
with (let ((my-enable-foo-advice t)) ...)
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: flet, cl-flet, cl-letf in 24.3
2013-04-22 13:32 ` Stefan Monnier
@ 2013-04-22 15:09 ` Andreas Röhler
0 siblings, 0 replies; 9+ messages in thread
From: Andreas Röhler @ 2013-04-22 15:09 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org List; +Cc: Stefan Monnier
Am 22.04.2013 15:32, schrieb Stefan Monnier:
>> as reported here [5], this documentation does not really tell me what to do
>> if I want to keep relying on the dynamic scoping of flet. A brief google
>> search [6] leads me to believe that
>
>> (cl-letf (((symbol-function 'foo) #'(lambda (...) ...))) ...)
>
>> is the suggested solution,
>
> That's the case.
>
>> Does that always have dynamic scope?
>
> How could it not?
>
>> however I wanted to make sure that is the case.
>
> Even better in most cases is:
>
> (defvar my-enable-foo-advice nil)
> (defadvice foo (...)
> (if my-enable-foo-advice ... ...))
>
> and then replace (flet ((foo ...)) ...)
> with (let ((my-enable-foo-advice t)) ...)
>
>
> Stefan
>
>
>
Hi Stefan,
until now, a let bound variable was easy to use, there was no difficulty wrt global namespace.
From this would expect some confusion, as a defvar is Emacs-wide. Isn't a defvar setting init-value only at first time?
I.e. if another program already used (defvar my-enable-foo-advice 'my-init-value)
(defvar my-enable-foo-advice nil) should have not effect.
May someone point me to the thread where that was discussed?
Thanks,
Andreas
^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <mailman.24438.1366637539.855.help-gnu-emacs@gnu.org>]
* Re: flet, cl-flet, cl-letf in 24.3
[not found] ` <mailman.24438.1366637539.855.help-gnu-emacs@gnu.org>
@ 2013-04-27 11:16 ` ndemmel
2013-04-27 11:46 ` Pascal J. Bourguignon
2013-04-27 13:52 ` Stefan Monnier
0 siblings, 2 replies; 9+ messages in thread
From: ndemmel @ 2013-04-27 11:16 UTC (permalink / raw)
To: help-gnu-emacs
On Monday, April 22, 2013 3:32:05 PM UTC+2, Stefan Monnier wrote:
> > as reported here [5], this documentation does not really tell me what to do
>
> > if I want to keep relying on the dynamic scoping of flet. A brief google
>
> > search [6] leads me to believe that
>
>
>
> > (cl-letf (((symbol-function 'foo) #'(lambda (...) ...))) ...)
>
>
>
> > is the suggested solution,
>
>
>
> That's the case.
Thanks!
>
> > Does that always have dynamic scope?
>
> How could it not?
>
I'm not sure. What makes you say that? I can see how a lexical binding to a generalized place (not a variable) would not neccessarily make sense; is that what you mean? Otoh cl-flet does exactly that, for the special case of (symbol-function ...), or is that not how I should view it?
>
> > however I wanted to make sure that is the case.
>
>
>
> Even better in most cases is:
>
>
>
> (defvar my-enable-foo-advice nil)
>
> (defadvice foo (...)
>
> (if my-enable-foo-advice ... ...))
>
>
>
> and then replace (flet ((foo ...)) ...)
>
> with (let ((my-enable-foo-advice t)) ...)
>
I see. In my case I was concerned with keeping legacy code working without changing much.
Thanks!
Niko
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: flet, cl-flet, cl-letf in 24.3
2013-04-27 11:16 ` ndemmel
@ 2013-04-27 11:46 ` Pascal J. Bourguignon
2013-04-27 13:52 ` Stefan Monnier
1 sibling, 0 replies; 9+ messages in thread
From: Pascal J. Bourguignon @ 2013-04-27 11:46 UTC (permalink / raw)
To: help-gnu-emacs
ndemmel@gmail.com writes:
> On Monday, April 22, 2013 3:32:05 PM UTC+2, Stefan Monnier wrote:
>> > as reported here [5], this documentation does not really tell me what to do
>>
>> > if I want to keep relying on the dynamic scoping of flet. A brief google
>>
>> > search [6] leads me to believe that
>>
>>
>>
>> > (cl-letf (((symbol-function 'foo) #'(lambda (...) ...))) ...)
>>
>>
>>
>> > is the suggested solution,
>>
>>
>>
>> That's the case.
>
> Thanks!
>
>>
>> > Does that always have dynamic scope?
>>
>> How could it not?
>>
>
> I'm not sure. What makes you say that?
That's because it's not until run-time that the function slot of the
symbol foo is modified. The _expression_ is evaluated at run-time.
Here we have a literal anonymous function, but it could be any
expression returning a function determined at run-time.
Therefore there's absolutely no way the compiler can know what (foo x)
means inside the cl-letf (apart from the fact that it's a function
call).
Also, since (symbol-function 'foo) is a global place, _while_ the cl-letf
is in effect, (foo x) will call your lambda even outside of the lexical
scope of the cl-letf.
> I can see how a lexical binding
> to a generalized place (not a variable) would not neccessarily make
> sense; is that what you mean?
Indeed.
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: flet, cl-flet, cl-letf in 24.3
2013-04-27 11:16 ` ndemmel
2013-04-27 11:46 ` Pascal J. Bourguignon
@ 2013-04-27 13:52 ` Stefan Monnier
1 sibling, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2013-04-27 13:52 UTC (permalink / raw)
To: help-gnu-emacs
> I see. In my case I was concerned with keeping legacy code working
> without changing much.
Then you don't need to change anything, since flet still works
as before.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-04-27 13:52 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-21 7:04 flet, cl-flet, cl-letf in 24.3 ndemmel
2013-04-21 7:41 ` Drew Adams
[not found] ` <mailman.24402.1366530089.855.help-gnu-emacs@gnu.org>
2013-04-21 9:49 ` ndemmel
2013-04-21 16:07 ` Drew Adams
2013-04-22 13:32 ` Stefan Monnier
2013-04-22 15:09 ` Andreas Röhler
[not found] ` <mailman.24438.1366637539.855.help-gnu-emacs@gnu.org>
2013-04-27 11:16 ` ndemmel
2013-04-27 11:46 ` Pascal J. Bourguignon
2013-04-27 13:52 ` Stefan Monnier
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).