HowTo: string-parameter to use as function call

Discussion of Common Lisp

HowTo: string-parameter to use as function call

Postby 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
Pingu
 

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

Postby makia » Wed Nov 04, 2009 2:34 am

(funcall (intern (string-upcase string)) arg1 arg2 ...)
makia
 
Posts: 25
Joined: Tue Jul 22, 2008 2:37 am


Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 4 guests