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

Subject: Re: How to find a procedure given a symbol or string
From: Toby Speight <Toby.Speight@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: 29 Jul 1999 12:21:48 +0100
Frank> Frank A. Christoph <URL:mailto:christo@xxxxxxxxxxxxxxxxxx>
Bng> Boris Goldowsky <URL:mailto:boris@xxxxxxxxxxxxxxxxxxxx>
Dmahler> dmahler <URL:mailto:dmahler@xxxxxxxxxx>

0> In article <14239.15414.478894.396764@xxxxxxxxxxxxxxxxxxxxxx>, Bng
0> wrote:

Bng> Something like the following ought to work:
Bng>
Bng> (element JEDIKNIGHT
Bng>   (let ((func (string->symbol (attribute-string "FUNC"))))
Bng>     (apply func (attribute-string "NAME"))))


0> In article <000201bed954$6e5cac40$0150ebca@xxxxxxxxxxxxxxxxxx>,
0> Frank wrote:

Frank> That won't work. A symbol is not a procedure; it cannot be
Frank> applied: ('apprentice "obiwan")


0> In article
0> <Pine.LNX.4.10.9907281914500.26258-100000@xxxxxxxxxxxxxxxxxxxxxxxx>,
0> Dmahler wrote:

Dmahler> What you need is eval,
Dmahler> (define (string->procedure name)
Dmahler>   (eval (string->symbol name)))
Dmahler>
Dmahler> then you can do
Dmahler>    ((string->procedure name) arg1 arg2 ...)
Dmahler> or
Dmahler>   (apply (string->procedure name) arglist)
Dmahler> if you have the arguments in a list.

The trouble with `eval' is that it causes a run-time compilation
(IYSWIM), and it means that the compiler has to keep all the symbol
information around from the initial compilation.  I suspect that's
(part of) the reason it's not part of the DSSSL expression language.


The original questioner might get some mileage from constructing an
architecture and making the "FUNC" attribute map the JEDIKNIGHT
element to various other elements, then applying a style sheet to the
architectural instance.  Whether or not this is feasible is hard to
tell from the snippet given.

-- 


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


Current Thread