Lecture3.6 - 1 8/29/06 From slides by N. Ramsey (Copyright)...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 8/29/06 From slides by N. Ramsey (Copyright) 1 DPL-3: Scheme - DATA We will introduce two new kinds of data: The automatically managed "cons" cell The "mother" of all heap allocated data structures Automatic Memory Management (Garbage Collection - not strictly a "language feature") The function closure This is not just a new datum, but a new feature. 8/29/06 From slides by N. Ramsey (Copyright) 2 DPL-3: Scheme Designed around 1975 - child of LISP (1958, 1960 - McCarthy, Russell) and grandchild of IPL (1956 - Newell, Shaw, Simon). Is the quintessential applicative programming environment You dene a function rather than write a program You evaluate a function rather than run a program It's interactive Ultimate simple syntax : parenthesized prex notation (NO precedence for operators) Recursion is the standard control structure Recursive types (S-expressions) are the standard datatypes Program and data are the same Automatic memory management (garbage collection - no pointers) 8/29/06 From slides by N. Ramsey (Copyright) 3 DPL-3: What's new in Scheme: Values Values are S-expressions, where an S-expression is A symbol (name), e.g., 'a An integer literal, e.g., 99 A Boolean #t or #f A list S 1 , S n of 0 or more S-expressions the list of 0 elements is denoted by '() This is not quite true (and could use more precision) - but will be adequate for our very simple version of Scheme. Somewhat more details later 8/29/06 From slides by N. Ramsey (Copyright) 4 DPL-3: S-expressions Like any other abstract data type, we need creators- create new values of the type producers- make new values from existing values observers- examine values of the type mutators- change values of the type N.B.: creators + producers = constructors We will introduce no mutators in Scheme (well... set ) 8/29/06 From slides by N. Ramsey (Copyright) 5 DPL-3: S-expression Creators and Producers '() is the empty list cons creates a new list: (cons S' S) is the list S' S S must be a list: (cons 'a '()) is: cons ('a '(b)) is: '(b) is a literal one-element list. a a b 8/29/06 From slides by N. Ramsey (Copyright) 6 DPL-3: S-expression observers Observers are dened only on lists: (car S) where S = ( S 1 , , S n ) , n > , is S 1 . (cdr S) where S = ( S 1 , , S n ) , n > , is ( S 2 ,, S n ) Interaction between constructor and observers : (car (cons 'a L)) 'a (cdr (cons 'a L)) L N.B.: (cdr (cons 'a '()) '() 2 8/29/06 From slides by N. Ramsey (Copyright) 7 DPL-3: more S-expression observers We introduce some predicates : they apply to all types return #f for false and #t for true ....
View Full Document

Page1 / 17

Lecture3.6 - 1 8/29/06 From slides by N. Ramsey (Copyright)...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online