HowTo: string-parameter to use as function call

Discussion of Common Lisp
Post Reply
Pingu

HowTo: string-parameter to use as function call

Post by Pingu » Mon Nov 02, 2009 6:18 am

Hi,

I have a problem to call a already defined function dynamically like the user input was:

Simplified I want to have the function gold or silver called depending the string metal:

> (win "gold" 19)

(defun gold(x) (* x x))
(defun silver(x) (* 2 x))

(defun win(metal y)
(* (internal metal) y))

I tried several things, but either the variable metal is unbound or the system does not know the symbol |gold|.

I don't want to use this dynamic idea to show that Lisp is able to call it.

Thanks,
Claudia

makia
Posts: 25
Joined: Tue Jul 22, 2008 2:37 am

Re: HowTo: string-parameter to use as function call

Post by makia » Wed Nov 04, 2009 2:34 am

(funcall (intern (string-upcase string)) arg1 arg2 ...)

Post Reply