RU beehive logo ITEC dept promo banner
ITEC 380
2009spring
ibarland

homeinfolecturesexamshwsarchive

displayDeprecationNoticeAsOf(2009,05,31+01, "http://www.radford.edu/itec380/")

lect03
working with lists

Recall:
aggregate data types (structs -- combine other types with AND);
union data types (combine other types with OR).

We finished last time with a recursive data definition: ; A list-of-numbers is: ; - empty, OR ; - (cons [number] [list-of-numbers]) ; Examples of the data: empty (cons 7 empty) (cons 3 (cons 7 empty)) (cons 5 (cons 3 (cons 7 empty))) Scheme has lists as a built-in data type: the following are built-in: ; A constant: empty ; A constructor: cons ; Its corresponding getters: first rest ; Predicates: empty? cons? list?

scheme lisp (and early scheme) If lists hadn't been built-in…
empty nil '() 'my-empty-list-sentinel
cons cons make-kons
first car kons-first
rest cdr kons-rest
cons? cons? kons?
empty? empty? (and (symbol? ) (symbol=? 'my-empty-list-sentinel ))

Topics/examples:

- discuss hw (compare to doing it in Java)
- list-of-nums:  we saw 'length' and 'sum'; write 'countEvens'.  Use a helper?
- list-of-boas:  find-longest;  will-fit?   Use helper.

If the 'first' is itself a complicated data type, definitely use a 
- list-of-animals:   Use helper!

- list-of-robot-moves:  total-steps     Use helper; or a data def'n w/ three branches:
#|
The robo-rally game:
  roborally

  A simple robot game has robots follow instructions like "walk 2,
  turn left, walk 4, walk 6, turn right ...".  We want a data
  definition to capture this.



  A list-of-num-and-sym is
    - empty, or
    - (cons number list-of-num-and-sym)
    - (cons symbol list-of-num-and-sym)

  Develop examples and template

    (cons 1 (cons 'left (cons 5 (cons 'right empty))))
    Alternate syntax: (list 1 'left 5 'right)


  ;; total-steps : list-of-num-and-sym -> number
  ;; produces the sum of all the numbers in the list

|#



- trees?  [Some example simpsons data]

homeinfolecturesexamshwsarchive

displayDeprecationNoticeAsOf(2009,05,31+01, "http://www.radford.edu/itec380/")
©2009, Ian Barland, Radford University
Last modified 2009.Feb.20 (Fri)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme