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

Subject: Re: How to find a procedure given a symbol or string
From: "Mitch C. Amiano" <amiamc@xxxxxxxxxxxxxxx>
Date: Thu, 29 Jul 1999 16:56:46 -0400
So far:
1) DSSSL does not provide a standard method by which 
to produce a reference an existing procedure.

2) An "eval" type of function would be sufficient
to handle the task, but could be easilly abused. It is 
also not necessary.

3) The case/if workaround can be syntactically elminated
by defining a function to do the association semi-automatically.
example from Brandon Ibach:
 (define defproc apprentice)
 (define procmap `(("apprentice" ,apprentice) ("badactor" ,badactor)))

(define (call-some-function-using-a-string func name)
  ((car (cdr (or (assoc func procmap) '(#f defproc)))) name))

4) Architectural forms could be used to push the associative 
mechanism into the SGML part of the engine, as long as the structure
of the SGML lends itself to the solution. The "jediknight" element
could then be matched as either an "apprentice" or "badactor" architectural
element.

5) The 
(query style-query-expression construct-expression priority-expression?) top-level 
form (12.4.1) could be an alternative, if it were supported by a DSSSL engine.

Of these, (3) is the best workaround for my purposes. (4) could work, but imposes 
a higher level structure to the style sheet which would lead to, in my current style sheets,
more work in order to eliminate redundancies between a multiplicity of similar 
element forms. (5) is not available in Jade because it doesn't have the (query) form, 
and even if it were, would again impose a higher level restructuring.

Thanks again for the comments.


"Mitch C. Amiano" wrote:
> 
> A question for the old-time DSSSLers out there: is there any way to
> produce an existing procedure object when given a string or a symbol?
> I want to use an attribute value to determine a function to be called,
> and want to avoid lots of "if"s or a "case".
> 
> That is, given tags like
> 
> <jediknight   name="obiwan" func="apprentice">
> <jediknight   name="maul" func="apprentice">
> <jediknight   name="anakin" func="badactor">
> 
> and a DSSSL functions
> 
> (define (apprentice name) (string-append name " is an apprentice" ))
> (define (badactor name) (string-append name " needs more work" ))
> 
> I want to use the value of "func" to call the correct
> DSSSL function, something like what would be
> expressed as "call-some-function-using-a-string" in
> the following snippet:
> 
> (element JEDIKNIGHT
>    (let ( (func (attribute-string "FUNC") )
>            (name (attribute-string "NAME") ) )
>         (literal  (call-some-function-using-a-string func name) ) ) )
> 
> Can this be done without resorting to ifs or case?
> Thanks

--                                                                          --
Mitch C. Amiano                                 Mitch.C.Amiano@xxxxxxxxxxxxxxx
Software Development Engineer        Advanced Design Process       Alcatel USA
Being imprecise doesn't mean you've made a good abstraction.


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


Current Thread