RU beehive logo ITEC dept promo banner
ITEC 380
2008fall
ibarland

homeinfolecturesexamsarchive

lect06b
mutual recursion example; intro BNF

In-class quiz:
  1. Suppose grow-fire is aready written; write grow-fires, using map.
  2. Suppose draw-fire is already written; write draw-fires, using foldl.
  3. Write map (not using foldl or foldr).
  4. Extra credit: write map using foldl.
; grow-fires : (-> (list-of fire) (list-of fire))
; Return the result of applying `grow-fire` to each element of `data`.
;
(define (grow-fires lof)
   )

; draw-fires : (-> (list-of fire) scene scene)
; Return the result of calling `draw-fire` for each fire onto sc.
;
(define (draw-fires lof sc)
   )

; map : (-> (-> α β) (list-of α) (list-of β))
; Return the result of applying `g` to each element of `data`.
;
(define (map f data)
   )
Examples:
(map sqr (list 3 4 5)) = (list 9 15 25)
(foldl + 0 (list 3 4 5)) = 12

- Sexpr: data-def'n.  Example: html.
   (see ~/Library/Preferences/.GlobalPreferences.plist.orig)


Data def'n, "S Expression":
An sexpr is:
 - an atom, or
 - a list-of-sexpr)

A list-of-sexpr) is:
 - empty, or
 - (cons sexpr list-of-sexpr)

An atom is:
 - a number
 - a symbol
 - a String
 - a boolean
 - a structure
 - an image
 - empty (!)

Same data def'n, written in BNF  [Reading: §3.1-§3.3 ]


sexpr ::= atom | sexprList
sexprList ::= empty
            | (cons sexpr sexprList)

atom ::= ...


  To do:
   Code which processes s-exprs.  (Really, same as file and family-trees.)
   Write total-count -- using map, and (apply + ...)
   Write equal? -- using map, and (apply and ...).  Wait, need andmap.

homeinfolecturesexamsarchive


©2008, Ian Barland, Radford University
Last modified 2008.Oct.10 (Fri)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme