Subject: scheme/dsssl question From: David Megginson <ak117@xxxxxxxxxxxxxxxxxxx> Date: Tue, 30 Dec 1997 07:50:19 -0500 |
Norman Walsh writes: > Given that I've got > > (define foo "this is some text") > > in my stylesheet, is it possible to write a function that > will take "foo" (literally) as an argument and return > "this is some text"? > > For example: > > (define (bar xyz) > ...something I can't quite wrap my head around in here... > ) > > such that > > (bar "foo") returns "this is some text"? No, there is not. This would require the use of an 'eval' function (requiring access to an interpreter), while DSSSL's parent/sibling/cousin Scheme is designed to be compiled as well as interpreted. The key is to use the (assoc ...) function from the expression language. First, declare an association list of all the keys and values that interest you (note the dotted pairs, a hard-core LISP thing): (define settings '(("foo" . "this is some text") ("hack" . "this is some more text"))) Next, declare a lookup function: (define (lookup key) (let ((result (assoc key settings))) (if result (cdr result) #f))) Now, you can use (lookup "foo") with the expected results. NOTE: Jade does not currently implement the (assoc ..) function, but here's a scarcely-tested facsimile that you can use as a work-around: (define (assoc key list) (cond ((null? list) #f) ((equal? (car (car list)) key) (car list)) (else (assoc key (cdr list))))) Good luck, and all the best, David -- David Megginson ak117@xxxxxxxxxxxxxxxxxxx Microstar Software Ltd. dmeggins@xxxxxxxxxxxxx http://home.sprynet.com/sprynet/dmeggins/ DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: scheme/dsssl question, Chris Maden | Thread | Another scheme/dsssl question, Norman Walsh |
List of pairs., Alexander Taranov | Date | PDF output?, David Megginson |
Month |