Re: automatically call functions based on arguments



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
.



Relevant Pages

  • Re: Yet another when to use macros question....
    ... macro expanding time can be eliminated ... do you actually have any empirical evidence that macro expansion is ... Since X represents code that you will later execute then before making N ...
    (comp.lang.lisp)
  • Re: ONCE-ONLY
    ... >> Now we see that this macro expands to code that return a s-expression. ... > macroexpansion is done, no further processing is performed during ... Now expanding: ... (BLOCK NIL ...
    (comp.lang.lisp)
  • Re: Yet another when to use macros question....
    ... macro expanding time can be eliminated ... I'll demonstrate it with macro PUSH. ... do you actually have any empirical evidence that macro expansion is ...
    (comp.lang.lisp)
  • Re: expandafter question
    ... not expanding its arguments. ... As Heiko mentioned, when you fold \index into a macro, you will ... not get verbatim writing to the .idx file and you will have ... Recursion is OK, but it depends on how it is implemented. ...
    (comp.text.tex)
  • Re: def results of input
    ... without expanding anything. ... Afterwards you could \input the copied-file instead of the ... defining a macro from that register. ...
    (comp.text.tex)