[plt-scheme] Help with programming

From: Marco Morazan (morazanm at gmail.com)
Date: Fri Apr 23 22:41:51 EDT 2010

Sure, no problem.

You see, it is quite simple. Apply the design recipe for abstraction to your
functions. Define an abstract function and then use your abstract function
to implement your original functions. Voila! There you go.

If you are not clear about what the design recipe for abstraction is, take a
look at Part IV of www.htdp.org.

Alternatively, you can use an appropriate built-in higher-order function for
filtering the elements of a list to implement your 3 functions.

I hope that helps.


On Thu, Apr 22, 2010 at 12:19 PM, Joe Burk <joshwbfantasy at yahoo.com> wrote:

> Hey everyone, I'm a bit new to scheme and I'm looking for some help.
> Hopefully you guys can assist me. I was given these few questions and I have
> no clue where to start. So if anyone could answer them they would be of much
> help. Thanks.
>
> Consider the following functions:
>
> (define get-evens
>   (lambda (lst)
>     (cond ((null? lst) '())
>              ((even? (car lst)) (cons (car lst) (get-evens (cdr lst))))
>              (else (get-evens (cdr lst))))))
>
> (define get-odds
>   (lambda (lst)
>     (cond ((null? lst) '())
>              ((odd? (car lst)) (cons (car lst) (get-odds (cdr lst))))
>              (else (get-odds (cdr lst))))))
>
> (define get>2
>   (lambda (lst)
>     (cond ((null? lst) '())
>              ((> (car lst) 2) (cons (car lst) (get>2 (cdr lst))))
>              (else (get>2 (cdr lst))))))
>
> 1. Write another function that accepts a test as one of its arguments, and
> which can then behave like each of the above functions. Starting with:
>
>  (define extract
>    (lambda (test? lst)
>
>
> 2. Use extract to define get-evens, get-odds, and get>2
>
>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>


-- 

Cheers,

Marco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100423/938985b5/attachment.html>

Posted on the users mailing list.