using a 'variable' function

David Kozina

Usenet Archive
Joined
Sep 6, 2000
Messages
310
Reaction score
0
Say that in a particular context, you need to call a custom or built-in function: DoX. In a different context, you need to call function: DoY. In yet a different context, you need to call function: DoZ. All the functions use a similar set of arguments, but use them in different ways. (I may later review how easy it would be to combine the different functions into one single function - but for now assume that they are different enough so as to justify BEING separate functions, (Example: +, -, * all use numerical arguments, but do different things with them)).

The code below works, but I was wondering if this is the best way to do it, or if there is a better or simpler method for doing this...

What may be obvious to you is most likely invisible to me.

(setq
Do_func
(cond
; case Context1 applies
(Context1
'DoX
);_end case
; case Context2 applies
(Context2
'DoY
);_end case
; case Context3 applies
(Context3
'DoZ
);_end case
; default case Unknown Context
(T
nil
);_end case
);_end cond
);_end setq
; ...function identified?
(if Do_func
; then
(apply
Do_func
(list
Argument1
Argument2
[...]
)
)
)

Any suggestions appreciated.

Best regards,
David Kozina
 
I guess you could:
(defun DoWhat (What Args)
(apply What Args)
)

But it seems a lot easier to just call the right function without another wrapper.
 
John,

Nice idea for a wrapper, thanks.
At least, it looks like I was going about using apply correctly. (I wasn't sure if there was another (more compact) way using a different built-in function).

Best regards,
David Kozina

John Uhden said:
I guess you could:
(defun DoWhat (What Args)
(apply What Args)
)

But it seems a lot easier to just call the right function without another wrapper.

Say that in a particular context, you need to call a custom or built-in function: DoX. In a different context, you need to call function: DoY. In yet a different context, you need to call function: DoZ. All the functions use a similar set of arguments, but use them in different ways. (I may later review how easy it would be to combine the different functions into one single function - but for now assume that they are different enough so as to justify BEING separate functions, (Example: +, -, * all use numerical arguments, but do different things with them)).

The code below works, but I was wondering if this is the best way to do it, or if there is a better or simpler method for doing this...

What may be obvious to you is most likely invisible to me.

(setq
Do_func
(cond
; case Context1 applies
(Context1
'DoX
);_end case
; case Context2 applies
(Context2
'DoY
);_end case
; case Context3 applies
(Context3
'DoZ
);_end case
; default case Unknown Context
(T
nil
);_end case
);_end cond
);_end setq
; ...function identified?
(if Do_func
; then
(apply
Do_func
(list
Argument1
Argument2
[...]
)
)
)

Any suggestions appreciated.

Best regards,
David Kozina
 

Latest threads

Back
Top