Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

The Little Schemer

Name: Anonymous 2009-07-19 23:23

Hi, I am working through the little schemer. I do not have the math skills to work through SICP.

I have the following code:


(define (member? a lat)
  (lambda (a lat)
    (cond
      ((null? lat) #f)
      (else (or (eq? (car lat) a)
                (member? a (cdr lat)))))))



When I run this say like:
(member? 3 (cons 3 '(9 8 7 6 13 3)))

I get the following:
#<procedure:...my-scheme-log.ss:137:2>
rather than a list without the first instance of 3

Can you help me?

Name: Anonymous 2009-07-21 1:04

>>33
You don't need to break up the cond tests here, that's the purpose of cond over if. (Seems like you realize this in >>38 but I just want to be sure.)

Which implementation are you using?

BTW you already encountered the member method which returns the sublist from the first match. No need to rewrite it! (Unless that was an exercise.)

Finally, there's no need to be so cryptic with your names. I know it is hard to believe what with "car", "cdr", "cons", and such, but you should try to be a little more descriptive. In other languages, having to retype long names several times is a pain, but with closures and first class functions Scheme doesn't really fall into the problem of too much typing.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List