Introduction to lambda calculus Part 3


 Valerie Copeland
 2 years ago
 Views:
Transcription
1 Introduction to lambda calculus Part 3 AnttiJuhani Kaijanaho Untyped lambda calculus... 2 Typed lambda calculi In an untyped lambda calculus extended with integers, it is required that any value, whether a function or a number, must be treatable as a function or as a number. Thus, in an untyped language, both 5(λx x) and 5+(λx x) must have a specified result (even if it is the undefined value ). In most contexts, however, such usage is a mistake. There are a number of ways to add types to lambda calculus. It rarely makes any sense to do this to the pure lambda calculus, so all my examples will have some extensions to the pure language. For a history of the concept of a type, see Kaijanaho (2015, Section 2.4.2). 2.1 Dynamically typed lambda calculus with integers Here is an abstract syntax for a lambda calculus with integers. Minor changes made afterward. Last changed :58:49+02:00. 1
2 c, d Const x, y, z Var t, u Term t, u ::= x c t u λx t t + u t u t u t / u For the denotational semantics, dynamic typing means that it must define what terms have type errors, and distinguish between type errors and other kinds of undefinedness. In this language, there are two principal kinds of type errors: calling a numeric value and performing arithmetic on functions. Thus, we must be able to distinguish between numbers and functions at the value level. We need two domains for the denotational semantics: Num is the domain of integers. Fun is the domain of suitable functions D D. Saying that these are domains means that each has an undefined value called bottom. Specifically, there is the undefined integer Num and the undefined function Fun (for which Fun (x) = D holds for all x D). Further, domain theory means that Fun contains only some functions D D, not all of them, but there will be sufficiently many for the purposes of garden variety denotational semantics. We will further assume that all common numeric operations such as addition are defined in Num with the supposition that if any operand is Num, the result is also Num. In other words, the operations are strict in all parameters. We will also assume the existence of a function V : Const Num that takes each literal constant to its numeric value. Now, let us assume that no number is a function and no function is an error, and no error is a number. Then we can define D = Num Fun wrong, D } We need an ultimate bottom D as distinct from the bottoms of each domain to indicate that we do not even know the domain the value belongs to. The value wrong indicates a type error. 2
3 The denotational semantics is now defined by the following function: E: Term (Var D) D E x σ = σ x (1) E c σ = V c (2) wrong if f Fun or a = wrong E tu σ = (3) f(a) otherwise where f = E t σ and a = E u σ E λx t σ = f, where f : D D E t + u = wrong a + b f(z) = E t (σ[x := z) if a Num or b Num otherwise where a = E t σ and b = E u σ wrong if a Num or b Num E t u = a b otherwise where a = E t σ and b = E u σ wrong if a Num or b Num E t u = a b otherwise where a = E t σ and b = E u σ wrong if a Num or b Num E t / u = Num if a Num and b = 0 otherwise a b where a = E t σ and b = E u σ Example 11 The denotation of (λx x) + 5 is wrong under (5), since E λx x σ is a function, not a numeric value. Reduction uses the standard α and β conversion rules, plus the following arithmetical rules: c + d a v where v = V c + V d (9) c d a v where v = V c V d (10) c d a v where v = V c V d (11) c / d a v (4) (5) (6) (7) (8) where v = V c, if defined (12) V d 3
4 An arithmetical redex is any term where two numeric constants are operands to an arithmetical operator. For the purposes of reduction order, arithmetical redexes count as redexes. Example 12 Let us compute (λx x+x)(3 3). First, use the normal order: Then the applicative order: (λx x + x)(3 3) β (3 3) + (3 3) a 9 + (3 3) a a 18 (λx x + x)(3 3) a (λx x + x)9 β a 18 Exercise 6 Compute (λx (λy (λx x + y))(2 x)) 3 using reductions. 2.2 A model of Lisp The essence of Lisp (see e. g. McCarthy 1960, 1981; McCarthy et al. 1966; Seibel 2005) is a dynamically typed lambda calculus with several extensions: There are atoms, which are akin to constants; every atom has a corresponding atom value which is distinct from every other value. There are at least two atoms: T and NIL. Any two values can be put into an ordered pair, which is itself a value. There is a guarded term for evaluating a term only if the value of another term is not NIL There is a way to combine guarded terms so that it is possible to choose between multiple terms. There is a mechanism for defining values by recursive computation. A real Lisp will also support assignable variables, side effects such as I/O and inplace modification of data structures, metaprogramming using macros, and many other features omitted from this model. 4
5 Thus, we arrive at the following abstract syntax: a, b, c Atom x, y, z Var t, u Term t, u ::= x a t u λx t µx t recursively defined value t, u ordered pair g g GuardedTerm g ::= t u term guarded by a condition g g 1 g 2 combined guarded term Before defining its semantics or behavior formally, I will explain informally some of the newer constructs. First, µx t (called a label expression in traditional Lisp and a fixpoint term by theorists) is intended to describe recursion, so the value of µx t is the value of t evaluated with x standing for the value of t. Second, a guarded term (t 1 u 1 t 2 u 2 t n u n ) tries each t i in order until one of them evaluates to something other than NIL, in which case the value of the whole guarded term is the value of the corresponding u i ; if all t i evaluate to NIL, then the whole guarded term evaluates to NIL. There is an idiom to chain pairs to form a linked list terminated by the atom NIL, so a, b, c, NIL is a linked list of a, b, and c. It is so ubiquitous an idiom that we will use the following syntactic sugar: [t 1, t 2,..., t n means the same as t 1, t 2,... t n, NIL.... A Lisp program presumes some standard atoms and variables (standing for functions). The standard variables are expected to be defined in the global environment. The most important ones are atoms representing numbers, and the following variables standing for functions: EQ p presumes that p evaluates to a list of atoms; it returns T if they are all the same atom and NIL otherwise. ATOM p returns T if p is an list consisting of a single atom and NIL otherwise. CONS p presumes that p evaluates to a list of two elements and returns a pair of those elements. 5
6 CAR p presumes that p evaluates to a pair and returns its left component. CDR p presumes that p evaluates to a pair and returns its right component. ADD l presumes that l evaluates to a list of atoms representing numbers and returns their sum. SUB l presumes that l evaluates to a list of atoms representing numbers and subtracts from the first all the rest, and returns the result. MUL l presumes that l evaluates to a list of atoms representing numbers and returns their product. DIV l presumes that l envaluates a list of atoms representing numbers and divides the first by the second, the result by the third, and so on, and returns the final result. Example 13 We may write the factorial function as follows: µf λx (EQ[x, 0 1 T MUL[x, f(sub[x, 1)) For a denotational semantics, we need a domain D that contains all the atoms in Atom, including T and NIL, enough functions D D (which will all belong to the subset Fun), enough pairs from D D (which will all belong to the subset Pair), the type error value wrong, and the undefined value. (Enough in this case means that D must satisfy the requirements of domain theory.) Further, there shall be a domain D f = D fail}, which is used to control selection among guarded terms. The denotational semantics is defined by the following two functions: E: Term (Var D) D E x σ = σ x (13) E a σ = a (14) 6
7 E tu σ = wrong f(v) if f = or v = else if f Fun or v = wrong otherwise where f = E t σ and v = E u σ E λx t σ = f where f : D D f(z) = E t (σ[x := z) (15) (16) E µx t σ = v where v = E t (σ[x := v) (17) if v = or w = E t, u σ = wrong if v = wrong or w = wrong (18) (v, w) otherwise where v = E t σ and w = E u σ NIL if v = fail E g σ = v otherwise where v = G g σ (19) G: Term (Var D) D f if v = wrong if v = wrong G t u σ = fail if v = NIL E u σ otherwise where v = E t σ G g 2 σ if v = fail G g 1 g 2 σ = v otherwise where v = G g 1 σ (20) (21) The set of free variables and variable substitution are largely similarly computed as with ordinary lambda calculus, except that µx t binds x the same way as λx t does. Exercise 7 Define F V : (Term GuardedTerm) P (Var) and variable substitution (t[x := u) formally for this model of Lisp. Note that you should avoid variable capture even though this was not traditionally done in Lisp. Reduction rules are a bit more complicated. In the rules below, v stands for a term on which no more reductions can be performed. We start with 7
8 the basic rule of β reduction, restricted to applicative order (requiring the reduction of the argument first): 1 (λx t)v t[x := v (22) Since the x in a recursion term stands for the term itself, we can simply move it inward to simulate one step of recursion. µx t t[x := µx t (23) The reduction rules for guarded terms are suggested by their informal semantics: (NIL u g) g (24) (v u g) u if v NIL (25) (NIL u) NIL (26) (v u) u if t NIL (27) Lisp s traditional reduction order is weak applicative order reduction from left to right: tu t u if t t (28) vu vu if u u (29) t, u t, u if t t (30) v, u v, u if u u (31) (t u g) (t u g) if t t (32) (t u) (t u) if t t (33) Finally, we would need rules for the standard functions, but I will omit them here (you may use them informally to make reduction steps once the arguments are fully reduced). Example 14 Let us compute (µf λx (EQ[x, 0 1 T MUL[x, f(sub[x, 1))) 1 using the reduction rules: ( µf λx ( )) 1 I will no longer subscript the arrow with the type of the reduction. 1 8
9 λx 1 T MUL x, µf λx (SUB [x, 1) by (23), (28) EQ [1, 0 1 T MUL 1, µf λx (SUB [1, 1) by (22) NIL 1 T MUL 1, µf λx (SUB [1, 1) by EQ, (32) ( [ ( ( )) ) T MUL 1, µf λx (SUB [1, 1) by (24) [ ( ( )) MUL 1, µf λx (SUB [1, 1) by (27) MUL 1, λx (SUB [1, 1) T MUL x, µf λx (SUB [x, 1) by (23), (28), (31),(29) MUL 1, λx T MUL x, µf λx (SUB [x, 1) by SUB, (29), (31),(29) EQ [0, 0 1 MUL 1, T MUL 0, µf λx (SUB [0, 1) by (22), (31),(29) T 1 MUL 1, T MUL 0, µf λx (SUB [0, 1) by EQ, (32), (31),(29) MUL [1, 1 by (25), (31),(29) 1 by MUL There is, however, a further interesting aspect of Lisp. There is a traditional concrete syntax for Lisp data, called Sexpressions. The basic idea is that a list is written by listing its elements one by one inside parentheses with nothing (except whitespace if needed) in between; atoms are written as they are. Thus, the list [a, b, [c, d, e is written in Sexpression format as (a b (c d e)). Further, a pair is written by listing its two elements in parentheses with a period in between: a, b is written as (a. b). More generally, a sequence of pairs that would be a list except that it terminates in something other than NIL is written like a list except that the terminating thing is separated from the rest of the list with a period; thus a, b, c, d is written as (a b c. d) (this is called a improper list). Atoms are written as themselves. Now, there is a standard way to represent Lisp terms as lisp data, expressed as Sexpressions (must be applied recursively): 9
10 My notation Standard Sexpression form t[u 1,..., u n (t u 1 u n ) λx t (LAMBDA x t) µx t (LABEL x t) a (QUOTE a) t, u (QUOTE (t. u)) [t 1,..., t n (QUOTE (t 1 t n ) (t 1 u 1 t n u n ) (COND (t 1 u 1 ) (t n u n )) Further, abstractions are usually written (LAMBDA (X Y Z) ( )) or sometimes even (LAMBDA (X Y. Z) ( )), which allows the Sexpression programmer to give names to some or all of the elements of an argument list given to the function. My notation does not support that. Since the QUOTEs get very cumbersome very fast, there is a common abbreviation: we can write instead of (QUOTE ). Quoting of an atom that does not look like a variable (such as a numeric constant) is not necessary. Similarly, do not nest QUOTEs: (QUOTE a (b c) d) is the nested list [a, [b, c, d In classical Lisp, Sexpressions were written in upper case letters. Nowadays lowercase letters are more commmonly used, and Sexpressions are usually treated as case insensitively (so LAMBDA and lambda are the same atom). Example 15 Here is the factorial function of Example 13 in Sexpression form: (label f (lambda (x) (cond ((eq x 0) 1) ( t (mul x (f (sub x 1))))))) Given all this, we can write a Lisp function that reads a Lisp term and an environment represesnted as Lisp data, and performs the reduction. It is not even particularly hard. This function, called eval, is the first ever definitional interpreter written. Practical Lisps usually provide a readevalprint loop (repl): a command line interface where terms written as Sexpressions are input by the user, then evaluated by the Lisp implementation, and finally the value of the expression is printed. Lisps also provide various ways to modify the toplevel environment which contains the standard functions for example (define 10
11 f (lambda )) in Scheme. This is the way programs are also written they are essentially scripts of repl sessions, at least in simple cases. Exercise 8 Write, using either my abstract syntax notation or Sexpression notation, a Lisp function that 1. counts the number of elements in a list 2. computes the average of numbers in a list 3. reverses a list You may also use the concrete syntax of a Lisp dialect implementation (but do not use its library funtions beyond the equivalents of the functions listed in this document). In that case, specify which dialect and implementation you used. References Kaijanaho, AnttiJuhani (2015). EvidenceBased Programming Language Design. A Philosophical and Methodological Exploration. Jyväskylä Studies in Computing 222. University of Jyväskylä. url: ISBN: McCarthy, John (1960). Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I. In: Communications of the ACM 3.4, pp doi: / (1981). History of LISP. In: History of programming languages I. New York, NY, USA: ACM, pp isbn: doi: / McCarthy, John et al. (1966). LISP 1.5 Programmer s Manual. 2nd ed. MIT Press. Seibel, Peter (2005). Practical Common Lisp. Apress. url: gigamonkeys.com/book/. 11
Functional Programming
Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used
More information11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT
Functional programming FP Foundations, Scheme (2 In Text: Chapter 15 LISP: John McCarthy 1958 MIT List Processing => Symbolic Manipulation First functional programming language Every version after the
More informationPrinciples of Programming Languages 2017W, Functional Programming
Principles of Programming Languages 2017W, Functional Programming Assignment 3: Lisp Machine (16 points) Lisp is a language based on the lambda calculus with strict execution semantics and dynamic typing.
More informationOrganization of Programming Languages CS3200/5200N. Lecture 11
Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages
More informationLambda Calculus. Variables and Functions. cs3723 1
Lambda Calculus Variables and Functions cs3723 1 Lambda Calculus Mathematical system for functions Computation with functions Captures essence of variable binding Function parameters and substitution Can
More informationScheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7
Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are firstclass values E.g., functions
More informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 16: Functional Programming Zheng (Eddy Zhang Rutgers University April 2, 2018 Review: Computation Paradigms Functional: Composition of operations on data.
More informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs Sexpressions cons, car, cdr Defining functions readevalprint loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More information1.3. Conditional expressions To express case distinctions like
Introduction Much of the theory developed in the underlying course Logic II can be implemented in a proof assistant. In the present setting this is interesting, since we can then machine extract from a
More informationCS 6110 S14 Lecture 1 Introduction 24 January 2014
CS 6110 S14 Lecture 1 Introduction 24 January 2014 1 Introduction What is a program? Is it just something that tells the computer what to do? Yes, but there is much more to it than that. The basic expressions
More informationFP Foundations, Scheme
FP Foundations, Scheme In Text: Chapter 15 1 Functional Programming  Prelude We have been discussing imperative languages C/C++, Java, Fortran, Pascal etc. are imperative languages Imperative languages
More informationPure (Untyped) λcalculus. Andrey Kruglyak, 2010
Pure (Untyped) λcalculus Andrey Kruglyak, 2010 1 Pure (untyped) λcalculus An example of a simple formal language Invented by Alonzo Church (1936) Used as a core language (a calculus capturing the essential
More informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs Sexpressions cons, car, cdr Defining functions readevalprint loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More informationIntroduction to Scheme
How do you describe them Introduction to Scheme Gul Agha CS 421 Fall 2006 A language is described by specifying its syntax and semantics Syntax: The rules for writing programs. We will use Context Free
More informationProgramming Languages
Programming Languages Lambda Calculus and Scheme CSCIGA.2110003 Fall 2011 λcalculus invented by Alonzo Church in 1932 as a model of computation basis for functional languages (e.g., Lisp, Scheme, ML,
More informationFunctional Programming. Big Picture. Design of Programming Languages
Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics
More informationDocumentation for LISP in BASIC
Documentation for LISP in BASIC The software and the documentation are both Copyright 2008 Arthur NunesHarwitt LISP in BASIC is a LISP interpreter for a Schemelike dialect of LISP, which happens to have
More informationScheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax
Scheme Tutorial Introduction Scheme is an imperative language with a functional core. The functional core is based on the lambda calculus. In this chapter only the functional core and some simple I/O is
More informationFunctional Programming. Pure Functional Programming
Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its subexpressions (if any).
More informationIntroduction to LISP. York University Department of Computer Science and Engineering. York University CSE V.
Introduction to LISP York University Department of Computer Science and Engineering York University CSE 3401 V. Movahedi 11_LISP 1 Introduction to LISP Evaluation and arguments S expressions Lists Numbers
More informationOne of a number of approaches to a mathematical challenge at the time (1930): Constructibility
λ Calculus Church s λ Calculus: Brief History One of a number of approaches to a mathematical challenge at the time (1930): Constructibility (What does it mean for an object, e.g. a natural number, to
More informationFunctional Programming Languages (FPL)
Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional
More informationRecursive Functions of Symbolic Expressions and Their Application, Part I
Recursive Functions of Symbolic Expressions and Their Application, Part I JOHN MCCARTHY Review: Amit Kirschenbaum Seminar in Programming Languages Recursive Functions of Symbolic Expressions and Their
More informationProject 2: Scheme Interpreter
Project 2: Scheme Interpreter CSC 4101, Fall 2017 Due: 12 November 2017 For this project, you will implement a simple Scheme interpreter in C++ or Java. Your interpreter should be able to handle the same
More informationScheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.
Scheme: Data CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu
More informationCOP4020 Programming Languages. Functional Programming Prof. Robert van Engelen
COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts
More informationFall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives
CS 6A Scheme Fall 207 Discussion 7: October 25, 207 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write
More informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
More informationSummer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define
CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationSymbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89
Symbolic Programming Symbols: +, , 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic expressions. Symbolic manipulation: you do it all the
More informationPolymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy
0602552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 201617 School of Computer Science c Uday Reddy201617 Handout 6: Polymorphic Type Systems 1. Polymorphic
More informationSpring 2018 Discussion 7: March 21, Introduction. 2 Primitives
CS 61A Scheme Spring 2018 Discussion 7: March 21, 2018 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme
More informationTopic III. LISP : functions, recursion, and lists References: Chapter 3 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.
Topic III LISP : functions, recursion, and lists References: Chapter 3 of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapters 5( 4.5) and 13( 1) of Programming languages: Design and
More informationCSCC24 Functional Programming Scheme Part 2
CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisplike Languages
More informationFUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE,
FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE, 2011 Jan Janoušek MIFLP Evropský sociální fond Praha & EU: Investujeme do vaší budoucnosti L I S P  Introduction L I S P
More informationFunctional Languages. Hwansoo Han
Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm
More informationScheme: Expressions & Procedures
Scheme: Expressions & Procedures CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, March 31, 2017 Glenn G. Chappell Department of Computer Science University
More informationHandout 10: Imperative programs and the Lambda Calculus
0602552 Princ of Progr Languages (and Extended ) The University of Birmingham Spring Semester 201617 School of Computer Science c Uday Reddy201617 Handout 10: Imperative programs and the Lambda Calculus
More informationChapter 15. Functional Programming Languages
Chapter 15 Functional Programming Languages Copyright 2009 AddisonWesley. All rights reserved. 12 Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages
More informationCSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures
CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures Dan Grossman Fall 2014 Hi! I m not Hal J I love this stuff and have taught
More informationFall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives
CS 6A Scheme Fall 208 Discussion 8: October 24, 208 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write
More informationComp 411 Principles of Programming Languages Lecture 7 Metainterpreters. Corky Cartwright January 26, 2018
Comp 411 Principles of Programming Languages Lecture 7 Metainterpreters Corky Cartwright January 26, 2018 Denotational Semantics The primary alternative to syntactic semantics is denotational semantics.
More informationAnnouncements. The current topic: Scheme. Review: BST functions. Review: Representing trees in Scheme. Reminder: Lab 2 is due on Monday at 10:30 am.
The current topic: Scheme! Introduction! Objectoriented programming: Python Functional programming: Scheme! Introduction! Numeric operators, REPL, quotes, functions, conditionals! Function examples, helper
More informationHarvard School of Engineering and Applied Sciences CS 152: Programming Languages. Lambda calculus
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Tuesday, February 19, 2013 The lambda calculus (or λcalculus) was introduced by Alonzo Church and Stephen Cole Kleene in
More informationSCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017
SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationSCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015
SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More information15 Unification and Embedded Languages in Lisp
15 Unification and Embedded Languages in Lisp Chapter Objectives Chapter Contents Pattern matching in Lisp: Database examples Full unification as required for Predicate Calculus problem solving Needed
More informationFunctional programming in LISP
Programming Languages Week 4 Functional programming in LISP College of Information Science and Engineering Ritsumeikan University review of part 3 enumeration of dictionaries you receive a sequence of
More informationSOFTWARE ARCHITECTURE 6. LISP
1 SOFTWARE ARCHITECTURE 6. LISP Tatsuya Hagino hagino@sfc.keio.ac.jp slides URL https://vu5.sfc.keio.ac.jp/sa/ 2 Compiler vs Interpreter Compiler Translate programs into machine languages Compilers are
More informationLambda Calculus. Gunnar Gotshalks LC1
Lambda Calculus LC1 l Calculus History Developed by Alonzo Church during 1930 s40 s One fundamental goal was to describe what can be computed. Full definition of lcalculus is equivalent in power to
More informationCPS 506 Comparative Programming Languages. Programming Language Paradigm
CPS 506 Comparative Programming Languages Functional Programming Language Paradigm Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming
More informationSymbolic Reasoning. Dr. Neil T. Dantam. Spring CSCI561, Colorado School of Mines. Dantam (Mines CSCI561) Symbolic Reasoning Spring / 86
Symbolic Reasoning Dr. Neil T. Dantam CSCI561, Colorado School of Mines Spring 2019 Dantam (Mines CSCI561) Symbolic Reasoning Spring 2019 1 / 86 Introduction Definition: Symbolic Reasoning Inference
More informationImperative, OO and Functional Languages A C program is
Imperative, OO and Functional Languages A C program is a web of assignment statements, interconnected by control constructs which describe the time sequence in which they are to be executed. In Java programming,
More informationFundamentals and lambda calculus
Fundamentals and lambda calculus Again: JavaScript functions JavaScript functions are firstclass Syntax is a bit ugly/terse when you want to use functions as values; recall block scoping: (function ()
More informationPrinciples of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003
Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003 CS 314, LS, LTM: Functional Programming 1 Scheme A program is an expression to be evaluated (in
More informationLanguages with Contexts II: An Applicative Language
Languages with Contexts II: An Applicative Language Wolfgang Schreiner Research Institute for Symbolic Computation (RISCLinz) Johannes Kepler University, A4040 Linz, Austria Wolfgang.Schreiner@risc.unilinz.ac.at
More informationLisp. Versions of LISP
Lisp Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks is based on Common Lisp Scheme is one of the major
More informationλ calculus Function application Untyped λcalculus  Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods
Course 2D1453, 200607 Advanced Formal Methods Lecture 2: Lambda calculus Mads Dam KTH/CSC Some material from B. Pierce: TAPL + some from G. Klein, NICTA Alonzo Church, 19031995 ChurchTuring thesis First
More informationINF4820: Algorithms for Artificial Intelligence and Natural Language Processing. Common Lisp Fundamentals
INF4820: Algorithms for Artificial Intelligence and Natural Language Processing Common Lisp Fundamentals Stephan Oepen & Murhaf Fares Language Technology Group (LTG) August 30, 2017 Last Week: What is
More informationType Systems Winter Semester 2006
Type Systems Winter Semester 2006 Week 4 November 8 November 15, 2006  version 1.1 The Lambda Calculus The lambdacalculus If our previous language of arithmetic expressions was the simplest nontrivial
More informationCITS3211 FUNCTIONAL PROGRAMMING
CITS3211 FUNCTIONAL PROGRAMMING 9. The λ calculus Summary: This lecture introduces the λ calculus. The λ calculus is the theoretical model underlying the semantics and implementation of functional programming
More informationPROGRAMMING IN HASKELL. Chapter 2  First Steps
PROGRAMMING IN HASKELL Chapter 2  First Steps 0 The Hugs System Hugs is an implementation of Haskell 98, and is the most widely used Haskell system; The interactive nature of Hugs makes it well suited
More informationFundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP)
Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology
More informationC311 Lab #3 Representation Independence: Representation Independent Interpreters
C311 Lab #3 Representation Independence: Representation Independent Interpreters Will Byrd webyrd@indiana.edu February 5, 2005 (based on Professor Friedman s lecture on January 29, 2004) 1 Introduction
More informationReasoning About Programs Panagiotis Manolios
Reasoning About Programs Panagiotis Manolios Northeastern University March 22, 2012 Version: 58 Copyright c 2012 by Panagiotis Manolios All rights reserved. We hereby grant permission for this publication
More informationThe University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS
The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER 2012 2013 MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS Time allowed TWO hours Candidates may complete the front
More informationFunctional programming with Common Lisp
Functional programming with Common Lisp Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 81 Expressions and functions
More informationLambda Calculus. Lecture 4 CS /26/10
Lambda Calculus Lecture 4 CS 565 10/26/10 Pure (Untyped) Lambda Calculus The only value is a function Variables denote functions Functions always take functions as arguments Functions always return functions
More informationLambda Calculus see notes on Lambda Calculus
Lambda Calculus see notes on Lambda Calculus Shakil M. Khan adapted from Gunnar Gotshalks recap so far: Lisp data structures basic Lisp programming bound/free variables, scope of variables Lisp symbols,
More informationLambda Calculus and Extensions as Foundation of Functional Programming
Lambda Calculus and Extensions as Foundation of Functional Programming David Sabel and Manfred SchmidtSchauß 29. September 2015 Lehrerbildungsforum Informatik Last update: 30. September 2015 Overview
More informationLECTURE 16. Functional Programming
LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative
More informationFrom the λcalculus to Functional Programming Drew McDermott Posted
From the λcalculus to Functional Programming Drew McDermott drew.mcdermott@yale.edu 20150928 Posted 20151024 The λcalculus was intended from its inception as a model of computation. It was used by
More informationModern Programming Languages. Lecture LISP Programming Language An Introduction
Modern Programming Languages Lecture 1821 LISP Programming Language An Introduction 72 Functional Programming Paradigm and LISP Functional programming is a style of programming that emphasizes the evaluation
More informationNotes on Higher Order Programming in Scheme. by Alexander Stepanov
by Alexander Stepanov August 1986 INTRODUCTION Why Scheme? Because it allows us to deal with: 1. Data Abstraction  it allows us to implement ADT (abstact data types) in a very special way. The issue of
More informationLecture Notes: Control Flow Analysis for Functional Languages
Lecture Notes: Control Flow Analysis for Functional Languages 17355/17665: Program Analysis (Spring 2017) Jonathan Aldrich aldrich@cs.cmu.edu 1 Analysis of Functional Programs Analyzing functional programs
More informationCSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings
More informationLambda Calculus and Lambda notation in Lisp II. Based on Prof. Gotshalks notes on Lambda Calculus and Chapter 9 in Wilensky.
λ Calculus Basis Lambda Calculus and Lambda notation in Lisp II Based on Prof. Gotshalks notes on Lambda Calculus and Chapter 9 in Wilensky Mathematical theory for anonymous functions» functions that have
More informationCommon LISPIntroduction
Common LISPIntroduction 1. The primary data structure in LISP is called the sexpression (symbolic expression). There are two basic types of sexpressions: atoms and lists. 2. The LISP language is normally
More informationCOP4020 Programming Assignment 1  Spring 2011
COP4020 Programming Assignment 1  Spring 2011 In this programming assignment we design and implement a small imperative programming language MicroPL. To execute MircoPL code we translate the code to
More informationConcepts of programming languages
Concepts of programming languages Lecture 7 Wouter Swierstra 1 Last time Relating evaluation and types How to handle variable binding in embedded languages? 2 DSLs: approaches A standalone DSL typically
More informationProgramming Systems in Artificial Intelligence Functional Programming
Click to add Text Programming Systems in Artificial Intelligence Functional Programming Siegfried Nijssen 8/03/16 Discover thediscover world at the Leiden world University at Leiden University Overview
More informationNote that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.
CS 6110 S18 Lecture 8 Structural Operational Semantics and IMP Today we introduce a very simple imperative language, IMP, along with two systems of rules for evaluation called smallstep and bigstep semantics.
More informationHarvard School of Engineering and Applied Sciences CS 152: Programming Languages
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 24 Thursday, April 19, 2018 1 Errorpropagating semantics For the last few weeks, we have been studying type systems.
More informationCIS 500 Software Foundations Fall September 25
CIS 500 Software Foundations Fall 2006 September 25 The Lambda Calculus The lambdacalculus If our previous language of arithmetic expressions was the simplest nontrivial programming language, then the
More informationALISP interpreter in Awk
ALISP interpreter in Awk Roger Rohrbach 1592 Union St., #94 San Francisco, CA 94123 January 3, 1989 ABSTRACT This note describes a simple interpreter for the LISP programming language, written in awk.
More informationFormal Semantics. Chapter TwentyThree Modern Programming Languages, 2nd ed. 1
Formal Semantics Chapter TwentyThree Modern Programming Languages, 2nd ed. 1 Formal Semantics At the beginning of the book we saw formal definitions of syntax with BNF And how to make a BNF that generates
More information6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson
6.184 Lecture 4 Interpretation Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 1 Interpretation Parts of an interpreter Arithmetic calculator
More informationThe Untyped Lambda Calculus
Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationComp 311: Sample Midterm Examination
Comp 311: Sample Midterm Examination October 29, 2007 Name: Id #: Instructions 1. The examination is closed book. If you forget the name for a Scheme operation, make up a name for it and write a brief
More informationCSC 533: Programming Languages. Spring 2015
CSC 533: Programming Languages Spring 2015 Functional programming LISP & Scheme Sexpressions: atoms, lists functional expressions, evaluation, define primitive functions: arithmetic, predicate, symbolic,
More informationLambda Calculus LC1
Lambda Calculus LC1 λ Calculus History1 Developed by Alonzo Church during 1930 s40 s One fundamental goal was to describe what can be computed. Full definition of λcalculus is equivalent in power
More informationFunctional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur
Functional Programming and λ Calculus Amey Karkare Dept of CSE, IIT Kanpur 0 Software Development Challenges Growing size and complexity of modern computer programs Complicated architectures Massively
More informationScheme in Scheme: The Metacircular Evaluator Eval and Apply
Scheme in Scheme: The Metacircular Evaluator Eval and Apply CS21b: Structure and Interpretation of Computer Programs Brandeis University Spring Term, 2015 The metacircular evaluator is A rendition of Scheme,
More information11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations
Outline FP Foundations, Scheme In Text: Chapter 15 Mathematical foundations Functional programming λcalculus LISP Scheme 2 Imperative Languages We have been discussing imperative languages C/C++, Java,
More informationFundamentals and lambda calculus. Deian Stefan (adopted from my & Edward Yang s CSE242 slides)
Fundamentals and lambda calculus Deian Stefan (adopted from my & Edward Yang s CSE242 slides) Logistics Assignments: Programming assignment 1 is out Homework 1 will be released tomorrow night Podcasting:
More informationThe PCAT Programming Language Reference Manual
The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language
More informationCMSC 330: Organization of Programming Languages. Operational Semantics
CMSC 330: Organization of Programming Languages Operational Semantics Notes about Project 4, Parts 1 & 2 Still due today (7/2) Will not be graded until 7/11 (along with Part 3) You are strongly encouraged
More informationRecursive Definitions, Fixed Points and the Combinator
Recursive Definitions, Fixed Points and the Combinator Dr. Greg Lavender Department of Computer Sciences University of Texas at Austin Recursive SelfReference Recursive selfreference occurs regularly
More informationCS 360 Programming Languages Interpreters
CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like
More informationWeek 4: Functional Programming
CS320 Principles of Programming Languages Week 4: Functional Programming Jingke Li Portland State University Fall 2017 PSU CS320 Fall 17 Week 4: Functional Programming 1/ 66 Topic List for this Unit Functional
More information