;; prints 'x is zero' otherwise prints x ;; shows off compound statements and basic printing (define (zero-test x) (if (not (= x 0)) (begin (display "x is ") (display x) (newline)) (begin (display "x is zero") (newline)))) ;; t if object is not a list with the exception of the empty list (define (atom? object) (not (pair? object))) ;; simply count number of elements in list (define (len x) (if (null? x) 0 (+ 1 (len (cdr x))))) ;; recursively count atoms (define (atomcount x) (cond ((null? x) 0) ((atom? x) 1) (else (+ (atomcount (car x)) (atomcount (cdr x)))))) ;; example of cond (define (type? x) (cond ((symbol? x) (display "I am a symbol")) ((number? x) (display "I am a number")) ((boolean? x) (display "I am a boolean")) ((list? x) (display "I am a list")) (else (display "I do not know what I am"))) (newline) )