lecture2 - R ECURSION E VALUATION F UNCTIONS G EORGE WANG...

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

View Full Document Right Arrow Icon
R ECURSION , E VALUATION , F UNCTIONS 2 G EORGE W ANG [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
Image of page 1

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

View Full Document Right Arrow Icon
(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 only
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern