Programming Languages - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Programming Languages

Description:

... Programs, online book: http://www.htdp.org/2003-09-26/Book/ chaps 1 ... blue parenthesis define the binding pairs. Practicum 1. variables and let expressions ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 17
Provided by: John859
Category:

less

Transcript and Presenter's Notes

Title: Programming Languages


1
Programming Languages
  • COMP 321
  • Spring 2012
  • Practicum 1

2
Practicum 1
  • expressions
  • lists (car, cdr, cons, list)
  • let expressions
  • lambda expressions
  • proper list, single variable, improper list
  • top level definitions (define)
  • conditional expressions

3
Practicum 1
  • reference
  • The Scheme Programming Language, 3rd ed., R. Kent
    Dybvig, MIT Press, chapter 2, sections 1-7
  • How to Design Programs, online book
    http//www.htdp.org/2003-09-26/Book/ chaps 1 2

4
Practicum 1
  • Expressions prefix
  • ( 3 5)
  • ( ( (/ 4 2) ( 3 7) 3)

5
Practicum 1
  • Lists
  • The principle data structure in Scheme
  • car and cdr operators to take apart lists
  • cons and append operators to put together lists
  • Lists always contain an empty pair () as their
    last item (like the \0 char in a C string)

6
Practicum 1
  • Lists
  • (a 4 z)
  • ( 3 4)
  • (car (a b c))
  • (cdr (a b c))
  • (car ((1 2)(3 4) 5))
  • (cdr ((1 2)(3 4) 5))

7
Practicum 1
  • lists
  • car and cdr can be combined
  • (cadr (a b c))
  • (caddr (a b c))
  • (cdar ((1 2)(3 4) 5))
  • (cdadr ((1 2)(3 4) 5))

8
Practicum 1
  • lists
  • (cons a ())
  • (cons a (b c))
  • (cons a (cons b (cons c ())))
  • (cons (a b) (c d))

9
Practicum 1
  • lists
  • (car (cons a (b c)))
  • (cdr (cons a (b c)))
  • (cons (car (a b c))
  • (cdr (d e f)))
  • (cons (car (a b c))
  • (cdr (a b c)))

10
Practicum 1
  • inproper lists (does not end in an empty pair)
  • (cons a b)
  • (cdr (a . b))
  • (cons a (b . c))
  • (a . b . c)

11
Practicum 1
  • Lists creating lists
  • (list a b c)
  • (list a)
  • (list)

12
Practicum 1
  • Lists combining lists
  • (append (a b) (d c))
  • (append a (b c)) what does this do?
  • (append (a b) c) why do you get
  • this answer?

13
Practicum 1
  • variables and let expressions
  • Creating local environments
  • Binding names to values
  • (let ((x 2))
  • ( x 3))
  • (let ((x 2) (y 3))
  • ( x y))

red parenthesis define the scope of the local
environment
blue parenthesis define the binding pairs
14
Practicum 1
  • variables and let expressions
  • (let ((a ( 4 4)))
  • ( a a))
  • Now we start to see the power of Scheme!
  • (let ( (f ) (x 2)(y 3) )
  • (f x y))

Scheme has complete orthagonality!
15
Practicum 1
  • Nesting environments
  • (let ((x 1))
  • (let ((new-x ( x 1)))
  • ( new-x new-x)) )

16
Practicum 1
  • Nesting environments
  • Local environment create scope!
  • (let ((x 1))
  • (let ((x ( x 1)))
  • ( x x)
  • )
  • )
Write a Comment
User Comments (0)
About PowerShow.com