From: Marcin Borkowski <mbork@mbork.pl>
To: Yuri Khan <yuri.v.khan@gmail.com>
Cc: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: Temporary changing the behavior of a function
Date: Fri, 06 Nov 2015 17:05:38 +0100 [thread overview]
Message-ID: <87611f9kq5.fsf@mbork.pl> (raw)
In-Reply-To: <CAP_d_8UbvnwDYuoe=r7CKvNHvjACsP=1CRf8QdSnfwY7Z1_d7g@mail.gmail.com>
On 2015-11-06, at 16:01, Yuri Khan <yuri.v.khan@gmail.com> wrote:
> On Fri, Nov 6, 2015 at 4:23 PM, Marcin Borkowski <mbork@mbork.pl> wrote:
>
>> so there is this function `foo', which calls the function `bar'. The
>> function `bar' is responsible for asking the user for some value and
>> passing that value to the guts of `foo'.
>>
>> Now I want to call `foo' in the Mafia-mode;-), i.e., it should ask no
>> further questions. What do I do? AFAIU, `cl-flet' won't help, since it
>> is lexical. The best I can think of is to temporarily advice `bar' with
>> :override - but then, instead of a `let'-like, local construct, I have
>> to explicitly add and then remove the advice, right?
>>
>> Any other ideas?
>
> Yes. In other languages, we recognize such a need as a “smell”, a sign
> of possibly bad design.
>
> “foo” should have optional arguments that can be passed by the calling
> code, and if they are not set, only then ask “bar” for user-supplied
> parameters.
>
> Alternatively, “foo” should invoke “bar” and pass its result to
> “foo-guts” (we usually call it “foo-impl” or “do-foo”), and
> programmatic callers should call “foo-guts” directly with the right
> arguments.
>
> If “foo” is in a third-party library you cannot or would rather not
> change, only then consider monkey-patching “bar” as a workaround.
All agreed, and that was my first thought, too. Of course, both `foo'
and `bar' are in some library I cannot change ATM. (That will wait
until I sign the FSF papers;-).)
OTOH, I /can/ imagine that the author did not anticipate such use: `foo'
is called only once in the whole (big) library, and then by another
interactive command, for which the user interaction is fine.
Thanks anyway,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
next prev parent reply other threads:[~2015-11-06 16:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-06 10:23 Temporary changing the behavior of a function Marcin Borkowski
2015-11-06 13:03 ` Stefan Monnier
2015-11-06 16:06 ` Marcin Borkowski
2015-11-06 15:01 ` Yuri Khan
2015-11-06 16:05 ` Marcin Borkowski [this message]
2015-11-06 18:06 ` Michael Heerdegen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87611f9kq5.fsf@mbork.pl \
--to=mbork@mbork.pl \
--cc=help-gnu-emacs@gnu.org \
--cc=yuri.v.khan@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.