48 lines
869 B
Scheme
48 lines
869 B
Scheme
|
|
; Test functions
|
|
|
|
(define add-three (lambda (x y z) (+ (+ x z) y)))
|
|
|
|
; Test factorial
|
|
|
|
(define fac (lambda (x) (if (>= x 1) (* x (fac (+ x -1))) 1)))
|
|
|
|
(define (faca x a)
|
|
(if (>= x 1)
|
|
(faca (+ x -1) (* x a))
|
|
a))
|
|
|
|
(define x 5)
|
|
(display x) (newline)
|
|
(display (fac x)) (newline)
|
|
(display (faca x 1)) (newline)
|
|
|
|
; Test stuff?
|
|
|
|
(define (f . l) (cdr l))
|
|
(define y '(1 2 3))
|
|
|
|
(display y) (newline)
|
|
(display (car y)) (newline)
|
|
(display (cdr y)) (newline)
|
|
|
|
; Check set!
|
|
|
|
(set! x 10)
|
|
(display x) (newline)
|
|
|
|
; Test syntax-rules
|
|
|
|
(define-syntax and
|
|
(syntax-rules ()
|
|
((and) #t)
|
|
((and test) test)
|
|
((and test1 test2 ...)
|
|
(if test1 (and test2 ...) #f))))
|
|
|
|
(display (and #t #t)) (newline)
|
|
(display (and #f #t)) (newline)
|
|
(display (and #f #f)) (newline)
|
|
(display (and #t #f)) (newline)
|
|
|