cs3l: introduction to symbolic programming

13
CS3L: Introduction to Symbolic Programming Summer 2008 Colleen Lewis [email protected] Lecture 18: HOF

Upload: brynne-holder

Post on 31-Dec-2015

21 views

Category:

Documents


0 download

DESCRIPTION

CS3L: Introduction to Symbolic Programming. Summer 2008Colleen Lewis [email protected]. Lecture 18: HOF. Announcements. Midterm two Tuesday July 29 th This one will probably be harder than the first Colleen will be out of town Thurs-Monday Homework - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS3L:  Introduction to Symbolic Programming

CS3L: Introduction to

Symbolic Programming

Summer 2008 Colleen Lewis

[email protected]

Lecture 18:HOF

Page 2: CS3L:  Introduction to Symbolic Programming

Announcements

Midterm two Tuesday July 29th

This one will probably be harder than the first Colleen will be out of town Thurs-Monday Homework

Miniproject 3 starts Today! Due Friday July 25th

Page 3: CS3L:  Introduction to Symbolic Programming

Today

lambda every keep Accumulate Global variables Tick-tack-toe (ttt)

Page 4: CS3L:  Introduction to Symbolic Programming

lambda

(lambda (arg1 arg2 …) body… )(define (square x) (* x x))

(define square (lambda (x)(* x x))THESE ARE THE SAME!

(define (square y) (lambda (x) (* x x)))(define square (lambda (y) (lambda (x) (* x x))) These are the same! Called: ((square 1) 4)16

Page 5: CS3L:  Introduction to Symbolic Programming

every

(every procedure sent)procedure

a procedure that takes in one argument a procedure that returns a word or a sentence

sent a sentence with 0 or more words a word with 0 or more letters

Page 6: CS3L:  Introduction to Symbolic Programming

every example(define (change-1st-char char sent)

(every

(lambda (wd)(word char (bf wd)))

sent))

(lambda (‘let) (word ‘x ‘let)

‘xet

(lambda (‘get) (word ‘x ‘get)

‘xet

(lambda (‘eat) (word ‘x ‘eat)

‘xat

(se

> (change-1st-char ‘x‘(eat get let))

Page 7: CS3L:  Introduction to Symbolic Programming

keep

(keep procedure sent)procedure

a procedure that takes in one argument a procedure that returns #t or #f

sent a sentence with 0 or more words a word with 0 or more letters

Page 8: CS3L:  Introduction to Symbolic Programming

keep example(define (keep-equal? wd sent)

(keep

(lambda (one-wd)

(equal? wd one-wd))

sent))

(lambda (‘con) (equal? ‘cat ‘con))

‘()

(lambda (‘bar)(equal? ‘cat ‘cat))

‘cat

(lambda (‘car) (equal? ‘cat ‘car))

‘()

(se

> (keep-equal? ‘cat ‘(car cat con))

Page 9: CS3L:  Introduction to Symbolic Programming

accumulate

(accumulate procedure sent)procedure

a procedure that takes in two arguments a procedure that combines things together

sent a sentence with 1 or more words a word with 1 or more letters

Page 10: CS3L:  Introduction to Symbolic Programming

accumulate(accumulate (lambda () …) ‘(cat dog hat tag sag)

‘tag ‘sag‘?

‘hat

‘??

‘dog

‘???

‘cat

‘????

Page 11: CS3L:  Introduction to Symbolic Programming

How to use global variables

(define (pi) 3.1415)

(define circumference

(lambda (diameter)

(* diameter (pi))))

(define pi 3.1415)

(define circumference

(lambda (diameter)

(* diameter pi)))

Page 12: CS3L:  Introduction to Symbolic Programming

X | | ---+---+--- O | O | X ---+---+--- | |

"X _ _" "O O X" "_ _ _"

"X _ _ O O X _ _ _"

The board

Page 13: CS3L:  Introduction to Symbolic Programming

X | | ---+---+--- O | O | X ---+---+--- | |

"X _ _ O O X _ _ _"

Triples (another representation of a board)

( )x23 oox 789 xo7 2o8 3x9 xo9 3o7