[plt-scheme] help writing a collector

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Mon Apr 26 16:48:17 EDT 2010

What?

It's hard to answer your question without knowing what approach you're 
trying to take. Your example, which would normally help, contains 
strange and undefined things like "get range".

If you're following HTDP, then go back to the beginning and follow the 
design recipe. When you get stuck, the steps you've completed will help 
other people figure out what you're trying to do.

(I suspect that you should read or reread at Part IV, Accumulating 
Knowledge. What information is "lost" when you recur; that is, what 
information about the elements you've already seen do you need to remember?)

If you aren't following HTDP, you'll need to figure out some other way 
of talking about the design of your program. Good luck.

Ryan


Joe Burk wrote:
> 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!
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.