David Evans CS150: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.

Slides:



Advertisements
Similar presentations
Class 3: Rules of Evaluation David Evans cs1120 Fall 2009.
Advertisements

David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 39: Lambda Calculus.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
ALGOL 60 Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. Design by committee of computer scientists:
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
Lecture 1: Intro to Computers Yoni Fridman 6/28/01 6/28/01.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
CSC 160 Computer Programming for Non-Majors Lecture #3: Calling Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #3a: Stepper, Words, Sentences Prof. Adam M. Wittenstein
1 CS 415: Programming Languages Fortran Aaron Bloomfield Fall 2005.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 2: Formal Systems and Languages MU!
David Evans CS200: Computer Science University of Virginia Computer Science Class 31: Universal Turing Machines.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Computer Science 101 Introduction to Programming.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chpater 3. Outline The definition of Syntax The Definition of Semantic Most Common Methods of Describing Syntax.
1 Extended Introduction to Computer Science 2 Administration סגל הקורס: –מרצים: ד"ר דניאל דויטש, איל כהן –מתרגלת:לבנת ג'רבי –בודק: ינון פלד Book: Structure.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
计算机科学概述 Introduction to Computer Science 陆嘉恒 中国人民大学 信息学院
CS 415 Daily Announcements. Friday, 26 August 2005 Readings: –Read Chapter 1 for next Monday –Read Algol 60 report for next Wednesday –Read some of chapter.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Think Globally, Mutate Locally.
Copyright © Curt Hill Languages and Grammars This is not English Class. But there is a resemblance.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
Principles of Programming Languages Lecture 1 Slides by Yaron Gonen, based on slides by Daniel Deutch and lecture notes by Prof. Mira Balaban.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 2: Formal Systems and Languages MU!
Lecture 2: Formal Systems and Languages MU! CS150: Computer Science
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 36: Modeling Computing.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 4: The Value of Everything.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 19: Environments.
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
Lecture 3: Rules of Evaluation CS150: Computer Science
Chapter 1: Introduction to Computers and Programming.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 2: Formal Systems and Languages MU!
(Thunking about Thunks)
Lecture 4: Metacircles Eval Apply David Evans
Lecture 6: Lambda Calculus
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation
Lecture 2: Schreme David Evans
Algol 60 John Cowan N Languages in N Months Meetup June 7, 2016
Lecture 4: Evaluation Rules Recursion CS200: Computer Science
Class 27: Universal Turing Machines CS150: Computer Science
Class 30: Models of Computation CS200: Computer Science
CS 326 Programming Languages, Concepts and Implementation
Lecture 37: A Universal Computer
Lambda Calculus Revisited
Class 19: Think Globally, Mutate Locally CS150: Computer Science
CS190/295 Programming in Python for Life Sciences: Lecture 1
Chapter 10 Programming Fundamentals with JavaScript
Mini Language Interpreter Programming Languages (CS 550)
The Metacircular Evaluator
Lecture 2: Formal Systems and Languages MU! CS200: Computer Science
FP Foundations, Scheme In Text: Chapter 14.
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 12/25/2018.
CS 3304 Comparative Languages
Lecture 25: Metalinguistics > (meval '((lambda (x) (* x x)) 4)
Lecture 24: Metalinguistics CS200: Computer Science
Extended Introduction to Computer Science
Streams, Delayed Evaluation and a Normal Order Interpreter
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019.
Class 31: Universal Turing Machines CS200: Computer Science
Class 34: Models of Computation CS200: Computer Science
Lecture 2 מבוא מורחב.
Lecture 3: Rules of Evaluation CS200: Computer Science
Class 26: Modeling Computing CS150: Computer Science
Introduction to the Lab
Presentation transcript:

David Evans CS150: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation

2 Lecture 3: Evaluation Rules Menu Describing Languages Learning New Languages Evaluation Rules My office hours are now scheduled: Wednesdays, 1-2pm (right after class) Thursdays, 3:30-4:30pm If you can’t make them, send to arrange meetings at other times.

3 Lecture 3: Evaluation Rules ENIAC: Electronic Numerical Integrator and Computer Early WWII computer –But not the world’s first (PS4) Built to calculate bombing tables Memory size: twenty 10 decimal digit accumulators = 664 bits Apollo Guidance Computer (1969): 1 inch You: 4.4 miles ENIAC (1946): ½ mm

4 Lecture 3: Evaluation Rules Directions for Getting 6 1.Choose any regular accumulator (ie. Accumulator #9). 2.Direct the Initiating Pulse to terminal 5i. 3.The initiating pulse is produced by the initiating unit's Io terminal each time the Eniac is started. This terminal is usually, by default, plugged into Program Line 1-1 (described later). Simply connect a program cable from Program Line 1-1 to terminal 5i on this Accumulator. 4.Set the Repeat Switch for Program Control 5 to 6. 5.Set the Operation Switch for Program Control 5 to. 6.Set the Clear-Correct switch to C. 7.Turn on and clear the Eniac. 8.Normally, when the Eniac is first started, a clearing process is begun. If the Eniac had been previously started, or if there are random neons illuminated in the accumulators, the ``Initial Clear'' button of the Initiating device can be pressed. 9.Press the ``Initiating Pulse Switch'' that is located on the Initiating device. 10.Stand back.

5 Lecture 3: Evaluation Rules Mathematics PhD Yale, 1934 Entered Navy, 1943 First to program Mark I (first “large” computer, 51 feet long) Wrote first compiler (1952) – program for programming computers Co-designer of COBOL (most widely used programming language until a few years ago) Admiral Grace Hopper ( ) “Nobody believed that I had a running compiler and nobody would touch it. They told me computers could only do arithmetic.”

6 Lecture 3: Evaluation Rules USS Hopper Guest on David Letterman “Dare and Do”

7 Lecture 3: Evaluation Rules Nanostick How far does light travel in 1 nanosecond? > (define nanosecond (/ 1 (* ))) ;; 1 billionth of a s > (define lightspeed ) ; m / s > (* lightspeed nanosecond) / > (exact->inexact (* lightspeed nanosecond)) = just under 1 foot Dell machines in Small Hall have “1.8-GHz Pentium 4 CPU” GHz = GigaHertz = 1 Billion times per second They must finish a step before light travels 6.6 inches!

8 Lecture 3: Evaluation Rules Code written by humans Compiler Code machine can run Compiler translates from code in a high- level language to machine code DrScheme uses an interpreter. An interpreter is like a compiler, except it runs quickly and quietly on small bits of code at a time.

9 Lecture 3: Evaluation Rules John Backus Chemistry major at UVA (entered 1943) Flunked out after second semester Joined IBM as programmer in 1950 Developed Fortran, first commercially successful programming language and compiler

10 Lecture 3: Evaluation Rules IBM 704 Fortran manual, 1956

11 Lecture 3: Evaluation Rules Describing Languages Fortran language was described using English –Imprecise –Verbose, lots to read –Ad hoc DO 10 I=1.10 Assigns 1.10 to the variable DO10I DO 10 I=1,10 Loops for I = 1 to 10 (Often incorrectly blamed for loss of Mariner-I) Wanted a more precise way of describing a language

12 Lecture 3: Evaluation Rules Backus Naur Form symbol ::= replacement We can replace symbol with replacement nonterminal – symbol that appears on left side of rule terminals – symbol that never appears on the left side of a rule A ::= B means anywhere you have an A, you can replace it with a B.

13 Lecture 3: Evaluation Rules Language Elements When learning a foreign language, which elements are hardest to learn? Primitives: lots of them, and hard to learn real meaning Means of Combination –Complex, but, all natural languages have similar ones [Chomsky] SOV (45% of all languages) Sentence ::= Subject Object Verb (Korean) SVO (42%) Sentence ::= Subject Verb Object VSO (9%)Sentence ::= Verb Subject Object (Welsh) “Lladdodd y ddraig y dyn.” (Killed the dragon the man.) OSV (<1%): Tobati (New Guinea) Schemish: Expression ::= (Verb Object) Means of Abstraction: few of these, but tricky to learn differences across languages English: I, we Tok Pisin (Papua New Guinea): mi (I), mitupela (he/she and I), mitripela (both of them and I), mipela (all of them and I), yumitupela (you and I), yumitripela (both of you and I), yumipela (all of you and I)

14 Lecture 3: Evaluation Rules Pages in Revised 5 Report on the Algorithmic Language Scheme Primitives Means of Combination Means of Abstraction 48 pages total (includes formal specification and examples)

15 Lecture 3: Evaluation Rules Pages in Revised 5 Report on the Algorithmic Language Scheme Primitives Standard Procedures Primitive expressions Identifiers, numerals Means of Combination Expressions Program structure 2222 Means of Abstraction Definitions½ 48 pages total (includes formal specification and examples)

16 Lecture 3: Evaluation Rules Pages in Revised5 Report on the Algorithmic Language Scheme Pages in C++ Language Specification (1998) Primitives Standard Procedures Primitive expressions Identifiers, numerals Means of Combination Expressions Program structure 2222 Means of Abstraction Definitions½ 48 pages total (includes formal specification and examples)

17 Lecture 3: Evaluation Rules Pages in Revised 5 Report on the Algorithmic Language Scheme Pages in C++ Language Specification (1998) Primitives Standard Procedures Primitive expressions Identifiers, numerals Standard Procedures Primitive expressions Identifiers, numerals Means of Combination Expressions Program structure 2222 Expressions, Statements Program Structure Means of Abstraction Definitions½Declarations, Classes pages total (includes formal specification and examples) 776 pages total (includes no formal specification or examples) C++ Core language issues list has 469 items!

18 Lecture 3: Evaluation Rules Pages in Revised 5 Report on the Algorithmic Language Scheme English Primitives Standard Procedures Primitive expressions Identifiers, numerals Morphemes Words in Oxford English Dictionary ? 500,000 Means of Combination Expressions Program structure 2222 Grammar Rules English Grammar for Dummies Book 100s (?) 384 pages Means of Abstraction Definitions½Pronouns~20 48 pages total (includes formal specification and examples)

Evaluation

20 Lecture 3: Evaluation Rules Expressions and Values (Almost) every expression has a value –Have you seen any expressions that don’t have values? When an expression with a value is evaluated, its value is produced

21 Lecture 3: Evaluation Rules Primitive Expressions Expression ::= PrimitiveExpression PrimitiveExpression ::= Number PrimitiveExpression ::= #t | #f PrimitiveExpression ::= Primitive Procedure

22 Lecture 3: Evaluation Rules Evaluation Rule 1: Primitives If the expression is a primitive, it evaluates to its pre-defined value. > 2 2 > #t #t > + #

23 Lecture 3: Evaluation Rules Name Expressions Expression ::= NameExpression NameExpression ::= Name

24 Lecture 3: Evaluation Rules Evaluation Rule 2: Names If the expression is a name, it evaluates to the value associated with that name. > (define two 2) > two 2

25 Lecture 3: Evaluation Rules Application Expressions Expression ::= Application Expression ApplicationExpression ::= (Expression MoreExpressions) MoreExpressions ::= ε MoreExpressions ::= Expression MoreExpressions

26 Lecture 3: Evaluation Rules Evaluation Rule 3: Application 3.If the expression is an application: a)Evaluate all the subexpressions (in any order) b)Apply the value of the first subexpression to the values of all the other subexpressions. (Expression 0 Expression 1 Expression 2 … )

