1 Topic #3: Lambda CSE 413, Autumn 2007 Programming Languages.

Slides:



Advertisements
Similar presentations
CSE 202 – Formal Languages and Automata Theory 1 REGULAR LANGUAGE.
Advertisements

1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Chapter 6: MuPAD Objects II Sequence, List, Set, Function MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
PPL Lecture 3 Slides by Dr. Daniel Deutch, based on lecture notes by Prof. Mira Balaban.
1 Functional programming Languages And a brief introduction to Lisp and Scheme.
1 Scheme Scheme is a functional language. Scheme is based on lambda calculus. lambda abstraction = function definition In Scheme, a function is defined.
מבוא מורחב - שיעור 2 1 Lecture 2 - Substitution Model (continued) - Recursion - Block structure and scope (if time permits)
6.001 SICP SICP – September Types and HOPs Trevor Darrell 32-D512 Office Hour: W web page:
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
SchemeCOP Introduction to Scheme. SchemeCOP Scheme Meta-language for coding interpreters –“ clean ” semantics Scheme = LISP + ALGOL –simple.
Lesson 5.2 (PART 2) FUNCTION NOTATION.
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.
14-October-2002cse Lists © 2002 University of Washington1 Lists CSE 413, Autumn 2002 Programming Languages
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
1 The Evaluator. 2 Compiler vs. Interpreter Command Processing Unit The Computer Program in Low Level Machine Language Program in High Level Language.
18-October-2002cse Symbols © 2002 University of Washington1 Symbols CSE 413, Autumn 2002 Programming Languages
CSI 3125, Subprograms, page 1 Subprograms General concepts Parameter passing Functions Subprograms as parameters.
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
1 Lecture 14: Assignment and the Environment Model (EM)
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Spring 2008Programming Development Techniques 1 Topic 5.5 Higher Order Procedures (This goes back and picks up section 1.3 and then sections in Chapter.
From Lambda Calculus to LISP Functional Programming Academic Year Alessandro Cimatti
9-October-2002cse MoreLambda © 2002 University of Washington1 More Lambda CSE 413, Autumn 2002 Programming Languages
Forms Writing your own procedures CS 480/680 – Comparative Languages.
Chapter 1: Real Numbers and Equations Section 1.3: Variables and Expressions.
CSE 202 – Formal Languages and Automata Theory 1 REGULAR EXPRESSION.
4 March 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Notes Over 1.2 Express the power in words. Then write the meaning. Word Meaning.
Remainder and Factor Theorems
Operational Semantics of Scheme
CS314 – Section 5 Recitation 10
Functional Programming
Introduction to Programming
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation
Carlos Varela Rennselaer Polytechnic Institute September 5, 2017
Limits of Functions.
زبان بدن Body Language.
Higher-Order Procedures
Essential Questions How do we use the Factor Theorem to determine factors of a polynomial? How do we factor the sum and difference of two cubes.
Functional Programming
CS220 Programming Principles
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.
6.001 SICP Environment model
Scheme: Basic Functionality
Introduction to Programming
Explicit Application of Procedures, and Explicit Evaluation
Lisp, Then and Now.
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.
6.001 SICP Environment model
6.001 SICP Variations on a Scheme
Defining Macros in Lisp
Notes Over 1.2.
Flow of Control.
Lecture 2 מבוא מורחב.
FUNCTION NOTATION.
6.001 SICP Environment model
Lecture 3: Rules of Evaluation CS200: Computer Science
CSE S. Tanimoto Lambda Calculus
equivalent expression
Introduction to the Lab
Lecture 2 מבוא מורחב.
Relations/Sequences Objective: Students will learn how to identify if a relation is a function. They will also be able to create a variable expression.
Introduction to Programming
Rules of evaluation The value of a number is itself.
Defining Macros in Scheme
Subprograms General concepts Parameter passing Functions
Carlos Varela Rennselaer Polytechnic Institute September 6, 2019
Presentation transcript:

1 Topic #3: Lambda CSE 413, Autumn 2007 Programming Languages

2 Scheme procedures are "first class" Procedures can be manipulated like the other data types in Scheme »A variable can have a value that is a procedure »A procedure value can be passed as an argument to another procedure »A procedure value can be returned as the result of another procedure »A procedure value can be included in a data structure

3 define and name (define (area-of-disk r) (* pi (* r r)))

4 Special form: lambda (lambda (  formals  )  body  ) A lambda expression evaluates to a procedure »it evaluates to a procedure that will later be applied to some arguments producing a result  formals  »formal argument list that the procedure expects  body  »sequence of one or more expressions »the value of the last expression is the value returned when the procedure is actually called

5 "Define and name" with lambda (define area-of-disk (lambda (r) (* pi (* r r))))

6 "Define and use" with lambda ((lambda (r) (* pi r r)) 1)

7 Separating procedures from names We can treat procedures as regular data items, just like numbers »and procedures are more powerful because they express behavior, not just state We can write procedures that operate on other procedures - applicative programming

8 define min-fx-gx (define (min-fx-gx f g x) (min (f x) (g x)))

9 apply min-fx-gx (min-fx-gx square cube 2) ; (min 4 8) => 4 (min-fx-gx square cube -2) ; (min 4 -8) => -8 (min-fx-gx identity cube 2) ; (min 2 8) => 2 (min-fx-gx identity cube (/ 1 2)) ; (min 1/2 1/8) => 1/8 (define (identity x) x) (define (square x) (* x x)) (define (cube x) (* x x x)) (define (min-fx-gx f g x) (min (f x) (g x)))

10 apply s-fx-gx (s-fx-gx min square cube 2) ; => (min 4 8) = 4 (s-fx-gx min square cube -2) ; => (min 4 -8) = -8 (s-fx-gx + square cube 2) ; => (+ 2 8) = 12 (s-fx-gx - cube square 3) ; => (- 27 9) = 18 ; define a procedure ‘s-fx-gx’ that takes: ; s - a combining function that expects two numeric arguments ; and returns a single numeric value ; f, g - two functions that take a single numeric argument and ; return a single numeric value f(x) or g(x) ; x - the point at which to evaluate f(x) and g(x) ; s-fx-gx returns s(f(x),g(x))

11 Exercises ; 4. (CHALLENGE) Define a procedure ‘apply-n-times’ that takes: ; f - a function that take a single numeric argument and ; return a single numeric value f(x) ; n – the number of times to apply the function f ; ‘apply-n-times’ returns a function that accepts one numeric ; argument ‘x’ and the result of applying f() to ‘x’, ‘n’ times ; Example: ( (apply-n-times square 2) 3)  81