Subject: Re: stretch function. From: Dave Love <d.love@xxxxxxxx> Date: 25 Sep 1997 17:54:34 +0100 |
>>>>> "Paul" == Paul Prescod <papresco@xxxxxxxxxxxxxxxx> writes: Paul> My solution has two problems. First, it uses map and Paul> string->list. Using the right tools shouldn't be considered a problem! Paul> The second is that it adds a space to the end of the string. Avoiding explicit recursion is good, but surely we should meet the specification. Here's one version that springs to mind: (define (stretch s) (string-via-list (lambda (cs) (cdr ; => (char #\space char ...) (apply append ; => (#\space char #\space char ...) (map ; => '((#\space char) ...) (lambda (c) (list #\space c)) ; char -> (#\space char) cs)))) ; (char ...) s)) ;; Convenience: transform string `s' by applying function `f' to a ;; list of the characters (define (string-via-list f s) (list->string (f (string->list s)))) [For string transformations it's a good move to define and use higher-order functions analagous to the standard's node-list ones (using intermediate character lists).] In this case it might be more appropriate to work on the node-list directly. Perhaps: (define (map-node-list->sosofo f nl) (if (node-list-empty? nl) (empty-sosofo) (sosofo-append (f (node-list-first nl)) (map-node-list->sosofo f (node-list-rest nl))))) (define (stretch nl) (sosofo-append (process-node-list (node-list-first nl)) (map-node-list->sosofo (lambda (snl) (sosofo-append (literal " ") (process-node-list snl))) (node-list-rest nl)))) (element acronym (stretch (children (current-node)))) ; H T H. DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: stretch function., Paul Prescod | Thread | DSSSL for software engineering?, Paul Prescod |
DSSSL for software engineering?, Paul Prescod | Date | Re: Jade & Tables & RTF questions.., James Clark |
Month |