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: Scheme Noobie. 2009-07-22 0:40

What does tail recursive mean? I read the wikipedia article but it is fucking boring and it assumes that the reader is an EXPERT PROGRAMMER

Here is my code for defining the other operators and an extra function that sums the members of a tup.



;; define the subtraction operator.
(define -o
  (lambda (n m)
    (cond
      ((zero? m) n)
      (else (-o (sub1 n) (sub1 m))))))

;; define addtup which finds the sum of a tup.
(define addtup
  (lambda (lat)
    (cond
      ((null? lat) 0)
      (else (+o (car lat) (addtup (cdr lat)))))))

;; define the * operator.
(define *o
  (lambda (n m)
    (cond
      ((zero? m) 0)
      (else (+o n (*o  n (sub1 m)))))))

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