Subject: Re: Attribute String... From: "Lassi A. Tuura" <Lassi.Tuura@xxxxxxx> Date: Sat, 04 Oct 1997 14:21:49 +0200 |
Norman Walsh wrote: > By the way, comments from scheme experts on the efficiency and > style of my code wouldn't be unwelcome. I'm just feeling my way > about. I might be inclined to use one list with different cases combined to sublists. That way you could use a simple map function that just takes `car', `cadr' or `caddr' of the sublists, instead of index-based searches in the lists as you do now. You could even use `assoc' on such a list, but unfortunately it will work one way only (but at least either casing operation will be fast :-). > (define (list-member-get elementlist count) I think you could use `list-ref' builtin instead. > (define (case-fold-down-charlist charlist) > ;; Shifts all characters in charlist to lowercase > (if (null? charlist) > '() > (cons (case-fold-down-char (car charlist)) > (case-fold-down-charlist (cdr charlist))))) > > (define (case-fold-up-charlist charlist) > ;; Shifts all characters in charlist to uppercase > (if (null? charlist) > '() > (cons (case-fold-up-char (car charlist)) > (case-fold-up-charlist (cdr charlist))))) These are not needed; basically these are like `map' function. Also, it is better to accumulate the list along the way with tail-recursion and use reverse at the end, than to leave a huge stack of pending `cons' calls (see my `mapfun' below). > (define (case-fold-down str) > ;; Returns str shifted to lowercase > (apply string (case-fold-down-charlist (string-to-list str)))) Write instead: (apply string (map case-fold-down-char (string-to-list str))) or (apply string (map case-fold-up-char (string-to-list str))) I think I have already sent an implementation of `map' to you in my DocBook style-sheet enhancements. In case you have missed it, here comes. It would of course be best if the tools included it since it is part of the DSSSL spec, but at least jade seemed to lack `map' and `cXr' family at some point. (define (mapfun proc result list other) (if (and (null? list) (null? other)) result (if (null? list) (mapfun proc result (car other) (cdr other)) (mapfun proc (cons (proc (car list)) result) (cdr list) other)))) (define (map proc list #!rest other) (reverse (mapfun proc '() list other))) //lat -- Lassi.Tuura@xxxxxxx There's no sunrise without a night DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Attribute String..., Norman Walsh | Thread | Re: Attribute String..., James Clark |
Re: JSPI from Copsol Problems, Alex Milowski | Date | Emergent, Paul Prescod |
Month |