From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Is there way to read function invoked and its parameters? Date: Mon, 28 Dec 2020 09:57:30 +0300 Message-ID: References: <9e5a8908-51c4-4abb-bdf2-b07fba13d651@default> <87blefjdp4.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2374"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0 (3d08634) (2020-11-07) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 28 07:59:49 2020 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 1ktmVQ-0000YA-O7 for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 28 Dec 2020 07:59:48 +0100 Original-Received: from localhost ([::1]:55594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktmVP-0000aO-Od for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 28 Dec 2020 01:59:47 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ktmUg-0000a3-S6 for help-gnu-emacs@gnu.org; Mon, 28 Dec 2020 01:59:02 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:41839) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ktmUe-0003pq-87 for help-gnu-emacs@gnu.org; Mon, 28 Dec 2020 01:59:02 -0500 Original-Received: from localhost ([::ffff:154.225.255.210]) (AUTH: PLAIN securesender, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000005DD3D.000000005FE98230.000048BA; Sun, 27 Dec 2020 23:58:56 -0700 Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <87blefjdp4.fsf@zoho.eu> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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:126837 Archived-At: * Emanuel Berg via Users list for the GNU Emacs text editor [2020-12-27 21:41]: > Drew Adams wrote: > > >> Would this concept be possible in Emacs Lisp: > >> > >> (defun my-function (arg &optional arg-1 arg-2) > >> (call-other-function (this-function-called parameters-to-this-function))) > >> > >> Then the other function would receive something like > >> > >> (my-function ARGUMENTS) > > > > Reading quickly, so perhaps not understanding the request. > > But I'm guessing that advice is what you're looking for. > > I'm not understanding either. > > What do you mean by "this-function-called"? > > You can pass a function as an argument, of course, if that is > the focus point. (it is known by many names, sometimes > "higher-order programming", sometimes "Aggregate functions", > sometimes list or set functions - but to us Lispers it is so > natural it doesn't need a name IMO) > > If it is about passing arg-1 and arg-2 you can use arg &rest > args and then concatenate them or by using backquote: > > (defun add-all (first &rest rest) > (apply `(+ ,@(cons first rest))) ) > > (add-all 1) ; 1 > (add-all 1 3) ; 4 > (add-all 1 3 3 7) ; 14 > > Or do it some other way with &rest I know I can pass stuff through arguments and I know I could hard code for each function how it is called. I was rather thinking that maybe there is functionality where function from inside knows how it was called and by which arguments. Maybe there is some global variable or function holding that information. Then I could just pass that variable to function invoked from that function. Then I would not need to hard code passing of arguments in hundreds of functions. Practically I wish to achieve this: 1. Reporting function is invoked, I would like to have program remember WHICH reporting function was invoked and by which arguments and to pass it to other functions. 2. Other function is called, there are few more hops. 3. The report is shown on screen. Now this reporting function is disconnected from the first and I would need a refresh of the report after editing or inserting information. The refresh shall know exactly how the first reporting function has been invoked. There are many functions that are at (1) so there is considerable number of those functions. For example this is such function that introspect the function being called: called-interactively-p is a compiled Lisp function in ‘subr.el’. (called-interactively-p KIND) Probably introduced at or before Emacs version 22.1. Return t if the containing function was called by ‘call-interactively’. Maybe there is other mechanism that introspects the function's own name and function's own arguments. Then I could do just this: (defun report (arg1 arg2 arg3) (do some stuff) (invoke-display (how-this-function-was-called))) (defun report-1 (arg1 arg2 arg3) (do some stuff) (invoke-display (how-this-function-was-called))) (defun report-2 (arg1 arg2 arg3) (do some stuff) (invoke-display (how-this-function-was-called))) Instead of doing this: (defun report (arg1 arg2 arg3) (do some stuff) (invoke-display '(report arg1 arg2 arg3))) (defun report-1 (arg1 arg2 arg3) (do some stuff) (invoke-display '(report-1 arg1 arg2 arg3))) (defun report-2 (arg1 arg2 arg3) (do some stuff) (invoke-display '(report-2 arg1 arg2 arg3))) Additionally, it becomes very tedious if I would now need to replace normal arguments with &rest only for those functions with parameters to be passed correctly. I rather prefer having introspection function that looks into itself and finds out what is its name and what were arguments.