;; 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-beginner-reader.ss" "lang")((modname 03-stepping) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f))) ;;;; STEPPING SEMANTICS OF EVALUATION (+ 3 (* 6 7)) ;; -[arithmetic]-> #; (+ 3 42) ;; -[arithmetic]-> #; 45 (+ (* 5 5) (/ 10 5)) ;; -[arithmetic]-> #; (+ 25 (/ 10 5)) ;; -[arithmetic]-> #; (+ 25 2) ;; -[arithmetic]-> #; 27 (string-append "five is " (number->string 5)) ;; -[arithmetic]-> #; (string-append "five is " "5") ;; -[arithmetic]-> #; "five is 5" (define (f x) (+ x 1)) (f (* 3 4)) ;; -[arithmetic]-> #; (f 12) ;; -[plug]-> #; (+ 12 1) ;; -[arithmetic]-> #; 13 (cond [(< 4 3) (* 8 9)] [(> 4 3) (- 10 2)] [else (string-append "a" "b")]) ;; -[arithmetic]-> #; (cond [false (* 8 9)] [(> 4 3) (- 10 2)] [else (string-append "a" "b")]) ;; -[cond]-> #; (cond [(> 4 3) (- 10 2)] [else (string-append "a" "b")]) ;; -[arithmetic]-> #; (cond [true (- 10 2)] [else (string-append "a" "b")]) ;; -[cond]-> #; (- 10 2) ;; -[arithmetic]-> #; 8 (+ (* 3 4) (string-length (string-append "hello" "!"))) ;; -[arithmetic]-> #; (+ 12 (string-length (string-append "hello" "!"))) ;; -[arithmetic]-> #; (+ 12 (string-length "hello!")) ;; -[arithmetic]-> #; (+ 12 6) ;; -[arithmetic]-> #; 18 (define (g x) (+ x 2)) (define (h x) (* x 15)) (g 3) ;; -[plugging]-> #; (+ 3 2) ;; -[arithmetic]-> #; 5 (g (h 10)) ;; -[plugging]-> #; (g (* 10 15)) ;; -[arithmetic]-> #; (g 150) ;; -[plugging]-> #; (+ 150 2) ;; -[arithmetic]-> #; 152 (define (j x) (* 2 (g x))) (j (j (j 1))) ;; -[plugging]-> #; (j (j (* 2 (g 1)))) ;; -[plugging]-> #; (j (j (* 2 (+ 1 2)))) ;; -[arith]-> #; (j (j (* 2 3))) ;; -[arith]-> #; (j (j 6)) ;; -[plugging]-> #; (j (* 2 (g 6))) ;; -[plugging]-> #; (j (* 2 (+ 6 2))) ;; -[arith]-> #; (j (* 2 8)) ;; -[arith]-> #; (j 16) ;; -[plugging]-> #; (* 2 (g 16)) ;; -[plugging]-> #; (* 2 (+ 16 2)) ;; -[arith]-> #; (* 2 18) ;; -[arith]-> #; 36