[plt-scheme] Help with programming
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100422/76534a6e/attachment.html>