Introduction to Scheme Syntax: Every expression in scheme has a value. An expression is something you type into scheme. A value is what you get out after scheme interprets your expression. Expression := Self-Evaluating | Variable | (Procedure Argument1 Argument2 ...) | Special-Form Self-Evaluating := Number | "String" | #t | #f Some special-Forms: (define variable value) => [undef] (if predicate consequent alternative) => [value of conseq or alt] (lambda (arg1 arg2 ...) expression) => [procedure] (let ((var1 value1) (var2 value2) ...) expression) => [value of expression] Examples: ;; Every expression has a value 3 => [3] (+ 1 2) => [3] (sqrt 9) => [3] (+ (* 2 3) (- 5 8)) => [3] ;; Use define to name values (define pi 3.14159) => [undef] (sin (/ pi 2)) => [1] ;; The use of "if" (if #t "foo" "bar) => ["foo"] (if (> val 0) val (- 0 val)) => [absolute value of val] (if (= x 0) 0 (/ 1 x)) => [a number, never an error] ;; procedures are values + => [procedure] (define + -) => [undef] (+ 3 2) => [1] (lambda (x) (* x x)) => [procedure] ((lambda (x) (* x x)) 3) => [9] (define square (lambda (x) (* x x))) => [undef] (square 3) => [9] ;; You can use define to simplify named lambdas (define (square x) (* x x)) => [undef] (square 3) => [9] ;; procedures can be passed are arguments (define apply-to-3 (lambda (proc) (proc 3))) => [undef] (apply-to-3 square) => [9] ;; let is used to name values within the let body (define x 20) => [undef] (let ((x 10)) (/ x 2)) => [5]