6.001: Structure and Interpretation of Computer Programs

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
Advanced Topics Object-Oriented Programming Using C++ Second Edition 13.
מבוא מורחב - שיעור 2 1 Lecture 2 - Substitution Model (continued) - Recursion - Block structure and scope (if time permits)
SICP Interpretation part 1 Parts of an interpreter Arithmetic calculator Names Conditionals and if Store procedures in the environment.
JavaScript, Third Edition
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
1 Extended Introduction to Computer Science 2 Administration סגל הקורס: –מרצים: ד"ר דניאל דויטש, איל כהן –מתרגלת:לבנת ג'רבי –בודק: ינון פלד Book: Structure.
Principles of Programming Languages Lecture 1 Slides by Yaron Gonen, based on slides by Daniel Deutch and lecture notes by Prof. Mira Balaban.
Introduction. 2COMPSCI Computer Science Fundamentals.
Principles of Programming Languages Lecture 1 Slides by Daniel Deutch, based on lecture notes by Prof. Mira Balaban.
מבוא מורחב 1 Review: scheme language things that make up scheme programs: self-evaluating 23, "hello", #t names +, pi combinations (+ 2 3) (* pi 4) special.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
1 The Evaluator. 2 Compiler vs. Interpreter Command Processing Unit The Computer Program in Low Level Machine Language Program in High Level Language.
Principles of Programming Languages Lecture 1 Slides by Yaron Gonen, based on slides by Daniel Deutch and lecture notes by Prof. Mira Balaban.
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
What is the main focus of this course? This course is about Computer Science Geometry was once equally misunderstood. Term comes from ghia & metra or earth.
Building Abstractions with Variables (Part 1) CS 21a: Introduction to Computing I First Semester,
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Chapter 9 ProgrammingLanguages.  Describe the evolution of programming languages from machine language to high-level languages.  Understand how a program.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Textbook C for Scientists and Engineers © Prentice Hall 1997 Available at NUS CO-OP at S$35.10.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Operational Semantics of Scheme
Functional Programming
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation
A Simple Syntax-Directed Translator
Lecture 4: Evaluation Rules Recursion CS200: Computer Science
6.001 SICP Variations on a Scheme
Topic: Python’s building blocks -> Variables, Values, and Types
Object Oriented Programming
Representation, Syntax, Paradigms, Types
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Original material by Eric Grimson
Announcements Final Exam on August 17th Wednesday at 16:00.
6.001 SICP Data abstractions
Building Java Programs Chapter 2
Higher-Order Procedures
The Metacircular Evaluator
Functional Programming
This Lecture Substitution model
Representation, Syntax, Paradigms, Types
Dynamic Scoping Lazy Evaluation
The Metacircular Evaluator
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.
Programming Languages 2nd edition Tucker and Noonan
Representation, Syntax, Paradigms, Types
The Metacircular Evaluator (Continued)
6.001 SICP Further Variations on a Scheme
Extended Introduction to Computer Science
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Lecture 12: Message passing The Environment Model
Lecture 13 - Assignment and the environments model Chapter 3
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.
Material in the textbook Sections to 1.2.1
6.001 SICP Variations on a Scheme
Representation, Syntax, Paradigms, Types
Summary of what we learned yesterday
Today’s topics Abstractions Procedural Data
Lecture 2 מבוא מורחב.
This Lecture Substitution model
6.001 SICP Interpretation Parts of an interpreter
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Lecture 3: Rules of Evaluation CS200: Computer Science
Introduction to the Lab
This Lecture Substitution model
Lecture 2 מבוא מורחב.
Good programming practices
Presentation transcript:

6.001: Structure and Interpretation of Computer Programs Today The structure of 6.001 The content of 6.001 Beginning to Scheme 4/7/2019 6.001 SICP

6.001: Structure and Interpretation of Computer Programs Main sources of information on logistics: General information handout Course web page http://sicp.csail.mit.edu/ 4/7/2019 6.001 SICP

Course structure Lectures Recitations Tutorials Delivered live here, twice a week (Tuesday and Thursday) Versions of lectures also available on the web site, as audio annotated Power Point. Treat this like a live textbook. Versions are not identical to live lecture, but cover same material. Recitations Twice a week (Wednesday and Friday) DON’T go to recitation assigned by registrar. We are going to do section assignments based on your input yesterday. Please check the web site for your assigned section. If you have conflict, contact course secretary by EMAIL only. You are expected to have attended the lecture (or listened to the online version) before recitation Opportunity to reinforce ideas, learn details, clarify uncertainties, apply techniques to problems Tutorials Once a week (typically Monday) Mandatory Ask questions, participate in active learning setting 4/7/2019 6.001 SICP

