{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

week1a_sol - CS61A Notes Week 1A Basics order of evaluation...

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

View Full Document Right Arrow Icon
CS61A Notes Week 1A: Basics, order of evaluation, special forms, recursion Assorted Scheme Basics What do you think Scheme will print for the following? Assume this definition of the om procedure: (define (om foo)     (word foo 'nom) > nom This will result in an error because nom has not been defined yet. If you wanted to print the word nom , you would type in 'nom . > (om 'nom) This will result in the value nomnom , where the variable foo in the body of the procedure om was replaced by the word nom . > (om nom) This will attempt to replace the variable foo with the value of the variable nom , resulting in an error, since nom was not defined. > ('om 'nom) This will attempt to call whatever is to the right of the first left parenthesis. However, since om is a word and not a procedure, this statement will fail. > (word 'a 'bc) This will result in the word abc . > (word 'a '(bc)) This will result in an error, because the arguments to the word procedure can only be words. > (sentence 'a 'bc) This will result in the sentence '(a bc) . > (sentence 'a '(bc d)) This will result in the sentence '(a bc d) . The arguments to the sentence procedure can be words or sentences. > (sentence '(a b) '(c d)) This will result in the sentence '(a b c d) . You're So Special: Special Forms 1. define : This would be a good time to recapitulate the two versions of define that we have seen. What is the difference between (define x 5) and  (define (x) 5) ? The first call defines a variable named x and gives it a value of 5 . The second call defines a procedure named x with no arguments. This newly defined procedure will always return the value 5 . 2. if , cond : QUESTION: 1. Write the abs procedure, which implements the absolute value function. Use a cond  statement. (define (abs x)     (cond ((= x 0) 0)           ((< x 0) (- x))           (else x))) 2. Convert the following cond statement into its equivalent if statement: (cond ((= area-code 415) (word 'san 'francisco)) CS61A Summer 2010 George Wang, Jon Kotker, Seshadri Mahalingam, Steven Tang, Eric Tzeng Notes developed based on those of Chung Wu and Justin Chen 1
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
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