Lambda - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Lambda

Description:

Lambda. Or, Do functions really need to have a name? Last time we said (define f ... The inner name in the new rule doesn't really matter. We could have: (define f ... – PowerPoint PPT presentation

Number of Views:86
Avg rating:3.0/5.0
Slides: 12
Provided by: csR7
Learn more at: http://www.cs.rice.edu
Category:
Tags: lambda | really

less

Transcript and Presenter's Notes

Title: Lambda


1
Lambda
  • Or,
  • Do functions really need to have a name?

2
Last time we said
  • (define f
  • (local ((define (f x) body )
  • f))
  • (define (f x) body )
  • Note Inner function only used once

3
Concrete example
  • (define f
  • (local ((define (g x) ( 1 x))
  • g))
  • by renaming
  • (define f
  • (local ((define (f x) ( 1 x))
  • f))
  • by our new rule
  • (define (f x) ( 1 x))

4
Observation I
  • The inner name in the new rule doesn't really
    matter. We could have
  • (define f
  • (local ((define (lalala x) body )
  • lalala))
  • and still, it would equal
  • (define (f x) body )

5
Observation II
  • This pattern comes up quite a bit. It would be
    nice to have less to write
  • (define f
  • (lambda (x) body ))
  • and still, it would equal
  • (define (f x) body )

6
So, on one hand
  • Lambda is a shorthand
  • (lambda (x y z) body )
  • by definition
  • (local ((define (lalala x y z) body ))
  • lalala)

7
On the other hand
  • Our property is now much easier to express
  • (define f
  • (lambda (x) body ))
  • by the property from last class
  • (define (f x) body )

8
More on Hand Evaluation
  • What are expressions like this supposed to do?
  • ((lambda (x) exp_1 ) value_2 )
  • ? exp_1 xvalue_2
  • Example
  • ((lambda (x) ( 1 x)) ( 3 4))
  • ? ( 1 x) x( 3 4) ( 1 ( 3 4))
  • ? ( 1 7) ? 8
  • ((lambda (x) ( 1 x)) ( 3 4))
  • ((lambda (x) ( 1 x)) 7)
  • ( 1 x) x7 ( 1 7) ? 8

9
More on Hand Evaluation
  • What are expressions like this supposed to do?
  • ((lambda (x) exp_1 ) exp_2 )
  • Example
  • ((lambda (x) ( 1 x)) ( 3 4))
  • ?
  • ?

10
More on Hand Evaluation
  • Can we write down a general rule?
  • ((lambda (x) exp_1 ) exp_2 )
  • ? ??? exp_1 ??? exp_2 ???
  • Is it really correct?

11
Lambda calculus
  • Very nice model of "programs"
  • Alonzo Church, 1930's
  • ltexpgt ltvargt
  • (lambda (x) ltexpgt)
  • (ltexpgt ltexpgt)
  • Originally (and still) used to formalize logic
  • LISP, 1960's. Basis for Scheme
  • Gordon Plotkin, 1975. Basis for ML, Haskell
Write a Comment
User Comments (0)
About PowerShow.com