RE: How to find a procedure given a symbol or string

Subject: RE: How to find a procedure given a symbol or string
From: dmahler@xxxxxxxxxx
Date: Thu, 29 Jul 1999 05:27:10 -0500 (CDT)

On Thu, 29 Jul 1999, Frank A. Christoph wrote:

> > >> To paraphrase Mitch C. Amiano <amiamc@xxxxxxxxxxxxxxx> question:
> > >> given tags like
> > >>   <jediknight   name="obiwan" func="apprentice">
> > >> and DSSSL functions
> > >>   (define (apprentice name) (string-append name " is an apprentice" ))
> > >> I want to use the value of "func" to call the correct DSSSL function...

What you need is eval,
(define (string->procedure name)
	(eval (string->symbol name)))

then you can do
   ((string->procedure name) arg1 arg2 ...)
or
  (apply (string->procedure name) arglist)
if you have the arguments in a list.

Daniel

> >
> > Something like the following ought to work:
> >
> > (element JEDIKNIGHT
> >   (let ((func (string->symbol (attribute-string "FUNC"))))
> >     (apply func (attribute-string "NAME"))))
> 
> That won't work. A symbol is not a procedure; it cannot be applied:
> ('apprentice "obiwan")

> 
> --FC
> 
> 
>  DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
> 


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread