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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:13:34+00:00 2026-06-06T19:13:34+00:00

I was going through Structure and interpretation of computer programming by Brain harvey. I

  • 0

I was going through Structure and interpretation of computer programming by Brain harvey. I came across this question which i could not figure out how to do it.

How do we write recursive procedure with lambda in Scheme?

  • 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-06T19:13:36+00:00Added an answer on June 6, 2026 at 7:13 pm

    TL;DR: Use named let (if you are executing a recursive function immediately) or rec (if you are saving the recursive function for later execution).


    The usual way is with letrec, or something that uses a letrec behind the scenes, like named let or rec. Here’s a version of (factorial 10) using letrec:

    (letrec ((factorial (lambda (x)
                          (if (< x 1) 1
                              (* (factorial (- x 1)) x)))))
      (factorial 10))
    

    And the same thing using named let:

    (let factorial ((x 10))
      (if (< x 1) 1
          (* (factorial (- x 1)) x)))
    

    The key understanding here is that both versions are exactly the same. A named let is just a macro that expands to the letrec form. So because the named let version is shorter, that is usually the preferred way to write a recursive function.


    Now, you might ask, what if you want to return the recursive function object directly, rather than execute it? There, too, you can use letrec:

    (letrec ((factorial (lambda (x)
                          (if (< x 1) 1
                              (* (factorial (- x 1)) x)))))
      factorial)
    

    There, too, is a shorthand for this, although not using named let, but instead using rec:

    (rec (factorial x)
      (if (< x 1) 1
          (* (factorial (- x 1)) x)))
    

    The nice thing about using rec here is that you can assign the function object to a variable and execute it later.

    (define my-fact (rec (factorial x)
                      (if (< x 1) 1
                          (* (factorial (- x 1)) x))))
    (my-fact 10)  ; => 3628800
    

    The more theoretical and “pure” way to create recursive functions is to use a Y combinator. 🙂 But most practical Scheme programs do not use this approach, so I won’t discuss it further.

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

Sidebar

Related Questions

I'm going through Structure and Interpretation of Computer Programs and I'm having a bit
Going through some documentation on modifying CGImageRef data, I came across a strange example
I was just going through programming structure studies; In particular I was studying concurrent
I was just going through some codes of C++. Where in I came across
I was just going through certain interview questions. Got this structure related issue, I
I was going through JNI tutorial and I came across below line in generated
I was going through some data structures and I noticed this as a time
While going through some tutorials, I have encountered lines such as this: ((IDisposable)foo).Dispose(); Ignore
While going through many resources on multithreaded programming, reference to volatile specifier usually comes
I'm fairly new the functional programming, so I'm going through some practice exercises. I

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.