Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6881603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:07:43+00:00 2026-05-27T05:07:43+00:00

The exercise 3.8 in the SICP is described as blow: When we defined the

  • 0

The exercise 3.8 in the SICP is described as blow:

When we defined the evaluation model in section 1.1.3, we said that
the first step in evaluating an expression is to evaluate its
subexpressions. But we never specified the order in which the
subexpressions should be evaluated (e.g., left to right or right to
left). When we introduce assignment, the order in which the arguments
to a procedure are evaluated can make a difference to the result.
Define a simple procedure f such that evaluating (+ (f 0) (f 1)) will
return 0 if the arguments to + are evaluated from left to right but
will return 1 if the arguments are evaluated from right to left.

And I wrote the procedure f so that if I call (f x) first, it will always return x whenever I call f again. But I do not know exactly why it works. The procedure I wrote is:

(define f
  (let ((s -1))
    (lambda (x)
      (if (= s -1)
          (begin (set! s x)
                 s)
           s))))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:07:44+00:00Added an answer on May 27, 2026 at 5:07 am

    Think of s as a special variable tied just to your procedure, keeping its value between its invocations. Since you’re going through SICP it should be clear that it’s part of the environment that the procedure attached to f lives in.

    First time it’s called with some X, it sets s to x and returns it. Next time, since s is no longer -1, it will just always return s, which is the value of x saved in the first call.

    > (f 42)  ; s is -1, so 42 is saved into it and returned
    42
    > (f 10)  ; is is 42, so the 'else' branch of the 'if' is taken
              ; and s is returned without looking at x
    42
    > (f 20)
    42
    > 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As an exercise I wrote a short Haskell function that returns the first four
Exercise 1.11 : A function f is defined by the rule that f(n) =
I'm trying to learn scheme via SICP. Exercise 1.3 reads as follow: Define a
The exercise says: Create a Text class that contains a string object to hold
As a programming exercise, I've written a Ruby snippet that creates a class, instantiates
In SICP exercise 2.26, this Scheme code is given: (define x (list 1 2
I am new to Scheme, by looking at the Exercise 1.5 of SICP, what
The Problem: Exercise 2-8 of The C Programming Language, Write a function rightrot(x,n) that
As an exercise, I am implementing in Haskell a 'cons' operation that forms a
Following is a exercise from SICP. I couldn't figure it out on my own.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.