6.001: Structure and Interpretation of Computer Programs Grades 2 mid-term quizzes – 25% Final exam – 25% 1 introductory project and 4 extended programming projects – 30% weekly problem sets – 10 % BUT MUST ATTEMPT ALL OR COULD RESULT IN FAILING GRADE!! Participation in tutorials and recitations – 10% 4/7/2019 6.001 SICP

6.001 – contact information Course secretary Donna Kaufman, dkauf@mit.edu, 38-409a, 3-4624 Lecturer Eric Grimson, welg@csail.mit.edu Web site: http://sicp.csail.mit.edu/ 4/7/2019 6.001 SICP

Other logistics Problem sets Projects Are released through the online tutor (see website for link – will create login for you when first used) Are due electronically on the date posted Includes lecture problems which are due on day of associated recitation First one was posted today! Projects First one was released today Check website for updates 4/7/2019 6.001 SICP

4/7/2019 6.001 SICP

4/7/2019 6.001 SICP

4/7/2019 6.001 SICP

4/7/2019 6.001 SICP

6.001: Structure and Interpretation of Computer Programs Other issues Collaboration – Read description on web site Use of bibles – see description on web site Time spent on course Survey shows 15-18 hours/week Seeking help Lab assistants Other sources 6.001 Lab – 34-501 Combination – 72962* 4/7/2019 6.001 SICP

6.001: Structure and Interpretation of Computer Programs Today The structure of 6.001 The content of 6.001 Beginning to Scheme 4/7/2019 6.001 SICP

What is the focus of 6.001? This course is about Computer Science An analogy is to Geometry: This comes from Ghia & Metra or Earth & Measure Geometry deals with Declarative or “what is” knowledge Computer Science deals with Imperative or “how to” knowledge 4/7/2019 6.001 SICP

Declarative Knowledge “What is true” knowledge 4/7/2019 6.001 SICP

Imperative Knowledge “How to” knowledge X = 2 G = 1 X/G = 2 To find an approximation of square root of x: Make a guess G Improve the guess by averaging G and x/G Keep improving the guess until it is good enough X = 2 G = 1 X/G = 2 G = ½ (1 + 2) = 1.5 X/G = 4/3 G = ½ (3/2 + 4/3) = 17/12 = 1.416666 X/G = 24/17 G = ½ (17/12 + 24/17) = 577/408 = 1.4142156 4/7/2019 6.001 SICP

“How to” knowledge Why “how to” knowledge? Could just store tons of “what is” information (e.g. tables of logs from the 1970’s) Much more useful to capture “how to” knowledge – a series of steps to be followed to deduce a particular value (e.g. the mechanism underlying the log function on a calculator) a recipe Called a procedure Actual evolution of steps inside machine for a particular version of the problem – called a process Distinguish between procedure (recipe) and process (actual computation) 4/7/2019 6.001 SICP

Describing “How to” knowledge Need a language for describing processes: Vocabulary – basic primitives Rules for writing compound expressions – syntax Rules for assigning meaning to constructs – semantics Rules for capturing process of evaluation – procedures 4/7/2019 6.001 SICP

Using procedures to control complexity Goals: Create a set of primitive elements– simple data and procedures Create a set of rules for combining elements of language Create a set of rules for abstracting elements – treat complex things as primitives Why? -- Can create complex procedures while suppressing details Target: Create complex systems while maintaining: robustness, efficiency, extensibility and flexibility. 4/7/2019 6.001 SICP

Key Ideas in 6.001 Management of complexity: Procedure and data abstraction Conventional interfaces & programming paradigms manifest typing streams object oriented programming Metalinguistic abstraction: creating new languages evaluators 4/7/2019 6.001 SICP

6.001: Structure and Interpretation of Computer Programs Today The structure of 6.001 The content of 6.001 Beginning to Scheme 4/7/2019 6.001 SICP

Computation as a metaphor Capture descriptions of computational processes Use abstractly to design solutions to complex problems Use a language to describe processes Primitives Means of combination Means of abstraction 4/7/2019 6.001 SICP

Primitives for representing basic information – what is the right level? Numbers Atomic element – single binary variable Takes on one of two values (0 or 1) Represents one bit (binary digit) of information Grouping together Sequence of bits Byte – 8 bits Word – 16, 32 or 48 bits Characters Sequence of bits that encode a character EBCDIC ASCII 4/7/2019 6.001 SICP

Binary numbers and operations Unsigned integers N-1 N-2 1 Bit place i 1 2^3 + 2^1 + 2^0 = 8 + 2 + 1 = 11 2^(n-1) 2^(n-2) 2^1 2^0 Weight b where is 0 or1 4/7/2019 6.001 SICP

