;; Some simple examples of programming in Scheme. Type these in one at ;; a time. If using DrScheme set the Language mode to the "Pretty Big" mode ;; under the Professional Languages tab. ; simple variable definitions and usage (define x 1) x (+ x 1) (define x '(this is a list)) x (length x) #t #f (and) (and #t #f) (and 0 1) (or) (or x) (or #f) (or #f #t) (if (or 1 2) #t #f) ;; everything is a list '() ; the empty list (length '()) (+ 1 2 3 4 5) (* 1 2 3 4 5) (+ 1 (* 2 3) (- 4 5)) (if (null? '()) #t #f) '(apples oranges grapes) (cons 'peanut '(butter and jelly)) (car '(apples oranges grapes)) (cdr '(apples oranges grapes)) ;; function definition (define (square x) (* x x)) ;; this is syntactic sugar for the next expr (define square (lambda (x) (* x x))) (define fact (lambda (n) (if (= n 0) 1 (* n (fact (- n 1))))))