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 7706257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:04:49+00:00 2026-06-01T00:04:49+00:00

In Concrete Abstractions , there is this example of recursion: (define subtract-the-first (lambda (n)

  • 0

In Concrete Abstractions, there is this example of recursion:

(define subtract-the-first (lambda (n)
                             (if (= n 0) 0
                                 (- (subtract-the-first (- n 1)) n))))

This I understand. For instance, if n = 3, this function evaluates to:
(- (+ (+ (+ 1) 2) 3)) -> -6

However, in one of the follow-up examples, one is supposed to explain why it’s not possible to switch the order of operations. For instance, let’s look at this:

(define subtract-the-first2 (lambda (n)
                             (if (= n 0) 0
                                 (- n (subtract-the-first2 (- n 1))))))

If I call (subtract-the-first2 4), the result is 2. However, I don’t quite understand the evaluation. Obviously, I am making a mistake here, because see this:
(- 4 (+ 3 (+ 2 (+ 1))) ), which is equal to (- 4 6) and thus evaluates to -2.

I appreciate any pointers as I’ve been banging me head against the wall for half an hour or so already…

Thank you!

  • 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-06-01T00:04:50+00:00Added an answer on June 1, 2026 at 12:04 am

    You can check the evaluation of this function by adding some semiquotes and unquotes:

    (define subtract-the-first2 (lambda (n)
                                  (if (= n 0) 0
                                    `(- ,n ,(subtract-the-first2 (- n 1))))))
    

    Then evaluate:

    > (subtract-the-first2 4)
    (- 4 (- 3 (- 2 (- 1 0))))
    

    This evaluates to 2. (I don’t see where you got the pluses…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

concrete example http://img246.imageshack.us/img246/602/6x7gridsm.png By address I mean the location if you were counting left
Can someone please derive a concrete example from the following: http://www.urdalen.com/blog/?p=210 ..that shows how
This is a more concrete question that is connected with my previous one. I
I have this concrete problem, but if You find my initial design idea crazy
I'll use a concrete, but hypothetical, example. Each Order normally has only one line
Let's take a concrete example and hope I can be clear. Suppose the (ordered)
A Concrete class typecasted to interface, does JVM still consider it a instance of
Here is a concrete example: I create a IWeBrowser2 interface by calling wb.CoCreateInstance(CLSID_InternetExplorer, 0,
There are zillions of concrete implementations of IEnumerable: List<T> , Dictionary<T> , etc. What
To give a concrete example of what I mean: Imagine I have an HTML

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.