From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: Temporary changing the behavior of a function Date: Fri, 06 Nov 2015 17:05:38 +0100 Message-ID: <87611f9kq5.fsf@mbork.pl> References: <87lhaba0kh.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1446825988 11187 80.91.229.3 (6 Nov 2015 16:06:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Nov 2015 16:06:28 +0000 (UTC) Cc: Help Gnu Emacs mailing list To: Yuri Khan Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 06 17:06:20 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZujWt-00046U-HL for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Nov 2015 17:06:19 +0100 Original-Received: from localhost ([::1]:39684 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZujWt-00023y-4H for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Nov 2015 11:06:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZujWa-0001zt-Hj for help-gnu-emacs@gnu.org; Fri, 06 Nov 2015 11:06:01 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZujWW-0005uN-CO for help-gnu-emacs@gnu.org; Fri, 06 Nov 2015 11:06:00 -0500 Original-Received: from mail.mojserwer.eu ([2a01:5e00:2:52::8]:42828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZujWW-0005tc-5n for help-gnu-emacs@gnu.org; Fri, 06 Nov 2015 11:05:56 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 89AE98F2008; Fri, 6 Nov 2015 17:05:55 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3qtSfGlnmg3T; Fri, 6 Nov 2015 17:05:47 +0100 (CET) Original-Received: from localhost (unknown [109.232.24.28]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 785208F2004; Fri, 6 Nov 2015 17:05:47 +0100 (CET) User-agent: mu4e 0.9.15; emacs 25.0.50.1 In-reply-to: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:5e00:2:52::8 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:107973 Archived-At: On 2015-11-06, at 16:01, Yuri Khan wrote: > On Fri, Nov 6, 2015 at 4:23 PM, Marcin Borkowski 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' wi= th >> :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 =E2=80=9Csmell=E2= =80=9D, a sign > of possibly bad design. > > =E2=80=9Cfoo=E2=80=9D should have optional arguments that can be passed= by the calling > code, and if they are not set, only then ask =E2=80=9Cbar=E2=80=9D for = user-supplied > parameters. > > Alternatively, =E2=80=9Cfoo=E2=80=9D should invoke =E2=80=9Cbar=E2=80=9D= and pass its result to > =E2=80=9Cfoo-guts=E2=80=9D (we usually call it =E2=80=9Cfoo-impl=E2=80=9D= or =E2=80=9Cdo-foo=E2=80=9D), and > programmatic callers should call =E2=80=9Cfoo-guts=E2=80=9D directly wi= th the right > arguments. > > If =E2=80=9Cfoo=E2=80=9D is in a third-party library you cannot or woul= d rather not > change, only then consider monkey-patching =E2=80=9Cbar=E2=80=9D as a w= orkaround. 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, --=20 Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University