Subject: Re: speakers From: Paul Prescod <papresco@xxxxxxxxxxxxxxxx> Date: Sun, 19 Jul 1998 16:55:59 -0400 (EDT) |
Here's another solution to the speakers problem. It is a little bit more tricky to code, but only requires one pass over the list of speakers: ; a dictionary is a list of name/value pairs called "entries": ; (("a" . 3) ("c" . 2) (e . 1)) ; if a dictionary entry exists with the right key, it updates it ; otherwise, it adds one. (define (update-dict dict key) ; main loop over dictionary (let loop ((dict-front '()) (dict-back dict)) ; if the input dictionary is expended... (if (null? dict-back) ; make a new entry and add it to the front (cons (cons key 1) dict-front) ;otherwise.... (let* ((dict-entry (car dict-back)) (dict-key (car dict-entry)) (dict-value (cdr dict-entry)) (matches (equal? dict-key key))) ; if the current entry matches the one I am looking for (if matches ; glue together the front of the list, the updated ; entry and the back of the list. (append dict-front (list (cons dict-key (+ 1 dict-value))) (cdr dict-back)) ;else look at the next entry in the dictionary (loop (cons dict-entry dict-front) (cdr dict-back))))))) (define (count-nodes nodes) (node-list-reduce nodes (lambda (dict node) (update-dict dict (data node))) '())) (element SPEAKERS (apply sosofo-append (map (lambda (x) (literal (car x) " " (number->string (cdr x)) " ")) (count-nodes (q-element "VOICE"))))) DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
tail recursion, Arthur Lemmens | Thread | Speakers, Paul Prescod |
Re: list of speakers, Paul Prescod | Date | Re: list of speakers, Arthur Lemmens |
Month |