Page 1 of 1

HowTo: string-parameter to use as function call

Posted: Mon Nov 02, 2009 6:18 am
by Pingu
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

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

Posted: Wed Nov 04, 2009 2:34 am
by makia
(funcall (intern (string-upcase string)) arg1 arg2 ...)