Lecture 2: Schreme David Evans

Slides:



Advertisements
Similar presentations
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 26: Proving Uncomputability Visualization.
Advertisements

1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
David Evans CS200: Computer Science University of Virginia Computer Science Class 30: Models of Computation.
Class 39: Universality cs1120 Fall 2009 David Evans University of Virginia.
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.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
David Evans CS200: Computer Science University of Virginia Computer Science Class 31: Universal Turing Machines.
Functional Programing Referencing material from Programming Language Pragmatics – Third Edition – by Michael L. Scott Andy Balaam (Youtube.com/user/ajbalaam)
Cs3102: Theory of Computation Class 18: Proving Undecidability Spring 2010 University of Virginia David Evans.
Class 37: Computability in Theory and Practice cs1120 Fall 2011 David Evans 21 November 2011 cs1120 Fall 2011 David Evans 21 November 2011.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
CSE 311 Foundations of Computing I Lecture 26 Computability: Turing machines, Undecidability of the Halting Problem Spring
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 2: Formal Systems and Languages MU!
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 36: Modeling Computing.
David Evans Class 15: P vs. NP (Smiley Puzzles and Curing Cancer) CS150: Computer Science University of Virginia Computer.
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
Lecture 3: Rules of Evaluation CS150: Computer Science
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
David Evans CS200: Computer Science University of Virginia Computer Science Class 26: Halting Problem It is plain at any.
Programming Language Paradigms ITSK2314 Lecture 3.
Fall 2013 Lecture 27: Turing machines and decidability CSE 311: Foundations of Computing.
Functional Programming
(Thunking about Thunks)
Functional Programming
Lecture 4: Metacircles Eval Apply David Evans
Zuse’s Plankalkül – 1945 Never implemented Problems Zuse Solved
Lecture 6: Lambda Calculus
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation
Lecture 4: Evaluation Rules Recursion CS200: Computer Science
Class 22: Inheritance CS150: Computer Science University of Virginia
Class 27: Universal Turing Machines CS150: Computer Science
Class 30: Models of Computation CS200: Computer Science
CSE 311 Foundations of Computing I
Automata and Languages What do these have in common?
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Lecture 37: A Universal Computer
Lambda Calculus Revisited
Class 19: Think Globally, Mutate Locally CS150: Computer Science
Busch Complexity Lectures: Undecidable Problems (unsolvable problems)
Lecture 2: Formal Systems and Languages MU! CS200: Computer Science
Prof. Jason Eisner MWF 3-4pm (sometimes 3-4:15)
Class 36: The Meaning of Truth CS200: Computer Science
Lecture 25: Metalinguistics > (meval '((lambda (x) (* x x)) 4)
Lecture 24: Metalinguistics CS200: Computer Science
Lecture 21: Crosscutting Aspect-Oriented Programming Background
Lecture 10: The Return of Paco Background just got here last week
Programming.
Variables, Lists, and Objects
Class 33: Making Recursion M.C. Escher, Ascending and Descending
Lecture 10: Using Object-Oriented Languages
6.001 SICP Variations on a Scheme
Class 24: Computability Halting Problems Hockey Team Logo
Lecture 19: Proof-Carrying Code Background just got here last week
Class 31: Universal Turing Machines CS200: Computer Science
Lecture 10: Fixed Points ad Infinitum M.C. Escher, Moebius Ants
Class 34: Models of Computation CS200: Computer Science
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
David Evans Lecture 19: ||ism I don’t think we have found the right programming concepts for parallel computers yet.
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Lecture 12: Minding your Ps & Qs:
CSE S. Tanimoto Lambda Calculus
Class 26: Modeling Computing CS150: Computer Science
Lecture 15: Crazy Eddie and the Fixed Points Background
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Group 4: Song Li, Ying Lu, Hexin Wang, and Michael Walker May 1, 2000
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Lecture 23: Computability CS200: Computer Science
Presentation transcript:

Lecture 2: Schreme David Evans Available within the network will be functions and services to which you subscribe on a regular basis and others that you call for when you need them. In the former group will be investment guidance, tax counseling, selective dissemination of information in your field of specialization, announcement of cultural, sport, and entertainment events that fit your interests, etc. In the latter group will be dictionaries, encyclopedias, indexes, catalogues, editing programs, teaching programs, testing programs, programming systems, data bases, and – most important – communication, display, and modeling programs. All these will be – at some late date in the history of networking - systematized and coherent; you will be able to get along in one basic language up to the point at which you choose a specialized language for its power or terseness. Background just got here last week finished degree at MIT week before Philosophy of advising students don’t come to grad school to implement someone else’s idea can get paid more to do that in industry learn to be a researcher important part of that is deciding what problems and ideas are worth spending time on grad students should have their own project looking for students who can come up with their own ideas for research will take good students interested in things I’m interested in – systems, programming languages & compilers, security rest of talk – give you a flavor of the kinds of things I am interested in meant to give you ideas (hopefully even inspiration!) but not meant to suggest what you should work on J. C. R. Licklider and Robert W. Taylor, The Computer as a Communication Device, April 1968 CS655: Programming Languages University of Virginia Computer Science David Evans http://www.cs.virginia.edu/~evans

Menu Registration Survey Results Universal Languages My Answers Universal Languages Stuff Languages are Made Of Scheme Infinitely many different functions 23 Jan 2001 CS 655: Lecture 2

Favorite Programming Languages C 41/3 C++ 21/3 Java 21/3 Perl 1 My answer: For getting work done: C (with LCLint) For reading other people’s code: CLU For fun: FL, Scheme 23 Jan 2001 CS 655: Lecture 2

Most Hated PL COBOL 2 Perl 2 (also favorite) Java 1 Lisp 1 None 4 My answer: For asthetics, readability: APL For teaching intro CS courses: C++ For writing big systems: Lisp 23 Jan 2001 CS 655: Lecture 2

Experience of Students in this Class C++ (38 years), C (36), BASIC (29), Pascal (21), various assemblies (12), Java (9), Perl (5), FORTRAN (4), Python (2½), Ada (2), Lisp dialects (1½), COBOL (1), Smalltalk (½) Algol60 direct successors = 106 Pre-Algol languages = 46 Completely object-oriented languages = ½ But O-O doesn’t really mean anything Pure functional languages = 0 Python is close (but has globals and state) 23 Jan 2001 CS 655: Lecture 2

Partner Preference Assigned Randomly 4 Choose Your Own 4 No Clear Preference 2 23 Jan 2001 CS 655: Lecture 2

Can class go over time? No problem 10 Problem 0 One said, “but if I am bored and you keep me there I will be really annoyed and glare at you”. 23 Jan 2001 CS 655: Lecture 2

Technical Questions Used higher-order procedures: No: 4 A little: 3 Yes: 3 Wrote function that returned infinitely many possible different functions No: 10 (some used tables of function pointers) Fixed points: find x where f(x) = x Gets really interesting when x is a function! 23 Jan 2001 CS 655: Lecture 2

Why taking this class? 23 Jan 2001 CS 655: Lecture 2

Next: Computability and Universal Programming Languages 23 Jan 2001 CS 655: Lecture 2

Computability A programming language is universal if it can express all computable functions. A function is “computable” if there exists an algorithm that computes it. An algorithm is a computational procedure that takes a finite number of steps. What’s a computational procedure? 23 Jan 2001 CS 655: Lecture 2

Turing Machine Tape head can: Read symbol from tape Write symbol on tape Move tape left or right one square Change its own state (finite state machine)   Infinitely long tape 23 Jan 2001 CS 655: Lecture 2

Universal Turing Machine Universal Turing Machine is a Turing machine that can simulate any other Turing machine Input (start state on tape) contains both a description of a Turing Machine (i.e., a program) and its input Yes, there really are such things Hopefully you will see it in CS660 23 Jan 2001 CS 655: Lecture 2

Computability A computational procedure is something that can be described by a Turing Machine A language is universal if it can express: all algorithms = all finite computational procedures = all Turing machines = one Universal Turing Machine 23 Jan 2001 CS 655: Lecture 2

Not everything is computable Halting Problem – will a Turing Machine halt? Suppose we could compute it: (define (halts? P) ...) returns true if P halts, false otherwise. 23 Jan 2001 CS 655: Lecture 2

(define contradicts-halts (if (halts? contradict-halts) (loop-forever) Based on Duane Boning, http://sicp.ai.mit.edu/Fall-1999/lectures/lec25/6001-12-9-99-computability.ppt (define contradicts-halts (if (halts? contradict-halts) (loop-forever) #t)) If contradict-halts halts, it loops forever; If contradict-halts doesn’t halt, value is true. Yikes! halts? must not exisit! Note: this is not a proof. (proof in 650) Perhaps it is if that doesn’t exist. 23 Jan 2001 CS 655: Lecture 2

Is a language universal? How can we prove a language is universal? Produce a program that implements a Universal Turing Machine in the language (usually this is pretty easy) How can we prove a language is not universal? Prove that it cannot express the function of some Turing Machine 23 Jan 2001 CS 655: Lecture 2

Elements of Language 23 Jan 2001 CS 655: Lecture 2

Elements of Language (Almost?) All Languages have: English: Primitives Means of combination English: Primitives = words (?) e.g., “Floccipoccinihilipilification” (the act of rendering useless) e.g., Sentence = Subject Verb Object 23 Jan 2001 CS 655: Lecture 2

Means of Combination Allow us to say infinitely many things with a finite number of primitives In English, words aren’t really primitives (linguists call the primitives morphemes – smallest units of meaning) Means of Combination work on word parts: Antifloccipoccinihilipilification (the act of not rendering useless) Antifloccipoccinihilipilificationator (one who does the act of not rendering useless) 23 Jan 2001 CS 655: Lecture 2

Describing Means of Combination BNF (Backus Naur Form) <non-terminal> ::= <replacement> Terminals are primitives in the language (don’t appear on left-hand side.) Alternatives <non-terminal> ::= <replacement1> | <replacement2> short for: <non-terminal> ::= <replacement2> 23 Jan 2001 CS 655: Lecture 2

BNF John Backus Normal  Peter Naur (Donald Knuth’s suggestion) FORTRAN (manual described syntax using verbose English, not a formal notation) Member of Algol60 committee, introduced formal notation for syntax Influential in development of functional languages: FP, FL, Turing Lecture Normal  Peter Naur (Donald Knuth’s suggestion) Chair of Algol60 committee 23 Jan 2001 CS 655: Lecture 2

BNF Example NP ::= Noun VP ::= Verb Noun ::= Dave | Scheme Sentence ::= NP VP NP ::= Noun VP ::= Verb Noun ::= Dave | Scheme Verb ::= rocks | sucks Could this language be a universal programming language? 23 Jan 2001 CS 655: Lecture 2

BNF Example NP ::= Noun VP ::= Verb | Noun and NP Sentence ::= NP VP NP ::= Noun VP ::= Verb Noun ::= Dave | Scheme Verb ::= rocks | sucks | Noun and NP We can express infinitely many things with a tiny language! With the right meaning function, this could be a universal programming language. 23 Jan 2001 CS 655: Lecture 2

Scheme 23 Jan 2001 CS 655: Lecture 2

Scheme Like all (?) languages, Scheme has: Primitives Means of Combination Also, like all (?) reasonable programming languages it has: Means of Abstraction 23 Jan 2001 CS 655: Lecture 2

Mini-Scheme Primitives Examples Numerals 0 655 3.52 -58 Functions + Constants #f #t You know what the primitives mean. Numeral  Number 655  655 Function  Function +  math addition 23 Jan 2001 CS 655: Lecture 2

Means of Combination Application Expression ::= (Expression) Expression ::= (Expression Expression) Expression ::= (Expression Expression Expression) ... Expression ::= (Expression*) (+ 655 58) (* (+ 0 (+ 2 2)) 6) “Evaluate all the expressions, then apply the first expression (a procedure) to all the other values.” 23 Jan 2001 CS 655: Lecture 2

Means of Combination Special Forms (if Expression1 Expression2 Expression3 ) If the value of Expression1 is #f, the value of the if is the value of Expression3. Otherwise, it is the value of Expression2 . A few others, but they are not necessary (note: neither is if!) 23 Jan 2001 CS 655: Lecture 2

Means of Combination Make Procedure Expression ::= (lambda (Variable) Expression) “A procedure that when applied to value, evaluates to Expression with all instances of Variable substituted for by value.” Note: “substitution” is complicated. 23 Jan 2001 CS 655: Lecture 2

Mini-Scheme Expression ::= (Expression*) | (lambda (Variable) Expression) | (if Expression1 Expression2 Expression3 ) | numeral | #f | #t | + Variable ::= identifier Is mini-scheme a Universal Programming Language? (Left as challenge problem.) 23 Jan 2001 CS 655: Lecture 2

Means of Abstraction (define Variable Expression) Substitute Expression for Variable. (define two 2) 2 (+ two two) 4 23 Jan 2001 CS 655: Lecture 2

Abstracting Procedures (define square (lambda (x) (* x x)) proc (square two) 4 (define (Variable1 Variable2) Expression) is just an abbreviation for: (define Variable1 (lambda (Variable2) Expression) 23 Jan 2001 CS 655: Lecture 2

Multiple Arguments (define (Variable1 Variable2 Variable3) Expression) is just an abbreviation for: (define Variable1 (lambda (Variable2) (lambda (Variable3) Expression))) This is called “currying”. 23 Jan 2001 CS 655: Lecture 2

Currying (define add (lambda (x) (lambda (y) (+ x y)))) (add 5) proc 7 23 Jan 2001 CS 655: Lecture 2

add add is a procedure that returns infinitely many different procedures! (define add (lambda (x) (lambda (y) (+ x y)))) 23 Jan 2001 CS 655: Lecture 2

triadd (define triadd (lambda (x) (lambda (y) (lambda (z) (+ x y z))))) triadd is a procedure that returns infinitely many different procedures, each of which is a procedure that returns infinitely many different procedures! So, after today your answer to survey question: “Yes, infinitely many!” 23 Jan 2001 CS 655: Lecture 2

Charge Problem Set 1 out today Its not long but may be hard, start it soon Question 0 think about: Do we really need define? What scheme expressions do not have values? Next time: Higher-Order Functions, Intro to Metacircular Evaluators 23 Jan 2001 CS 655: Lecture 2