27 Lecture 3: Evaluation Rules Rules for Application 1.Primitives. If the procedure to apply is a primitive, just do it. 2.Constructed Procedures. If the procedure is a constructed procedure, evaluate the body of the procedure with each formal parameter replaced by the corresponding actual argument expression value.

28 Lecture 3: Evaluation Rules Eval Apply Eval and Apply are defined in terms of each other. Without Eval, there would be no Apply, Without Apply there would be no Eval!

29 Lecture 3: Evaluation Rules Making Procedures lambda means “make a procedure” Expression ::= ProcedureExpression ProcedureExpression ::= (lambda (Parameters) Expression) Parameters ::= ε Parameters ::= Name Parameters

30 Lecture 3: Evaluation Rules Evaluation Rule 4: Lambda 4. Lambda expressions evaluate to a procedure that takes the given parameters and has the expression as its body.

31 Lecture 3: Evaluation Rules Lambda Example: Tautology Function (lambda () #t) > ((lambda () #t) 150) # : expects no arguments, given 1: 150 > ((lambda () #t)) #t > ((lambda (x) x) 150) 150 make a procedure with no parameters with body #t

32 Lecture 3: Evaluation Rules Evaluation Rule 5: If (if Expression Predicate Expression Consequent Expression Alternate ) To evaluate an if expression: (a)Evaluate Expression Predicate. (b) If it evaluates to #f, the value of the if expression is the value of Expression Alternate. Otherwise, the value of the if expression is the value of Expression Consequent.

33 Lecture 3: Evaluation Rules Now You Know All of Scheme! Once you understand Eval and Apply, you can understand all Scheme programs! Except: –There are a few more special forms (like if) –We have not define the evaluation rules precisely enough to unambiguously understand all programs (e.g., what does “value associated with a name” mean?)

34 Lecture 3: Evaluation Rules Charge Problem Set 2: out today (we’ll talk about it next class) Reading: Chapters 4 and 5