ClosuresStreams - Click to edit Master subtitle style...

Info iconThis preview shows pages 1–11. 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

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight 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: Click to edit Master subtitle style CS784(pm) Closures and Streams More on Evaluations CS784(pm) 11 CS784(pm) References Structure and Interpretation of Computer Programs (SICP) http://mitpress.mit.edu/sicp/ 1.3 Abstractions w/ Higher-Order Procedures 3.2 The Environment Model of Evaluation 3.5 Streams 4.2 Variations on a Scheme Lazy Evaluation 22 CS784(pm) CS784(pm) Four Types Of Expressions Constants: numbers, booleans. Variables: names for values. Created using the special form define Special forms have special rules for evaluation. Cannot be redefined 15 magic words and, begin, case, cond, define, do, if, 33 CS784(pm) CS784(pm) Mantras of Scheme Every expression has a value except for errors, infinite loops, and define special form Computing the value of a combination (operator operands ) Compute all sub-expressions (in any order) Apply the value of the first to the values of the 44 CS784(pm) CS784(pm) Order Of Evaluation The order of evaluation turns out to be of central importance for the strength of the functional paradigm. In this lecture we will study the subject of evaluation order in the functional programming paradigm. This includes an introduction to infinite lists (streams) in Scheme. CS784(pm) 55 CS784(pm) Referential Transparency Two equal expressions can substitute each other without affecting the meaning of a functional program Referential transparency provides for easy equational reasoning about a program does not rely on a particular notion of equality Reference equality, shallow equality and deep equality cannot be distinguished by functional CS784(pm) 66 CS784(pm) Referential Transparency With referential transparency it is possible to perform natural program transformations without any concern for side effects Are these two equivalent? 1. (3*F(a,b)+b) *(3*F(a,b)-c) 2. let t be 3*F(a,b) in (t+b)*(t+c) . Depends on the Details of F(x, y). CS784(pm) 77 CS784(pm) 88 Substitution Model of Evaluation No assignments; i.e., no set! Or its equivalent. To apply a compound procedure to arguments, evaluate the body of the procedure with each formal parameter replaced by the corresponding argument (define (square x ) (* x x )) ( ( lambda ( x y ) (+ (square x ) (square y )) ) (- 5 3) 5 ) = (+ (square 2) (square 5)) = (+ (* 2 2) (* 5 5)) = (+ 4 25) CS784(pm) distance-between-points (define square (lambda (x) (* x x))) (define sum-of-squares (lambda (x y) (+ (square x) (square y)))) (define dist-between-pts (lambda (x1 y1 x2 y2) (sqrt (sum-of-squares (- x1 x2) (- y1 y2))))) 99 CS784(pm) Substitution Model Example the evaluated expressions have "**" before and after ** them....
View Full Document

This note was uploaded on 06/02/2011 for the course CS 784 taught by Professor Tkprasad during the Spring '11 term at New York Institute of Technology-Westbury.

Page1 / 51

ClosuresStreams - Click to edit Master subtitle style...

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

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