;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname lect33-dist-law-of-racket) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) #| THE LAW OF RACKET: Expresssions evaluate to values. In racket: An Expression is: - value examples: 7 "hello" 'green #t (lambda (x) (+ x 3)) semantics: Values evaluate to themselves. - identifier examples: pi + string-append x semantics: rule for eval: look up in previous `define`s, and eval to the right-hand-side (cached). (if wasn't previously `define`d, it's an error.) - function-application: examples: (+ 2 3) (string-append "hi" name) ((lambda (x) (+ x 3)) 7) syntax: ( ... ) semantics: Evaluate each of ...; let's call them v0...vN. (Btw: v0 had *better* be a function-value! -- else error) if v0 is a built-in function: apply the built-in to v1...vN. if v0 is a lambda: take the *body* of the lambda, substitute v1...vN for ... in that ; call the result E' (substitute only the *free* occurrences) return: eval(E') - special-forms: cond } and } they short-circuit if } let, let* lambda syntax: (lambda ( ... ) ) There are also a couple of *statements* (not expressions): define define-struct -- they have a side-effect, and they can't be used in places there 'any expression' fits, like the arguments to "+" -- you can't say (+ (define x 99) 3) |#