primitive data types n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Primitive Data Types PowerPoint Presentation
Download Presentation
Primitive Data Types

Loading in 2 Seconds...

play fullscreen
1 / 10

Primitive Data Types - PowerPoint PPT Presentation


  • 185 Views
  • Uploaded on

Primitive Data Types. Symbol: any sequence of characters except ()[]{};,”`’#\ Number signed integers signed real numbers bignums (large integers) rationals exponential notation for reals complex numbers Boolean constants: #t #f. Naming. (define pi 3.14159) ;; special form

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Primitive Data Types' - star


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
primitive data types
Primitive Data Types
  • Symbol: any sequence of characters except ()[]{};,”`’#\
  • Number
    • signed integers
    • signed real numbers
    • bignums (large integers)
    • rationals
    • exponential notation for reals
    • complex numbers
  • Boolean constants: #t #f
naming
Naming

(define pi 3.14159) ;; special form

(define radius 10)

(* pi (* radius radius))

314.159

(define circumference

(* 2 pi radius))

circumference

62.8318

(define (circumference r) ;; redefinition

(* 2 pi r))

(circumference 20)

example of evaluation
Example of Evaluation

(* (+ 2 (* 4 6))

(+ 3 5 7))

390

15

26

*

7

+

5

3

+

2

24

*

6

4

rules of evaluation
Rules of Evaluation
  • The value of a numeral is itself.
  • The value of a primitive operation is a pointer to the internal machine instructions to accomplish it.
  • The value of a name is the value associated with that name in an environment.
  • The value of a combination is obtained by:
    • Evaluating the sub-expressions in any order.
    • Applying the value of the operator sub-expression to the values of the other sub-expressions, where applying a compound procedure means evaluating the body of the procedure with each formal parameter replaced by is corresponding value.
procedure definition
Procedure Definition

(define (square x) (* x x))

(square 21)

(square (+ 2 5))

(square (square 3))

(define (sum-of-squares x y)

(+ (square x) (square y)))

(sum-of-squares 3 4)

(define (f a)

(sum-of-squares (+ a 1) (* a 2)))

(f 5)

substitution model
Substitution Model

(f 5)

;; (sum-of-squares (+ a 1) (* a 2))

;: (sum-of-squares (+ 5 1) (* 5 2))

;: (+ (square 6) (square 10))

;: (+ (* 6 6) (* 10 10))

;: (+ 36 100)

136

  • NOT how the interpreter really works!
  • A way to start thinking about the process
  • Applicative order of evaluation: eval-and-apply
normal order evaluation
Normal Order Evaluation

(f 5)

(sum-of-squares (+ 5 1) (* 5 2))

(+ (square (+ 5 1))(square (* 5 2)))

(+ (* (+ 5 1) (+ 5 1))

(* (* 5 2) (* 5 2)))

(+ (* 6 6) (* 10 10))

(+ 36 100)

136

evaluation an example
Evaluation: An Example

(define (p) (p))

(define (test x y)

(if (= x 0)

0

y))

(test 0 (p))

  • applicative order: eval-and-apply infinite loop due to (p)
  • normal order: fully-expand-and-reduce infinite term, safe execution
conditional expressions
Conditional Expressions

(define (abs x)

(cond ((> x 0) x)

((= x 0) 0)

((< x 0) (- x))))

(define (abs x)

(cond ((< x 0) (- x))

(else x)))

(define (abs x)

(if (< x 0)

(- x)

x))

compound predicates
Compound Predicates

(and (> x 5) (< x 10))

(define (>= x y)

(or (> x y) (= x y)))

(define (>= x y)

(not (< x y)))