[PLT logo] TeachScheme! 2002

July/August, 2002

Details for Monday afternoon




- demo ping-pong.  
  PVD 2002:
  We did not do this demo.  Nobody seemed to really care, and we got
  to spend more time on core content.  We just *talked* about what
  ping-pong requires.

  Ping-pong requires:
  -- dealing with conditional situations
  -- dealing with compound data
  -- dealing with graphics (we don't teach this though, since it's
     not portable learning -- if you want to illustrate this, point
     to Java's quick change from AWT to Swing)

- claims and conditionals

  Claims are true or false: 
    given any x on numberline, only one of 
    -- x = 0
    -- x < 0
    -- x > 0 
    holds; examples!

  Scheme syntax: [show contracts!]
    -- (= x 0) 
    -- (< x 0)
    -- (> x 0)

  Computation: Booleans! [note: not 0 or 1.  booleans are a distinct
                          kind of value]

  Consider interval on number line: 
    all numbers between 0 and 5. 
  To describe it, we need compound claims: 
    (and (< 0 x) (< x 5))

  [DON'T hand-eval and/or.  Raises too many questions about shortcuts]

  If have boolean values, should be able to create functions that
  return booleans.

  Boolean-value functions: 
    -- Is the ball inside some box?         if not, game's over
    -- Is the ball inside of some interval? if yes, it hit paddle

  Example: ;in_interval : num num num -> boolean
           ;true if n between lo and hi, inclusive
           (define (in-interval n low hi) ...)

  Conditional functions: 

    Sometimes the method for computing results differs depending
    on what the input is. We need CONDITIONAL EXPRESSIONS: shape
    [question-answer]; use; evaluation.

  Example: 
    -- ;sign : num -> symbol
       ;returns 'positive, 'negative, or 'zero based on sign of input
       (define (sign n) ...)

       [demo stepper on sign]

    -- ;pepper-scale : num[>=5000] -> symbol
       ;returns pepper name based on scoville-index
       (define (pepper-scale n)
         (cond [(and (>= n 5000) (< n 25000)) 'serrano]
               [(and (>= n 30000) (< n 50000)) 'cayenne]
               [(and (>= n 65000) (< n 90000)) 'thai]
               [(>= n 100000) 'habenero]))
       [note: the scoville-organoleptic test measures the heat of
        peppers by mixing pepper extract with a sugar-water solution
        such that the tongue experiences no sensation when tasting the
        mixture. The scoville-rating indicates the ratio of sugar
        solution to pepper needed for this test.]

  PVD 2001: Suggestion from one of our teachers: make the ranges
  discontiguous, so people are less likely to waste time arguing about
  whether or not we can just assume the fall-through behavior.

  Extend grammar and reduction rules.  

  >> DESIGN RECIPE << for conditionals
    draw intervals, 
    choose interior, boundary points as examples
    write conditional with conditions
    write down answers, case by case 

-------------------------------------------------------------------  

  Structures: 

  positions of a ball: x and y coordinate 
  lots of balls flying around in a game - better keep the x and y
  coordinates together

  Need a way to write down positions

    make-posn : number number -> posn
    (make-posn 3 4)
   
  ;; shift-posn : posn number -> posn
  ;; returns posn shifted in both x and y directions by given number
  (define (shift-posn a-posn num) ...)

  Oops -- need way to take posns apart:

    posn-x : posn -> number
    posn-y : posn -> number

    (posn-x (make-posn 3 4)) = 3
    (posn-y (make-posn 3 4)) = 4

  (define (shift-posn a-posn num) 
    (make-posn (+ num (posn-x a-posn))
               (+ num (posn-y a-posn))))
 
  [PVD 2002: starting with contracts from start made this very smooth
  this year]

  [The confusion over values will likely arise here, as subsequent
   examples appear to "create" the same value twice.

   [PVD 2001: We didn't even introduce the term "values" until
    Tuesday morning.]

   Emphasize that "(make-posn 1 2)" is just the name of a position,
   like "7" is the name of a number. We can write "7" on the twice,
   but it's the same number.]


[Point] LAB

Generated on: Saturday, July 20th, 2002