;; 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 lets) (read-case-sensitive #t) (teachpacks ((lib "docs.rkt" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "docs.rkt" "teachpack" "htdp")) #f))) (let ((x 2)) (* x x)) ; should return 4 (let ((x 2)) (let ((y 1)) (+ x y))) ; should return 3 (let* ((x 10) (y (* 2 x))) (* x y)) ; yields 200 ;(let ((x 10) (y (* 2 x))) (* x y)) ; (let ((x 10) (y (* 2 x))) (* x y)) is in error as can't have dependences ; between binding list elements because that implies an order of execution ; message sent is this x: this variable is not defined (let ((x 10)) (let ((f (lambda (a) (+ a x)))) (let ((x 2)) (f 5)))) ; returns 15 which s (+ 5 10) NOT (+ 5 2) ; good example of lexical scoping; inner varible x ; hides the outer scope x (define (f z) (let* ((x 5) (f (lambda (z) (* x z)))) (map f z))) (f '(1 2 3))