소스 검색

cond has an else clause now

master
Felix Brendel 7 년 전
부모
커밋
311af423df
2개의 변경된 파일16개의 추가작업 그리고 11개의 파일을 삭제
  1. +9
    -4
      bin/pre.slime
  2. +7
    -7
      bin/tests/sicp.slime

+ 9
- 4
bin/pre.slime 파일 보기

@@ -46,10 +46,15 @@
(define (rec clauses)
(if (= nil clauses)
nil
(list 'if (first (first clauses))
(pair 'prog (rest (first clauses)))
(rec (rest clauses)))))
(rec clauses))
(if (= (first (first clauses)) 'else)
(prog
(if (not (= () (rest clauses)))
(error "There are additional clauses after the else clause!")
(pair 'prog (rest (first clauses)))))
(list 'if (first (first clauses))
(pair 'prog (rest (first clauses)))
(rec (rest clauses))))))
(rec clauses))

(define (nil? x)
"Checks if the argument is nil."


+ 7
- 7
bin/tests/sicp.slime 파일 보기

@@ -1,6 +1,6 @@
(define (abs x)
(cond ((< x 0) (- x))
(t x)))
(else x)))

(assert (= (abs 1) 1))
(assert (= (abs (- 2)) 2))
@@ -151,7 +151,7 @@
(define (A m n)
(cond ((= m 0) (+ n 1))
((= n 0) (A (- m 1) 1))
(t (A (- m 1) (A m (- n 1))))))
(else (A (- m 1) (A m (- n 1))))))

(assert (= (A 0 0) 1))
(assert (= (A 1 2) 4))
@@ -165,7 +165,7 @@
(define (fib n)
(cond ((= n 0) 0)
((= n 1) 1)
(t (+ (fib (- n 1)) (fib (- n 2))))))
(else (+ (fib (- n 1)) (fib (- n 2))))))

(define (fib2 n)
(fib-iter 1 0 n))
@@ -195,7 +195,7 @@
;; (define (cc amount kinds-of-coins)
;; (cond ((= amount 0) 1)
;; ((or (< amount 0) (= kinds-of-coins 0)) 0)
;; (t (+ (cc amount (- kinds-of-coins 1))
;; (else (+ (cc amount (- kinds-of-coins 1))
;; (cc (- amount (first-denomination kinds-of-coins)) kinds-of-coins)))))

;; (define (first-denomination kinds-of-coins)
@@ -232,7 +232,7 @@

(cond ((= n 0) 1)
((even? n) (square (fast-expt b (/ n 2))))
(t (* b (fast-expt b (- n 1))))))
(else (* b (fast-expt b (- n 1))))))

(assert (= (expt 1 2) 1))
(assert (= (expt 2 2) 4))
@@ -269,7 +269,7 @@
(define (find-divisor n test-divisor)
(cond ((> (square test-divisor) n) n)
((divides? test-divisor n) test-divisor)
(t (find-divisor n (+ test-divisor 1)))))
(else (find-divisor n (+ test-divisor 1)))))

(define (divides? a b)
(= (% b a) 0))
@@ -333,7 +333,7 @@
(let ((test-value (f midpoint)))
(cond ((positive? test-value) (search f neg-point midpoint))
((negative? test-value) (search f midpoint pos-point))
(t midpoint))))))
(else midpoint))))))

(define (close-enough? x y) (< (abs (- x y)) 0.001))



불러오는 중...
취소
저장