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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:50:08+00:00 2026-05-20T18:50:08+00:00

Ok, this is a fairly basic question: I am following the SICP videos, and

  • 0

Ok, this is a fairly basic question: I am following the SICP videos, and I am a bit confused about the differences between define, let and set!.

1) According to Sussman in the video, define is allowed to attach a value to avariable only once (except when in the REPL), in particular two defines in line are not allowed. Yet Guile happily runs this code

(define a 1)
(define a 2)
(write a)

and outputs 2, as expected. Things are a little bit more complicated because if I try to do this (EDIT: after the above definitions)

(define a (1+ a))

I get an error, while

(set! a (1+ a))

is allowed. Still I don’t think that this the only difference between set! and define: what is that I am missing?

2) The difference between define and let puzzles me even more. I know in theory let is used to bind variables in local scope. Still, it seems to me that this works the same with define, for instance I can replace

(define (f x)
    (let ((a 1))
        (+ a x)))

with

(define (g x)
    (define a 1)
    (+ a x))

and f and g work the same: in particular the variable a is unbound outside g as well.

The only way I can see this useful is that let may have a shorter scope that the whole function definition. Still it seems to me that one can always add an anonymous function to create the necessary scope, and invoke it right away, much like one does in javascript. So, what is the real advantage of let?

  • 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-20T18:50:08+00:00Added an answer on May 20, 2026 at 6:50 pm

    Do you mean (+ 1 a) instead of (1+ a) ? The latter is not syntactically valid.

    Scope of variables defined by let are bound to the latter, thus

    (define (f x)
      (let ((a 1))
        (+ a x)))
    

    is syntactically possible, while

    (define (f x)
      (let ((a 1)))
      (+ a x))
    

    is not.

    All variables have to be defined in the beginning of the function, thus the following code is possible:

    (define (g x)
      (define a 1)
      (+ a x))
    

    while this code will generate an error:

    (define (g x)
      (define a 1)
      (display (+ a x))
      (define b 2)
      (+ a x))
    

    because the first expression after the definition implies that there are no other definitions.

    set! doesn’t define the variable, rather it is used to assign the variable a new value. Therefore these definitions are meaningless:

    (define (f x)
      (set! ((a 1))
        (+ a x)))
    
    (define (g x)
      (set! a 1)
      (+ a x))
    

    Valid use for set! is as follows:

    (define x 12)
    > (set! x (add1 x))
    > x
    13
    

    Though it’s discouraged, as Scheme is a functional language.

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

Sidebar

Related Questions

This is a fairly basic question about state server but assume there are 2
This is a fairly basic question about CakePHP, but since my knowledge of this
Fairly new to python, forgive me if this is a basic question about learning
This is a fairly basic question, which for some reason, a proper solution escapes
This is a fairly basic question, but I haven't been able to find any
All, This would seem like a fairly basic asp.net question - but in all
first post, so play nice! I have a fairly basic question about Python dictionaries.
This is a very basic question. I'm learning Javascript, and I'm fairly new to
Fairly basic question i'm hoping. In the following javascript, I want to run the
This is probably a fairly basic question but I haven't managed to find anything

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.