This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: R ECURSION , E VALUATION , F UNCTIONS 2 GEORGE WANG [email protected] Department of Electrical Engineering and Computer Sciences University of California, Berkeley June 22, 2010 1 Functions from Last Lecture 1.1 CS Illustrated Words and sentences: http://csillustrated.berkeley.edu/PDFs/word-sentence-selectors. pdf 1.2 Procedures We Learned first ; Returns the first element of a sentence or a word butfirst ;Returns the rest of the sentence or a word bf ;Abbreviation for butfirst last ;returns the last element of a sentence or a word butlast ; returns all but the last element bl ; abbreviation for butlast word ;takes 2 things and combines them into a single word ’ ; Quotes a word, so prevents evaluation equal? ; tests if two things are equal if ;Syntax: (if (PREDICATE?) TRUE-EXPRESSION FALSE-EXPRESSION) cond ;Syntax: (cond ((PRED-1?) (DO-1)) ((PRED-2?) (DO-2)) (else (DO-3))) member? ; (member? ’a ’hello) ⇒ #f (member? ’a ’halo) ⇒ #t 2 Recursion: At the end of lecture, we talked about this: ;;;;; In file cs61a/lectures/1.1/pigl.scm (define (pigl wd) (if (pl-done? wd) (word wd ’ay) 1 (pigl (word (bf wd) (first wd))))) (define (pl-done? wd) (vowel? (first wd))) (define (vowel? letter) (member? letter ’(a e i o u))) When we trace it, we get some interesting things. Let’s look at why by first explaining a bit about how computers work. I’m gong to step a bit on the toes of CS61C, but here we go. There are a lot of really little people in your machine. Each of these little people, are unfortunately not very bright. They really onlypeople in your machine....
View Full Document