This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

HowTo: string-parameter to use as function call

2 posts · 1285 views

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

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