day02

day02 - CS1: Introduction to Computation Day 2: October 1,...

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

View Full Document Right Arrow Icon
Caltech CS 1 -- Fall 2008 CS1: Introduction to Computation Day 2: October 1, 2008 Substitution Model
Background image of page 1

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

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Before we begin…
Background image of page 2
Caltech CS 1 -- Fall 2008 Monty Python and the Holy Grail (1975)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Precision • Human (natural) language is imprecise – full of ambiguity • Computer languages must be precise – only one meaning – no ambiguity
Background image of page 4
Caltech CS 1 -- Fall 2008 Last time • saw how to form Scheme expressions – primitive expressions e.g. numbers – combinations – abstractions using define – procedures using lambda
Background image of page 5

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

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Today • We’ll determine the meaning of Scheme expressions – by developing a precise model for interpreting them • This model: Substitution Model
Background image of page 6
Caltech CS 1 -- Fall 2008 Analysis and synthesis • Programming has two interrelated aspects: – How do I design a program that does a particular job? ( synthesis ) – How do I understand the behavior of some code I’ve already written? ( analysis ) • This lecture is mostly analytical – We’ll analyze very simple “programs” • We’ll look at program design starting next lecture 7
Background image of page 7

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

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Admin 1 • We post slides after class – and sometimes before – see course schedule online • We put Scheme code on handout – sometimes on back of “Big Idea” handout • (more admin at end of class)
Background image of page 8
Caltech CS 1 -- Fall 2008 Scheme combinations • Recall: ( operator operand1 operand2 … ) – delimited by parentheses – first element is the operator – rest are operands
Background image of page 9

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

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Some simple combinations • (+ 2 3) • (- 4 1) • (+ 2 3 4) • (abs -7) • (abs (+ (- x1 x2) (- y1 y2)))
Background image of page 10
Caltech CS 1 -- Fall 2008 Meaning? • What does a Scheme expression mean ? • In other words: • How do we know what value will be calculated by an expression?
Background image of page 11

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

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Substitution Model The basic rule: To evaluate a Scheme expression: 1. Evaluate its operands 2. Evaluate the operator 3. Apply the operator to the evaluated operands
Background image of page 12
Caltech CS 1 -- Fall 2008 Note! • The order in which operands are evaluated doesn’t matter – no matter what order, get the same result • In fact, can even evaluate the operator before the operand and it’ll work fine • We keep this order for compatibility with the textbook (SICP) 13
Background image of page 13

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

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Warning! Boredom ahead! • We will walk through evaluations – in painful, excruciating detail • Not the most exciting part of course • but necessary to give a precise model – so stay awake
Background image of page 14
Caltech CS 1 -- Fall 2008 Example expression eval • Example: (+ 3 (* 4 5) )
Background image of page 15

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

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Example expression eval • Example: ( + 3 (* 4 5) ) operator
Background image of page 16
Caltech CS 1 -- Fall 2008 Example expression eval • Example: ( + 3 (* 4 5) ) operator operand 1
Background image of page 17

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

View Full DocumentRight Arrow Icon
Caltech CS 1 -- Fall 2008 Example expression eval • Example: ( + 3 (* 4 5) ) operator operand 1 operand 2
Background image of page 18
Example expression eval • Note:
Background image of page 19

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

View Full DocumentRight Arrow Icon
Image of page 20
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 63

day02 - CS1: Introduction to Computation Day 2: October 1,...

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

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