Logo
  • Home
  • Classes
  • Conveying Computing
  • Exams
  • Fractal Gallery
  • Guides
  • Problem Sets
  • Syllabus

Class 4: Constructing Procedures

Assignments Due

  • By Friday: Read Chapters 1-4 of course book, Chapters 1-3 of James Gleick’s The Information
  • Monday, 5 September (11:01am): Problem Set 1 (both on-line submission and paper)
  • Wednesday, 7 September (in class): Quiz 1: covers Chapters 1-4 of course book, Chapters 1-3 of The Information, Classes 1-5 (including questions)

    Upcoming Help Schedule (all office hours are now in Rice Hall)

  • Today, 5-6:30pm (Jiamin, Rice, first floor)
  • Thursday: 9:45-11am (Dave, Rice 507); 10-11:30am (Peter, Rice first floor); 1-2:30pm (Joseph, Rice first floor); 4:30-6pm (Jonathan, Rice first floor); 6-7:30pm (Jiamin, Rice first floor)

Scheme Grammar and Rules of Evaluation

(continued from Class 3)

Expression ::= ProcedureExpression

ProcedureExpression ::= (lambda (Parameters) Expression)


Parameters ::=


Parameters ::= Name Parameters

Evaluation Rule 4: A lambda expression evaluates to a procedure that takes the given parameters and has the expression as its body.

(lambda () true)
(lambda (x) (* x x))
(lambda (a)
   (lambda (b)
      (+ a b)))

Applying Constructed Procedures

((lambda () true) 1120) 

((lambda (x) (+ x 1000)) 120) 

((lambda (a) (lambda (b) (+ a b))) 5) 

(((lambda (a) (lambda (b) (+ a b))) 5) 6) 

Expression ::= IfExpression

IfExpression ::= (if ExpressionPredicate ExpressionConsequent ExpressionAlternate)

Evaluation Rule 5: If. To evaluate an if expression, (a) evaluate the ___________________; then, (b) if the value of the predicate expression is ___________ then the value of the if expression is the value of the alternate expression; otherwise, the value of the if expression is the value of the _____________________________________.

(if false false true)

(if (> 4 3) 4 3)

((lambda (a b) (if (> a b) a b)) 5 6) 

Questions

Show how the Rules of Evaluation would evaluate:

   (define square (lambda (x) (* x x)))
   (square 4)

You will need more space for this and it will be very tedious, but it is worth doing once. Of course, you know the final value, but the important thing is to understand how following the Scheme evaluation rules steps will produce that value. You should be confident that you can determine the value of any Scheme expression just by following the evaluation rules systematically.

Evaluation Rule 3a does not say in what order the subexpressions should be evaluated in. For example, we could evaluate them left to right, or right to left, or in any other order. Does it ever matter in which order the subexpressions of an application are evaluated? (Tough question, but try to think of a Scheme expression where it would make a difference.)


Links

  • Why Verb-Initial Languages are Not Frequent [PDF], Andre Grüning, May 2002. Interesting paper that speculates on why most natural languages are SOV or SVO using results from computer simulations.
  • Revised5 Report on the Algorithmic Language Scheme [PDF] – this is the official definition of the Scheme language
  • C++ Standard Core Language Active Issues (948 issues or problems
    with C++ that the language experts can’t agree on). A new version of the C++ language was recently approved; it attempts to resolve some problems in C++, but also adds more complexity so I’m sure there will be more new issues soon…
    Print Friendly Print Get a PDF version of this webpage PDF
  • Leave a Reply Cancel reply

    You must be logged in to post a comment.


    Fall 2011

    Register
    Login

    Help Schedule

    (all in Davis Commons, except Dave's office hours in Rice 507)
    Sundays, 1-6pm (Valerie/Joseph/Kristina)
    Mondays, noon-1:30pm (Kristina)
    Mondays, 1:15-2:00pm (Dave, Rice 507)
    Tuesdays, 11am-noon (Dave, Rice 507)
    Tuesdays, 5-8pm (Valerie/Jonathan)
    Wednesdays, 5-6:30pm (Jiamin)
    Thursdays, 9:45-11am (Dave, Rice 507)
    Thursdays, 1-2:30pm (Joseph)
    Thursdays, 4:30-7:30pm (Jonathan/Jiamin)
    Fridays, noon-1:30pm (Peter)

    Recent Posts

    • Course Wrap-Up
    • Class 41: The Cake of Computing
    • PS8 Submissions
    • Class 40: GuardRails, Big Data, and Secure Computation
    • Exam 2 Solutions

    Recent Comments

    • David Evans on Problem Sets
    • jacob777 on Problem Sets
    • Prof. K.R. Chowdhary on Class 41: The Cake of Computing
    • Anon on Exams
    • Anon on Exams

    Index

    • Classes
      • Class 1: Computing
      • Class 2: Language
      • Class 3: Rules of Evaluation
      • Class 4: Constructing Procedures
      • Class 5: Procedures Practice
      • Class 6: Programming with Data
      • Class 7: Programming with Lists
      • Class 8: Recursive List Procedures
      • Class 9: Consistent Hashing
    • Conveying Computing
    • Exams
    • Fractal Gallery
    • Guides
      • DrRacket Guide
      • Schemer’s Guide to Python
    • Problem Sets
      • Problem Set 0: Course Registration, Racket
      • Problem Set 1: Making Mosaics
        • PS1 Comments
      • Problem Set 2: Sequence Alignment
        • PS2 Comments
      • Problem Set 3: Limning L-System Fractals
        • PS3 – Comments
      • Problem Set 4: Constructing Colossi
        • PS4 – Comments
      • Problem Set 5: Wahoo! Auctions
        • PS5 Comments
      • Problem Set 6: Adventures in Charlottansville
        • PS6 Comments
      • Problem Set 7: Charming Snakes with Mesmerizing Memoizers
        • PS7 Comments
        • PS7 Responses
      • Problem Set 8 (Part 2): Typed Aazda
      • Problem Set 8: From Aazda to aaZda (Part 1)
        • PS8 Part 1 Comments
    • Syllabus
      • Course Pledge
    • Using These Materials

    RSS BA Computer Science

    RSS Jefferson’s Wheel

    • MICO Challenge in Membership Inference
    • Voice of America interview on ChatGPT
    • Uh-oh, there's a new way to poison code models
    • Trojan Puzzle attack trains AI assistants into suggesting malicious code

    RSS Hacker News

    • Humanness in the Age of AI
    • He who submits a resume has already lost
    • Google Drive does a surprise rollout of file limits, locking out some users
    • APLcart – Find your way in APL
    • ChatGPT simulates 1987 BBS System

    RSS Babbage

    • And it’s goodnight from us
    • Why 10, not 9, is better than 8
    • Future, imperfect and tense
    • The paperless dilemma
    • How to judge a ’bot; why it’s covered
    cs1120 | RSS | Comments RSS | Book | Using These Materials | Login | Admin | Powered by Wordpress