Lecture 11 Notes

or similarly 3 1

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: mentation of the ¡ ¦ % ¡¦ 0§ ¡ y ' ¡ x ¦¦¦¦ §¥¥¥¦ ¤  ¡  ¢ © "¨ ¢ ¥"© ¦ )¢ © ' % ¤¥§ ¡ ¢ ¦  '(&¢ % © "¨  ¢  ¢ £ $  ¢ #  ¥    ¢ ¢ will satisfy integers we use. © "¨  Or similarly: ¦¥¦¥¦¥¦¥¦ ¦  ¤ ¡  ' % ¢ ¦ § ¡   ¢ 3 ©#  © "   ¢ 1' ¢ ¦  © )¢ ¤ % ¥§ ¡ ¢ ¦  '(&¢ £ % ©#    ¢ # $  ¢  ¥    ¢ Implementations: 1. Unary representation: ¢ ’s. e.g., 0 is represented by , etc. , 1 is ¦ ¦   ¡ ¡ So the integer n is represented by a list of n represented by , 2 is represented by n) ¡ ¡¨  ¦ ¡ ¨ ¢ 1  © ¥§¢ 0 n  ¢ ¦ ¢ It’s easy to see that we can satisfy the specification by writing:  ¥    ¢  § ¡   ¥    ¢ © ¤ ¥§ ¡  £¢ ¦ ¤  ¨ ¥  ¦¦ ¥¥¦ ¥  ¡ ¢ ¦ §¦ ¦ ¥ ¢  £ $  ¢ #  ¥©  ¥    ¢ ©¥§ ¢  ¥    ¢ ¦ ¡  ¤ ¡   2. Scheme number representation: ¥ ¥ ¦¥¥) ¦¦ ¦¦¦ ¥¥) ¥  n = the Scheme integer ¡ ¥ ¥ ¥ ¥  ¢ £ ¥¤¢ ¦¥    ¤ ¡  ¢ £# ¢ ¦  ¥ ¢  £ #  ¢ ¥© ¦  © ¤¥§ ¡  ¤¥§ ¡  £¢ ¦  § ¡  ¢ ¢  ¢  ¢  ¢   3. Bignum representation (Base B, least-significant bigit first): N ¦ ) ¢ ©¢ 4  ¡ ¡ ©¥§ ¡ ¡ So if N 16, 33 , 258 (258 1 162 0 ). Exercise: write the operations in this implementation. 16 0  r 161  r0 2  0 qB  r q) n n ¡ ¨§¦ © () ( ¡ n ¡ ¨ ¡ ¦ ©  ¢ ¡ ¡ ¡ 2.3 Environments 2.3.1 Interface Data: An environment is a function whose domain is a finite set of Scheme symbols, and whose range is the set of all Scheme values. (s1 v1 ) (s n v n ) ¤ Typical environment: ¦ ¦ £¢¢¦ ¦ ¡¡¡ where the si are distinct symbols and the vi are any Scheme values. We sometimes call the value of s in an environment env its binding in env. Three procedures in the interface: ¡ ¦ ¡ ¡ ¡ where g(s ) v if s s f (s ) otherwise ¡© f (s) g © ¡ § ¨ ¡© © fs sv f ¦ ¦ § ¡ ¡  ¦  ¥   ¥ ¦¥ %   ¨¦  ¥ ¦¥ ' ¦ ¦¥     # ¥ ' ¢  ¢ ...
View Full Document

This document was uploaded on 03/17/2014 for the course CSG 111 at Northeastern.

Ask a homework question - tutors are online