From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: How can function know its own name? Date: Sun, 26 Jun 2022 07:46:24 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="bvfLMzvC3NJQRN5z" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39284"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Help GNU Emacs To: Jean Louis Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 26 07:48:09 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o5L7v-0009y8-TT for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 26 Jun 2022 07:48:07 +0200 Original-Received: from localhost ([::1]:34922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o5L7u-0007hI-Cn for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 26 Jun 2022 01:48:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50584) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5L6W-0007gu-2O for help-gnu-emacs@gnu.org; Sun, 26 Jun 2022 01:46:40 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]:50064) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5L6K-0000PU-93 for help-gnu-emacs@gnu.org; Sun, 26 Jun 2022 01:46:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=wTWbarh8KnnakKzL9k20rqEPEeHnq3JPFSDUDygOfw0=; b=WO36Af02XQr8U2++V0Foq9RQhP UEqceBxMitSKzVOEdJe+frV6iDzpaFCIfwLi7y6A7MhwtY+zCq9b/A+af5yKsdcnTpg33WwAiVWDB qLsqlOCWdw2z4wqktpqYBE7PORRhM20+a4DwuKN7lez8uvlcNvCzFbJNWCdYHlM1vJg0EtZ7NwXFj P6AiSWGJveQgz5PEGqCYUuDgf8IXUFYbewMNk9leYLzZsxOWab3GyNCD57ZBPA3uN5yJH8ysf/loU BE4dgH94NkfdAHvc7/5awXSdgxY8vchW+p2oSjDlL63swTRjBioYsD/Di18hhse2uuJXp90Mv7QW5 P6bAQggQ==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1o5L6G-00055t-Lj; Sun, 26 Jun 2022 07:46:24 +0200 Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:138098 Archived-At: --bvfLMzvC3NJQRN5z Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jun 25, 2022 at 11:21:20PM +0300, Jean Louis wrote: >=20 > I would like to invoke logging for specific functions automatically, > without specifying what to log, and my function should know which > function invoked it. This is not completely trivial. In Lisp, a function has no name. It is a first-class object which can be bound to (the function slot) of a symbol (or to that of two, three... symbols). It's like the value 42. Many variables can be bound to that. Or none. What name has (lambda (x) (if (=3D (mod x 2) 1) (+ (* 3 x) 1) (/ x 2)))? None (yet?). Try this: (setf (symbol-function 'foo) (lambda (x) (+ x 1))) Now: (foo 13) =3D> 14 So that function that adds one to its argument is now arguably called foo. But: (setf (symbol-function 'bar) (symbol-function 'foo)) Then: (bar 14) =3D> 15 =2E..it can be called bar at the same time. Well, I can be called two names too, can't I? See 13.3 "Naming a function" and 9.1 "Symbol Components" in our beloved Emacs Lisp manual for all the gory details. Now to the interesting question: how do debuggers pull it off? Cheers --=20 t --bvfLMzvC3NJQRN5z Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCYrfyqgAKCRAFyCz1etHa RnpiAJ9xhoYpiS9cn+pU41Hox0WC6qWXmwCfaVRlH0I4B9/LZ3u3YJM3PG4nJjQ= =D485 -----END PGP SIGNATURE----- --bvfLMzvC3NJQRN5z--