From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.help Subject: Re: Temporary changing the behavior of a function Date: Fri, 6 Nov 2015 21:01:03 +0600 Message-ID: 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 1446822105 8533 80.91.229.3 (6 Nov 2015 15:01:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Nov 2015 15:01:45 +0000 (UTC) Cc: Help Gnu Emacs mailing list To: Marcin Borkowski Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 06 16:01:44 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 1ZuiWO-0000HV-HD for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Nov 2015 16:01:44 +0100 Original-Received: from localhost ([::1]:39229 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuiWO-0007Zx-0S for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Nov 2015 10:01:44 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuiWC-0007Zm-G7 for help-gnu-emacs@gnu.org; Fri, 06 Nov 2015 10:01:33 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZuiW6-0007Gw-Ce for help-gnu-emacs@gnu.org; Fri, 06 Nov 2015 10:01:32 -0500 Original-Received: from mail-lf0-x22c.google.com ([2a00:1450:4010:c07::22c]:34439) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuiW6-0007FU-5h for help-gnu-emacs@gnu.org; Fri, 06 Nov 2015 10:01:26 -0500 Original-Received: by lfgh9 with SMTP id h9so73114577lfg.1 for ; Fri, 06 Nov 2015 07:01:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=qPn+AcuHA0oS33LXmLsffrPqkFmmTprsaW40QO8IU44=; b=URTQL10z6/SRWsL3PIm3ENPqOf2ZYRqA90kWSNcG4LXxSJVQJr3ZhbjthgsawIhhZ6 UeC9srKDgNkQ+R6qIT1boBMLbFL2rPtcz0z5uH+xtEO7+GNnz20BAzjnlgQ7IJSDogVn cyw0Hs7A4KNC60dzUL+sUvz2EU5R4aUYiAiKaP2N4RnA/6YqDi/VS4QT4BiRZYcZeTxZ kDFA7LuwfyTj/X+1EHtqBxIS1RxLLkoGCu6NW4q953Joa8ADLjwwwd1AVquxH0+MjLQ/ iR6SainaDl6GgQsGBBs/2+JbeqV1jCHwhYO69Ua3t8wAgQ7Ij3kMspwLmcRUZbtdBAhb MU7Q== X-Received: by 10.25.84.71 with SMTP id i68mr4327468lfb.43.1446822082894; Fri, 06 Nov 2015 07:01:22 -0800 (PST) Original-Received: by 10.112.67.103 with HTTP; Fri, 6 Nov 2015 07:01:03 -0800 (PST) In-Reply-To: <87lhaba0kh.fsf@mbork.pl> X-Google-Sender-Auth: I2dyIrNmeSZkfgVj6PcJBGS3mXs X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c07::22c 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:107972 Archived-At: 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' 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 =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 an= d pass its result to =E2=80=9Cfoo-guts=E2=80=9D (we usually call it =E2=80=9Cfoo-impl=E2=80=9D o= r =E2=80=9Cdo-foo=E2=80=9D), and programmatic callers should call =E2=80=9Cfoo-guts=E2=80=9D directly with t= he right arguments. If =E2=80=9Cfoo=E2=80=9D is in a third-party library you cannot or would ra= ther not change, only then consider monkey-patching =E2=80=9Cbar=E2=80=9D as a worka= round.