Lec9 - CMPSC 461 Programming Language Concepts Lecture 9...

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

View Full Document Right Arrow Icon
CMPSC 461: Programming Language Concepts Lecture 9 Instructor: Prof. Swarat Chaudhuri
Background image of page 1

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

View Full Document Right Arrow Icon
Data abstraction Natural numbers zero succ pred is_zero? Implementation Interface Client Client Data type = +
Background image of page 2
Connections between interface and representation Suppose representation of n is |n| (zero ) = |0| (is-zero? |n|) = #t if n = 0 #f otherwise (succ |n|) = |n+1| (pred |n + 1|) = |n|
Background image of page 3

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

View Full Document Right Arrow Icon
How do we write A function to add two numbers? (define plus (lambda (x y) (if (is-zero? x) y (succ (plus (pred x) y))))) This satisfies (plus |x| |y| ) = |x + y|
Background image of page 4
Different implementations Unary: the representation |n| is simply a list of n # t’s . |0| = ’() |1| = ’(# t) Scheme’s internal representation (nothing special about this!) Bignum: Base N numbers for some large N. 1019 10345 75789 97678
Background image of page 5

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

View Full Document Right Arrow Icon
Data abstraction Numbers are not abstract if a client can manipulate the internal representation. Opaque type: Programming language forbids such manipulation. Transparent type:
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 19

Lec9 - CMPSC 461 Programming Language Concepts Lecture 9...

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

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