;; 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 lect17-cond-semantics-stepper) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) (require "student-extras.rkt") ; - review: using local variables (or not) ; - syntax/semantics of `cond`, w/o '...' ; - stepping through my-max (w/ and w/o `let`) ;; We re-write the following to use 0,1,2 or 3 local variables, via `let*`: ; downcased-initial : string -> string ; Given a *non-empty* string `w`, ; return its first character, downcased. ; #;(define (downcased-initial w) (string (char-downcase (string-ref w 0)))) ;; Step through this: (downcased-initial "hello") #| Syntax,semantics of `cond`: A is: (cond ) A ("question/answers") is either: - ε (that's our notation for 'nothing at all') - [ ] Semantics of `cond`: eval of (cond ) returns: - if is ε, then: semantics say trigger a run-time error. - if is [ ] , then: eval ; If true: return result of eval'ing . If false: return result of eval'ing (cond ). |# ;;;;;;;;;;;;;;; my-max ; my-max : list-of-number -> number ; (define (my-max a-lon) (cond [(empty? a-lon) -inf.0] [(cons? a-lon) (if (< (first a-lon) (my-max (rest a-lon))) (my-max (rest a-lon)) (first a-lon))])) (my-max (cons 1 (cons 2 empty)))