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

  • Home
  • SEARCH
  • 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 790975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:45:40+00:00 2026-05-14T21:45:40+00:00

I am currently working through SICP using Guile as my primary language for the

  • 0

I am currently working through SICP using Guile as my primary language for the exercises. I have found a strange behavior while implementing the exercises in chapter 3.5. I have reproduced this behavior using Guile 1.4, Guile 1.8.6 and Guile 1.8.7 on a variety of platforms and am certain it is not specific to my setup.

This code works fine (and computes e):

  (define y (integral (delay dy) 1 0.001))
  (define dy (stream-map (lambda (x) x) y))
  (stream-ref y 1000)

The following code should give an identical result:

  (define (solve f y0 dt)
    (define y (integral (delay dy) y0 dt))
    (define dy (stream-map f y))
    y)
  (stream-ref (solve (lambda (x) x) 1 0.001) 1000)

But it yields the error message:

standard input:7:14: While evaluating arguments to stream-map in expression (stream-map f y):
standard input:7:14: Unbound variable:
y ABORT: (unbound-variable)

So when embedded in a procedure definition, the (define y …) does not work, whereas outside the procedure in the global environment at the REPL it works fine.

What am I doing wrong here? I can post the auxiliary code (i.e., the definitions of integral, stream-map etc.) if necessary, too. With the exception of the system-dependent code for cons-stream, they are all in the book. My own implementation of cons-stream for Guile is as follows:

(define-macro (cons-stream a b)
  `(cons ,a (delay ,b)))
  • 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-14T21:45:41+00:00Added an answer on May 14, 2026 at 9:45 pm

    The key difference between what happens when you evaluate the definitions one by one at the REPL and when you place them inside solve is that in the first case, they are evaluated sequentially, thus the y the expression (stream-map <some-function> y) refers to is already in scope, whereas with internal definitions or letrec, it is not yet available.

    Funnily enough, MIT Scheme, which I used when going through SICP, had no such problem back then and still treats letrec and internal defines differently:

    ;; this is an error
    (letrec ((xs '(1 2 3)) (ys (map (lambda (x) (+ x 1)) xs))) ys)
    
    ;; this is still an error (and is treated as such by Guile),
    ;; yet evaluates to (2 3 4) in MIT Scheme
    (let () (define xs '(1 2 3)) (define ys (map (lambda (x) (+ x 1)) xs)) ys)
    

    I’m not sure about the original “Revised Report On Algorithmic Language Scheme” or R2RS, but at least from R3RS on internal defines were supposed to be equivalent to letrec. Apparently this peculiarity of MIT’s environment influenced the book… or perhaps it’s the other way around.

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

Sidebar

Related Questions

One long term project I have is working through all the exercises of SICP.
I'm currently working through the excercises in 'The C Programming Language'. Here's one of
I'm working through Practical Web 2.0 Appications currently and have hit a bit of
I'm currently working through some exercises in a c++ book, which uses text based
I'm currently working through O'Reilly's Programming PHP and have come across this table titled
I'm working through SICP. Currently, in the first chapter, I'm having problems getting Racket
I am currently working through Accelerated C++ and have come across an issue in
I am currently working through SICP's section on Logic Programming, but I got stuck
I'm currently working through an assignment that deals with Big-O and running times. I
I've been working through the Stanford iPhone Coding course and currently hooking into the

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.