CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 16: Let and Lambda.

Slides:



Advertisements
Similar presentations
Months of the year December January November October February
Advertisements

Chubaka Producciones Presenta :.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 17: HOF and Tick-Tack-Toe.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 18: HOF.
Slide 1. Slide 2 Administrivia Mid-semester survey this week (Thur/Fri) –you NEED to do this. Interviews should be starting in a few weeks. I apologize.
2012 JANUARY Sun Mon Tue Wed Thu Fri Sat
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 19: HOF Problems.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 6: Mini-Project Prep.
January 2012 Monday Tuesday Wednesday Thursday Friday Sat/ Sun / /8 14/15 21/22 28/
/3024/ SUN MON TUE WED THU FRI SAT JANUARY 2011 February 2011 SMTWTFS
P Pathophysiology Calendar. SundayMondayTuesdayWednesdayThursdayFridaySaturday January 2012.
Slide 1 CS3 Fall 2005 Lecture 9: Higher Order Functions.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 15: Procedures as Arguments.
Chicas, este calendario si es pa' nosotras !!!!!.
2007 Monthly Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.

What day is today? What`s the date?. Sunday Monday Tuesday Wednesday Thursday Friday Saturday What day is today?
WORD JUMBLE. Months of the year Word in jumbled form e r r f b u y a Word in jumbled form e r r f b u y a february Click for the answer Next Question.
September 2008 SundayMondayTuesdayWednesdayThursdayFridaySaturday
DATE POWER 2 INCOME JANUARY 100member X 25.00P2, FEBRUARY 200member X 25.00P5, MARCH 400member X 25.00P10, APRIL 800member.
2011 Calendar Important Dates/Events/Homework. SunSatFriThursWedTuesMon January
TEMPORAL VISUALIZATION OF DATA FROM THE FRENCH SENTINEL NETWORK.
July 2007 SundayMondayTuesdayWednesdayThursdayFridaySaturday
CS61A Lecture Colleen Lewis. Clicker Test Are you coming to the potluck on Thursday on the 4 th floor of Soda from 6:30pm-9:00? A)Yes B)Maybe.
Dictation practice 2nd Form Ms. Micaela-Ms. Verónica.
JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER
JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER
McDonald’s Kalender 2009.
McDonald’s Kalender 2009.
13-block rotation schedule
1   1.テキストの入れ替え テキストを自由に入れ替えることができます。 フチなし全面印刷がおすすめです。 印刷のポイント.
JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER
Logo Calendar – January 2012 TO DO LIST 01/04/2012 Example TO DO LIST
January MON TUE WED THU FRI SAT SUN
January MON TUE WED THU FRI SAT SUN
ANNUAL CALENDAR HOLIDAYS JANUARY FEBRUARY MARCH APRIL MAY JUNE
HOLIDAYS ANNUAL CALENDAR JANUARY FEBRUARY MARCH APRIL MAY JUNE
McDonald’s Kalender 2009.
January Sun Mon Tue Wed Thu Fri Sat
January MON TUE WED THU FRI SAT SUN
January MON TUE WED THU FRI SAT SUN
Problem Gambling Clicks to Opgr.org
2300 (11PM) September 21 Blue line is meridian..
HOLIDAYS ANNUAL CALENDAR JANUARY FEBRUARY MARCH APRIL MAY JUNE
S M T W F S M T W F
January MON TUE WED THU FRI SAT SUN
McDonald’s calendar 2007.
1 - January - Sun Mon The Wed Thu Fri Sat
2 0 X X s c h e d u l e 1 MON TUE WED THU JANUARY 20XX FRI SAT SUN MEMO.
Teacher name August phone: Enter text here.
January MON TUE WED THU FRI SAT SUN
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
Calendar.
January MON TUE WED THU FRI SAT SUN
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
February 2007 Note: Source:.
January MON TUE WED THU FRI SAT SUN
MONTHS OF THE YEAR January February April March June May July August
S M T W F S M T W F
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
McDonald’s calendar 2007.
1 January 2018 Sun Mon Tue Wed Thu Fri Sat
1 January MON TUE WED THU FRI SAT SUN MEMO 2 February MON TUE WED THU FRI SAT SUN.
Habitat Changes and Fish Migration
2015 January February March April May June July August September
Habitat Changes and Fish Migration
S M T W F S M T W F
S M T W F S M T W F
1 January MON TUE WED THU FRI SAT SUN MEMO 2 February MON TUE WED THU FRI SAT SUN.
Presentation transcript:

CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 16: Let and Lambda

Today Homework Mon: Mini-project 2 due Thursday at 11:59 pm let lambda

Treating functions as things “define” associates a name with a value The usual form associates a name with a object that is a function (define (square x) (* x x)) (define (pi) ) You can define other objects, though: (define *pi* ) (define *month-names* ‘(january february march april may june july august september october november december))

"Global variables" Functions are "global", in that they can be used anywhere: (define (pi) ) (define (circle-area radius) (* (pi) radius radius)) A "global" variable, similarly, can be used anywhere: (define *pi* ) (define (circle-area radius) (* *pi* radius radius))

Consider two forms of “month-name”: (define (month-name1 date) (first date)) (define month-name2 first) Are these the same?

Let ( let ( ( variable1 value1 ) ;;definition 1 ( variable2 value2 ) ;;definition 2 ) statement1 ;;body statement2... )

Using let to define temporary variables let lets you define variables within a procedure: (define (scramble-523 wd) (let ((second (first (bf wd))) (third (first (bf (bf wd)))) (fifth (item 5 wd)) ) (word fifth second third) ) ) (scramble-523 'meaty)  yea

Let ( let ( ( variable1 value1 ) ;;definition 1 ( variable2 value2 ) ;;definition 2 ) statement1 ;;body statement2... )

Three ways to define a variable 1. In a procedure call (e.g., the variable proc ): (define (doit proc value) ;; proc is a procedure here… (proc value)) 2. As a global variable (define *alphabet* '(a b c d e … )) (define *month-name* '(january … )) 3. With let

Which pi? (define (square x) (let ((pi 3.1)) (* pi pi))) (define (square pi) (let ((pi 3.1)) (* pi pi))) (define pi ) (define (square pi) (let ((pi 3.14)) (* pi pi))) (square 1)  9.61

Which pi? (define pi ) (define (square x) (* pi pi)) (define pi ) (define (square pi) (* pi pi)) (square 1)  (square 1)  1

Anonymous functions: using lambda

the lambda form " lambda " is a special form that returns a function: (lambda (arg1 arg2 …) statements ) (lambda (x) (* x x))      a procedure that takes one argument and multiplies it by itself

Using lambda with define These are the same: (define (square x) (* x x)) (define square (lambda (x) (* x x)) )

Using lambda with define These are VERY DIFFERENT: (define (adder-1 y) (lambda (x) (+ x 1))) (define adder-2 (lambda (x) (+ x 1)))

Accumulate (define (my-accum1 accum-proc num-sent) (if (= (count num-sent) 1) (first num-sent) (accum-proc (first num-sent) (my-accum1 accum-proc (bf num-sent)) ) ) > (my-accum1 - ‘245)

(my-accum1 - ‘( )) (- 4 (my-accum1 - ‘( 4 5 )) (my-accum1 - ‘( 5 )) > (my-accum1 - ‘245) (- 2 5 (define (my-accum1 accum-proc num-sent) (if (= (count num-sent) 1) (first num-sent) (accum-proc (first num-sent) (my-accum1 accum-proc (bf num-sent)) ) )  (- 2 (- 4 5))  3