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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:29:25+00:00 2026-05-11T09:29:25+00:00

I am writing a Scheme interpreter, and I am faced with a valid let

  • 0

I am writing a Scheme interpreter, and I am faced with a valid let statement such as:

;; should print 7 (let ((a 4) (b 3))     (let ((a (* a a))            (b (* b b)))        (+ a b)        (- a b))) 

My interpreter implements only a purely functional subset of Scheme, so there will be no side effects such as set!. In a purely functional language, why would you allow multiple expressions inside of a let statement such as above?

And in writing my interpreter, is there any reason I should evaluate anything but the last expression in the let? It seems they could never affect the outcome of the last statement evaluated.

  • 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. 2026-05-11T09:29:26+00:00Added an answer on May 11, 2026 at 9:29 am

    You’re right (almost): if you’re implementing a purely functional subset of Scheme (i.e. no set!, set-car!, set-cdr!) then any expression but the last in a let will have their return value thrown away, and since you’re guaranteed not to have side effects, there’s no danger in silently ignoring them.

    However, there is one small case you need to consider, and that is when the preceding expressions are defines:

    (let ((x 3))   (define y 4)   (+ x y)) 

    This is both legal and functional. However, there is some good news – inside a block (like a let) you have to have all your defines at the top. As in, this is not considered legal Scheme:

    (let ((x 3))   (+ 2 3)   (define y 4)   (+ x y)) 

    This means that when evaluating a block, all you have to do is scan the top for defines and wrap them up into the equivalent letrec expression, then proceed to ignore all but the last expression (which you would then return).

    edit: antti.huima makes an excellent point about call/cc. If you’re going to include continuations in your implementation, you really can’t make many assumptions about when things will be evaluated.

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

Sidebar

Related Questions

I'm writing a scheme interpreter, and in the case of an if statement such
I am writing a Scheme-like in interpreter. It seems natural that the Scheme-like interpreter
I'm writing a small interpreter for a C-like language in Scheme (R5RS) and trying
When writing a switch statement, there appears to be two limitations on what you
Suppose I want to implement an interpreter for a functional language. I would like
I am learning on my own about writing an interpreter for a programming language,
I am writing a program in scheme, that uses recursion to walk through the
I am writing a tiny evaluator for Scheme. I need to write the evaluator
I am writing a silly letrec in Scheme (DrRacket Pretty Big): (letrec ((is-creative? (lambda
How would I go about writing my own eqv? or equal? in scheme? Would

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.