lecture2 - R ECURSION , E VALUATION , F UNCTIONS 2 GEORGE...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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

This note was uploaded on 08/14/2010 for the course EECS 61A taught by Professor Harvey during the Summer '08 term at Berkeley.

Page1 / 4

lecture2 - R ECURSION , E VALUATION , F UNCTIONS 2 GEORGE...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online