[plt-scheme] help writing a collector

From: Joe Burk (joshwbfantasy at yahoo.com)
Date: Mon Apr 26 16:15:15 EDT 2010

I know how to write a simple collector

(define collect-range
  (lambda (min max)
    (cons (min (cons max ' ())))))

But that will just return a list containing its two arguments.  I want my function to be able produce results such as these.

(get range ' (3 7 5 1 2 4) collect-range)  and it will return ' (1 7)

Ok so first off i have to define collect max. Which I do as follows

 (define collect-max
   (lambda (max)
       max))

Next I have to define get max. Which is simply

(define get-max
  (lambda (lst collector)
    (cond ((null? lst) (collector 0))
             (else
              (get-max (cdr lst)
                (lambda (max)
                  (cond ((> (car lst) max)
                            (collector (car lst)))
                              (else
                               (collector max)))))))))

So the get max function will be able to keep track of the highest number in the list. 

I need a function that can keep track of both the highest AND the number lowest in the list. If anyone could help me out I'd greatly appreciate it. Thanks!



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100426/75ffd112/attachment.html>

Posted on the users mailing list.