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:38:20 +0400 Message-ID: <87vbx6355f.fsf@gmail.com> References: <87y522wq3o.fsf@nl106-137-194.student.uu.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1390765147 17010 80.91.229.3 (26 Jan 2014 19:39:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 26 Jan 2014 19:39:07 +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:39:14 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 1W7VY2-0000vE-Et for geh-help-gnu-emacs@m.gmane.org; Sun, 26 Jan 2014 20:39:14 +0100 Original-Received: from localhost ([::1]:56106 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7VY2-0005yE-3a for geh-help-gnu-emacs@m.gmane.org; Sun, 26 Jan 2014 14:39:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7VXN-0005L8-5B for help-gnu-emacs@gnu.org; Sun, 26 Jan 2014 14:38:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W7VXE-00047o-AL for help-gnu-emacs@gnu.org; Sun, 26 Jan 2014 14:38:33 -0500 Original-Received: from mail-la0-x230.google.com ([2a00:1450:4010:c03::230]:60335) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7VXE-00047i-21 for help-gnu-emacs@gnu.org; Sun, 26 Jan 2014 14:38:24 -0500 Original-Received: by mail-la0-f48.google.com with SMTP id mc6so3845678lab.21 for ; Sun, 26 Jan 2014 11:38:22 -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=9CHuY7nmt3aSR2GG9zRHHxeUjTjJuwcla1SaBIyKfkU=; b=PLogf4nxNXJdN2ec5yrDpA48lwfsBZTiY9EeXuRHp4+RJaN0rCzmaw3svYIKie/w6i hWqBCNAEujWyuNu8FTP9I3HPkf03XkQ/ZyMDOCYdHU38zUh5ezWreI9wtjVKFFEfiA5T dmu43a6rmvKqJ2hZ8QRRKNZLTiYRb0OJf5KJt6E70cCkgTg1aUWA/iOylFL5SYvBbv5i 3DJsMQ9ilLjfBkuy0vQ9L7QQ2MucYu3+TFxZYrXKawa0cB6ko666zf6WYkVv02RC/XzX GKTu8+/hn3jTZ835G7zrbIx7opAT1Zu+vepboS4cxYqsQaO3x5eF6VzD/3/0PvSECEDA 2bmw== X-Received: by 10.152.8.47 with SMTP id o15mr15510831laa.20.1390765102830; Sun, 26 Jan 2014 11:38:22 -0800 (PST) Original-Received: from leviafan (128-70-204-126.broadband.corbina.ru. [128.70.204.126]) by mx.google.com with ESMTPSA id s9sm13268274laj.0.2014.01.26.11.38.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jan 2014 11:38:22 -0800 (PST) In-Reply-To: <87y522wq3o.fsf@nl106-137-194.student.uu.se> (Emanuel Berg's message of "Sun, 26 Jan 2014 19:32:34 +0100") 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::230 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:95677 Archived-At: Emanuel Berg (2014-01-26 22:32 +0400) wrote: > Alex Kost writes: > >> 1. The main question is: how can I override a >> function with another compatible function (with the >> same args) temporarily? > > ;;;; dynamic (Emacs wide) > > ;; first store the correct functions so we have them > ;; (note: "subr" as in "subroutine", not "subtract") > (setq addition-fun (symbol-function '+)) ; # > (setq subtraction-fun (symbol-function '-)) ; # > > ;; change + to do subtraction > (fset '+ subtraction-fun) > (+ 1 2 3) ; -4 > > ;; revert > (fset '+ addition-fun) > (+ 1 2 3) ; 6 > > ;;; lexical > > (cl-labels ((+ (&rest args) (apply '- args))) > (+ 1 2 3) ) ; -4 > (+ 1 2 3) ; still 6 Thank you, I know all that stuff. That's not exactly what i need, but your will to help always impress me.