Re: automatically call functions based on arguments
- From: Alessio Stalla <alessiostalla@xxxxxxxxx>
- Date: Tue, 29 Apr 2008 02:36:49 -0700 (PDT)
On Apr 29, 11:09 am, normanj <nii2...@xxxxxxxxx> wrote:
Suppose there are several functions (or macros):
func-aa-1-1
func-aa-2-1
func-bb-1-3
Is there a way to call these functions like this:
(call-function 'aa 1 1) => (func-aa-1-1)
(call-function 'bb 1 3) => (func-bb-1-3)
And, if the expected function doesn't exist, how to emit warning?
Thanks.
If you're only interested in functions, see the FIND-SYMBOL, SYMBOL-
FUNCTION and FUNCALL (or APPLY) functions.
Macros instead can't be "called"; they are expanded before code is run
(actually, before code is even compiled!) so if you want to be able to
do your transformation on macros too, CALL-FUNCTION must be a macro
itself, expanding to the proper call (the name would be a bit
misleading too). Note though that if CALL-FUNCTION was a macro, you'd
lose the ability to dynamically determining which function/macro to
invoke, i.e.
(let ((x 'aa))
(call-function x 1 2))
would expand to (x-1-2) and NOT (aa-1-2)!
Furthermore, using a macro would prevent you from detecting if you're
invoking a nonexistent function, unless you define the function before
the macro is run (and use FBOUNDP on the generated symbol to see if it
names a function): this means using EVAL-WHEN when defining the
function, and things grow a another little bit more complex :)
So, maybe you're trying to solve the wrong problem; what are you
exactly trying to achieve?
hth,
Alessio Stalla
.
- References:
- automatically call functions based on arguments
- From: normanj
- automatically call functions based on arguments
- Prev by Date: Re: automatically call functions based on arguments
- Next by Date: Re: automatically call functions based on arguments
- Previous by thread: Re: automatically call functions based on arguments
- Next by thread: Re: automatically call functions based on arguments
- Index(es):
Relevant Pages
|
|