From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alex Kost Newsgroups: gmane.emacs.help Subject: Re: How to shadow a function temporarily? (flet and cl-flet) Date: Sun, 26 Jan 2014 23:24:44 +0400 Message-ID: <8761p64kcj.fsf@gmail.com> References: <87k3dm4yv4.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1390764310 8774 80.91.229.3 (26 Jan 2014 19:25:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 26 Jan 2014 19:25:10 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jan 26 20:25:16 2014 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 1W7VKW-0003RN-8o for geh-help-gnu-emacs@m.gmane.org; Sun, 26 Jan 2014 20:25:16 +0100 Original-Received: from localhost ([::1]:55968 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7VKV-0002Md-RQ for geh-help-gnu-emacs@m.gmane.org; Sun, 26 Jan 2014 14:25:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47964) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7VKC-0002Jn-Uk for help-gnu-emacs@gnu.org; Sun, 26 Jan 2014 14:25:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W7VK4-0008Nd-GW for help-gnu-emacs@gnu.org; Sun, 26 Jan 2014 14:24:56 -0500 Original-Received: from mail-la0-x234.google.com ([2a00:1450:4010:c03::234]:46139) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7VK4-0008NY-9D for help-gnu-emacs@gnu.org; Sun, 26 Jan 2014 14:24:48 -0500 Original-Received: by mail-la0-f52.google.com with SMTP id c6so3790035lan.25 for ; Sun, 26 Jan 2014 11:24:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version:content-type; bh=URISIs07pqsZL7h8652TpMh9GSxcagr4pcgxOQ67sZk=; b=L/GokICNlPw0JsK6w8kLRCjghJgXSlgRkEpHqkD/OPmFlUsZqqU5PRNYXhQ3iidcaT rHMDQ0k2NGuJYlJwBdvxYkK1ehYfQ5ZmDBC+hkxeiuas2FVLlujhxsdrqJTmr3DLKFZc nbrErjL8w06zKuIW9I5saLs9XCdZVCDuARb+3MLxFq1EOASmq1lyw6DjoUGgee4PcfD+ GZ+3xVQ/yRLOAL/W0HoPFUh9nr0eMNNBMhCmFwzadyEeC0M65+IDGUcbdcw3VPsO9sYy f81OkZxVfluqCzQhrYDpxc95bP3AFcUzzczoaLtfkYNGnjsbqsD0qCUpcGFpSySizaw1 PZCg== X-Received: by 10.112.14.34 with SMTP id m2mr14548477lbc.13.1390764287069; Sun, 26 Jan 2014 11:24:47 -0800 (PST) Original-Received: from leviafan (128-70-204-126.broadband.corbina.ru. [128.70.204.126]) by mx.google.com with ESMTPSA id mx3sm9367649lbc.14.2014.01.26.11.24.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jan 2014 11:24:46 -0800 (PST) In-Reply-To: (Stefan Monnier's message of "Sun, 26 Jan 2014 09:50:15 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::234 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:95674 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier (2014-01-26 18:50 +0400) wrote: >> 1. The main question is: how can I override a function with another >> compatible function (with the same args) temporarily? > > Be careful with "temporarily": it can be interpreted as "lexically" or > "dynamically". From your example, it seems you want "dynamically". > Note, tho, that > > (defun 8+ (arg) > (+ 8 arg)) > > (flet ((+ (&rest args) > (apply '- args))) > (8+ 3)) ; => 5 > > will give you 11 when byte-compiled. Thank you, I didn't know about that. > IOW, you had better look for > another solution to your problem. One option could be something along > the following lines: > > (defvar my-plus-is-subtraction nil) > > (defun 8+ (arg) > (funcall (if my-plus-is-subtraction #'- #'+) 8 arg)) > > (let ((my-plus-is-subtraction t)) > (8+ 3)) ; => 5 It was an example, I cannot modify `8+' function. Here is what I actiually need: I want to make `read-color' function to use my functions instead of `foreground-color-at-point' and `background-color-at-point', so I tried the following (but now I see that it's not suitable): --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline Content-Transfer-Encoding: quoted-printable (defun my-read-color (&optional prompt convert-to-RGB allow-empty-name msg) (interactive "i\np\ni\np") (flet ((foreground-color-at-point () (my-foreground-color-at-point)) (background-color-at-point () (my-background-color-at-point))) (read-color prompt convert-to-RGB allow-empty-name msg))) --=-=-= Content-Type: text/plain Now i don't see another solution except of using the code of `read-color' in `my-read-color'. --=-=-=--