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

DOCTOR SCHEME

Name: Anonymous 2008-12-10 14:33

(define (pow X N)
  (cond
   ((= N 0) 1)
   ((> N 0) (* X (pow X (- N 1))))
   )
  )

(define (countAtoms X)
  (cond
    ((null? X)
     0)
    ((list? X)
     (cond
       ((list? (car X))
        (+ (countAtoms (cdr X)) (countAtoms (car X))))
       (else
        (+ (countAtoms (cdr X)) 1)))
     )
    )
  )

(define (cons2 X Y)
  (cond
    ((null? X)
     (cons Y ()))
    ((not(pair? X))
     (cons X (cons Y ())))
    (else
     (cons (car X) (cons2 (cdr X) Y)))
    )
  )

(define (reverse X)
  (cond
    ((null? X) ())
    ((null? (cdr X))
     (car X))
    ((list? X)
     (cond
       ((list? (car X))
        (cons2 (reverse (cdr X)) (reverse(car X))))
       (else
        (cons2 (reverse (cdr X)) (car X)))))
    )
  )

Name: Anonymous 2008-12-10 22:02

>>7
I prefer >>5's style, the closing parens should be aligned with the opening parens. Forced indentation of the parentheses, etc.

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