Announcements Colloquium today: CSCI 334: thesis presentations in TCL 202, 2:30pm Principles of Programming Languages Lecture 3: PL Fundamentals (they’ve all worked really hard— Instructor: Dan Barowy show support for your fellow CS Ephs!) Announcements Outline • Next quiz is on Tuesday • Short discussion of Pirsig • Quizzes cover previous week’s • Stack drawing material • Lab 2 hint • Therefore, the quiz will be on… • PL foundations • … the lambda calculus.
technical Tough coding experiences communication 9 8 low-level big questions knowledge (C) 7 high-level (theoretical) 6 knowledge LISP & functional 5 MIDTERM programming 4 language architecture 3 2 F# 1 object 0 CS432 CS343 Research/internship CS338 CS136 Personal project Coding in general CS237 orientation (C++) Activity char * #include <stdio.h> h o r c r u x \0 void add(int *x, int *y, int *z) { *z = *x + *y; 0 1 2 3 4 5 6 7 2 } char ** int main() { int x = 1; char * h h h h h h h h h h int y = 3; 1 int z; o o o o o o o o o o add(&x, &y, &z); r r r r r r r r r r 3 return z; } c c c c c c c c c c s main r r r r r r r r r r arr Diagram the stack and variables when the program is at the three points. u u u u u u u u u u Call stack x x x x x x x x x x \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
Activity The Dream Write a function swap that swaps the values of x and y . “I thought again about my early plan of a new language or writing-system of reason, which could serve as a communication tool for all Start by drawing a picture of what you want. different nations... If we had such an universal tool, we could discuss the problems of the #include <stdio.h> metaphysical or the questions of ethics in the same way as the problems and questions of void swap(int *a, int *b) { mathematics or geometry. That was my aim: ??? } Every misunderstanding should be nothing more Wilhelm Gottfried Leibniz than a miscalculation (...), easily corrected by the int main() { grammatical laws of that new language. Thus, in int x = 1; the case of a controversial discussion, two int y = 2; philosophers could sit down at a table and just swap(&x, &y); printf("x = %d, y = %d\n", x, y); calculating, like two mathematicians, they could return 0; say, 'Let us check it up …’” } The Dream Wilhelm Gottfried Leibniz “What is the answer to the ultimate question of life, the universe, and “stepped reckoner” everything?
What is computable? What is computable? • Why do we care? • Hilbert: Is there an algorithm • f(x) = x + 1 that can decide whether a • We can clearly do this with logical statement is valid? pencil and paper. • “Entscheidungsproblem” • ∫ 6x dx (literally “decision problem”) • Also computable, in a di ff erent manner. • Leibniz thought so! • We care because the computable functions can be done on a computer. Lambda calculus grammar Lambda calculus • Invented by Alonzo Church in <expr> ::= <var> order to solve | <abs> the Entscheidungsproblem. | <app> • Short answer to Hilbert’s <var> ::= x question: no. <abs> ::= λ <var>.<expr> • Proof: No algorithm can decide equivalence of <app> ::= <expr><expr> two arbitrary λ -calculus expressions. • By implication: no algorithm can determine whether an arbitrary logical statement is valid.
What is a variable? What is an abstraction? <var> ::= x <abs> ::= λ <var>.<expr> It’s just a value. It’s a function de fi nition def foo(x): <expr> What is an application? Evaluation: You know how C does it <app> ::= <expr><expr> #include <stdio.h> It’s a “function call” void hello() { printf(“Hello world!\n”); hello } foo(2) <expr><expr> int main() { main hello(); return 0; } Call stack function argument
Recap & Next Class Evaluation: Lambda calculus is like algebra Today we covered: ( λ x.x)x More boxes and arrows Evaluation consists of simplifying an PL Foundations expression using text substitution. Only two simpli fi cation rules: Next class: α -reduction Foundations β -reduction Project idea: http://worrydream.com/AlligatorEggs/
Recommend
More recommend