{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Cpsc 201 Problem Set 1

Cpsc 201 Problem Set 1 - 1 John C Rimson has defined...

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

View Full Document Right Arrow Icon
1. John C. Rimson has defined reverse-if as follows: The problem with this implementation is the (predicate) – which (because it is enclosed in parentheses) is a call to the (no-arguments) procedure predicate . So, one can write an if expression that will evaluate to the string “Consequence” as follows: However, if one tries to perform a similar operation using John’s reverse-if (with the alternative and consequence inverted): an error is returned. In an if expression, the first argument (the predicate) can be any expression which evaluates to a value (even if that value is a procedure): But expressions which do not evaluate to anything, will cause an error: However, John’s reverse-if requires that predicate be a no-arguments procedure, making it far less versatile than the standard if . This problem can be fixed by using the following version of reverse-if : Now, for our earlier example, reverse-if behaves as expected: But suppose I define a procedure PrintLineAndEvaluate as follows: This procedure takes a single argument, which it prints and returns as its value: Using this method as part of an if expression yield the expected results: But, a reverse-if expression does not have equivalent results:
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
If is a special form which does not evaluate in the same way as a standard Scheme expression. Normally, a procedure is evaluated by first evaluating each of its arguments (in some arbitrary order) and binding these values to the process’s variables (a process being an evaluation of a procedure for a specific set of arguments). However, an if is evaluated by first evaluating the predicate. If the
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