Binary numbers and operations Addition 0 0 1 1 +0 +1 +0 +1 0 1 1 10 10101 21 111 7 11100 28 4/7/2019 6.001 SICP

Binary numbers and operations Can extend to signed integers (reserve one bit to denote positive versus negative) Can extend to character encodings Representation is too low level! Need abstractions!! 4/7/2019 6.001 SICP

Assuming a basic level of abstraction We assume that our language provides us with a basic set of data elements Numbers Characters Booleans And with a basic set of operations on these primitive elements Can then focus on using these basic elements to construct more complex processes 4/7/2019 6.001 SICP

Our language for 6.001 Scheme Dialect of Lisp Invented in 1975 Some Completely Hairy Environment Mechanism for Evaluation Scheme Invented in 1975 Dialect of Lisp Invented in 1959 Lots of Insidious, Silly Parentheses 4/7/2019 6.001 SICP

Rules for describing processes in Scheme Legal expressions have rules for constructing from simpler pieces (Almost) every expression has a value, which is “returned” when an expression is “evaluated”. Every value has a type. Syntax Semantics 4/7/2019 6.001 SICP

Kinds of Language Constructs Primitives Means of combination Means of abstraction 4/7/2019 6.001 SICP

Language elements – primitives Self-evaluating primitives – value of expression is just object itself Numbers: 29, -35, 1.34, 1.2e5 Strings: “this is a string” “ this is another string with %&^ and 34” Booleans: #t, #f 4/7/2019 6.001 SICP

Language elements – primitives Built-in procedures to manipulate primitive objects Numbers: +, -, *, /, >, <, >=, <=, = Strings: string-length, string=? Booleans: boolean/and, boolean/or, not 4/7/2019 6.001 SICP

Language elements – primitives Names for built-in procedures +, *, -, /, =, … What is the value of such an expression? +  [#procedure …] Evaluate by looking up value associated with name in a special table 4/7/2019 6.001 SICP

Language elements – combinations How do we create expressions using these procedures? (+ 2 3) Close paren Open paren Expression whose value is a procedure Other expressions Evaluate by getting values of sub-expressions, then applying operator to values of arguments 4/7/2019 6.001 SICP

Language elements - combinations Can use nested combinations – just apply rules recursively (+ (* 2 3) 4) 10 (* (+ 3 4) (- 8 2)) 42 4/7/2019 6.001 SICP

Language elements -- abstractions In order to abstract an expression, need way to give it a name (define score 23) This is a special form Does not evaluate second expression Rather, it pairs name with value of the third expression Return value is unspecified 4/7/2019 6.001 SICP

Language elements -- abstractions To get the value of a name, just look up pairing in environment score  23 Note that we already did this for +, *, … (define total (+ 12 13)) (* 100 (/ score total))  92 This creates a loop in our system, can create a complex thing, name it, treat it as primitive 4/7/2019 6.001 SICP

Scheme Basics Rules for evaluation If self-evaluating, return value. If a name, return value associated with name in environment. If a special form, do something special. If a combination, then a. Evaluate all of the subexpressions of combination (in any order) b. apply the operator to the values of the operands (arguments) and return result 4/7/2019 6.001 SICP

Read-Eval-Print (+ 3 (* 4 5)) READ EVAL 23 Visible world Internal representation for expression EVAL Value of expression PRINT Execution world Visible world 23 4/7/2019 6.001 SICP

A new idea: two worlds visible world execution world printed representation of value 23 23 expression print eval self-rule 23 value 4/7/2019 6.001 SICP

A new idea: two worlds visible world execution world printed representation of value visible world execution world expression 3.14 23 eval self-rule print pi print eval name-rule 3.14 value value name-rule: look up value of name in current environment 4/7/2019 6.001 SICP

Define special form visible world execution world define-rule: evaluate 2nd operand only name in 1st operand position is bound to that value overall value of the define expression is undefined visible world execution world name value print scheme versions differ (define pi 3.14) "pi --> 3.14" eval define-rule undefined pi 3.14 4/7/2019 6.001 SICP

Mathematical operators are just names (+ 3 5)  8 (define fred +)  undef (fred 4 6)  10 How to explain this? Explanation + is just a name + is bound to a value which is a procedure line 2 binds the name fred to that same value 4/7/2019 6.001 SICP

Primitive procedures are just values visible world execution world #[compiled-procedure 8 #x583363] printed representation of value * expression print eval name-rule A primitive proc that multiplies its arguments value 4/7/2019 6.001 SICP

Summary Primitive data types Primitive procedures Means of combination Means of abstraction – names 4/7/2019 6.001 SICP