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

R5RS brain fart

Name: Anonymous 2012-08-17 12:56


(define (removerepeated l)
        (cond (case (null? l)
                    (list))
              (case (inlist (cdr l) (car l))
                    (removerepeated (cdr l)))
              (else (cons (car l) (removerepeated (cdr l))))))


l is a list. The procedure is supposed to turn a list l into a set. Yes I know a primitive set exists in Scheme. This is just a data structures exercise I'm doing.

Anyway I run this:


(display (removerepeated (list 1 2 3 4 1 2 3 4 4 3 2 1)))


And get this


()


Questions:

1. Can anyone hint out what is wrong with my snippet of piss poor code?

2. I use (list) to denote an empty list. I this good technique or is there an ulterior way that is more conventional?

3. How does one debug Scheme code? I don't usually use debuggers, just printf and equivalent.

Name: Anonymous 2012-08-17 13:23

By the way. I forget this important tidbit:



(define (inlist l a)
  (if (null? l)
      #f
      (or (= a (car l))
          (inlist (cdr l) a))))


It basically  returns #t if atom a is in list l.

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