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: How to shadow a function temporarily? (flet and cl-flet) Date: Sun, 26 Jan 2014 18:11:11 +0400 Message-ID: <87k3dm4yv4.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1390745499 2749 80.91.229.3 (26 Jan 2014 14:11:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 26 Jan 2014 14:11:39 +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 15:11:45 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 1W7QR6-0004ZM-OL for geh-help-gnu-emacs@m.gmane.org; Sun, 26 Jan 2014 15:11:44 +0100 Original-Received: from localhost ([::1]:54792 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7QR6-0006iv-9E for geh-help-gnu-emacs@m.gmane.org; Sun, 26 Jan 2014 09:11:44 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7QQn-0006ia-Tj for help-gnu-emacs@gnu.org; Sun, 26 Jan 2014 09:11:34 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W7QQf-0004jp-BJ for help-gnu-emacs@gnu.org; Sun, 26 Jan 2014 09:11:25 -0500 Original-Received: from mail-lb0-x233.google.com ([2a00:1450:4010:c04::233]:54152) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7QQf-0004jl-1r for help-gnu-emacs@gnu.org; Sun, 26 Jan 2014 09:11:17 -0500 Original-Received: by mail-lb0-f179.google.com with SMTP id l4so3810271lbv.10 for ; Sun, 26 Jan 2014 06:11:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type; bh=Ew+TOk0di/XY9XnlovanOcepa92T+Ic86kHtxLKdckU=; b=Mz9g9QWZopVZ6CoxISir4xX+8miQRwStMNn1RYwGnP6Yp9lFuoVJF5Z/+gdJiSmB33 LBylicSPS9/5RuVeI2me9IcVQQx/gcROXIWPYGrL0pbQqd36lUW7osj1SMV0tZtzn+7d De7UChkmF+yHp4WDKHMWFZ/cBj3ye1e4m6DbmPA1EWpVxJK5jHhi1ippaiiNmt1ELYLt lILQnQqtvJeyq/F/WfvtBO1d4U3AFt4MmwaFcokufHjH7fC8joEtPe/QoGJEbLYsC609 a3fvs5vZxBKCmFBlzvDqoZXlb4Ghh1tZLE4m3vFNDpYueQst7ygFY4lo/2ApM2msgVFy hOXQ== X-Received: by 10.112.144.69 with SMTP id sk5mr254114lbb.44.1390745475077; Sun, 26 Jan 2014 06:11:15 -0800 (PST) Original-Received: from leviafan (128-70-204-126.broadband.corbina.ru. [128.70.204.126]) by mx.google.com with ESMTPSA id th3sm8550352lbb.11.2014.01.26.06.11.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jan 2014 06:11:14 -0800 (PST) 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:c04::233 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:95667 Archived-At: --=-=-= Content-Type: text/plain Hello, I have 2 questions. 1. The main question is: how can I override a function with another compatible function (with the same args) temporarily? I want something like this: (let-shadow ((+ '-)) (+ 3 2)) ; should return 1, not 5 2. If there is no such macro, I can use `flet' for my purposes, but it is obsolete and `cl-flet' doesn't do what I need (see attached example). According to (info "(cl) Obsolete Macros"), `flet' makes a dynamic binding (unlike `cl-flet'). So the second question is: how can I avoid using obsolete `flet` if I need a dynamic binding? --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline Content-Transfer-Encoding: quoted-printable (defun 8+ (arg) (+ 8 arg)) ;; In both forms I override `+' with `-' and call `8+', ;; but results differ: (flet ((+ (&rest args) (apply '- args))) (8+ 3)) ; =3D> 5 (cl-flet ((+ (&rest args) (apply '- args))) (8+ 3)) ; =3D> 11 --=-=-= Content-Type: text/plain -- Alex Kost --=-=-=--