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-20 20:45

>>32
This is my first language.

I finally figured the insertL shit out without cheating. I had to actually write out all of the steps and returns in the recursion lol.


;;write insertL
(define insertL
  (lambda (new old lat)
    (cond
      ((null? lat) '())
      (else
       (cond
         ((eq? (car lat) old) (cons new (cons old (cdr lat))))
         (else (cons (car lat) (insertL new old (cdr lat)))))))))


Calling:
(insertL 'fudge 'topping '(ice cream with topping for dessert))

Answer:
(ice cream with fudge topping for dessert)


And it works as expected. I am really enjoying this.

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