help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there way to read function invoked and its parameters?


From: Emanuel Berg
Subject: Re: Is there way to read function invoked and its parameters?
Date: Sun, 27 Dec 2020 19:39:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

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

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]