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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:16:11+00:00 2026-06-16T05:16:11+00:00

I’m having trouble running an example code from SICP (Structure and Interpretation of Computer

  • 0

I’m having trouble running an example code from SICP (Structure and Interpretation of Computer Programs) Section 3.5.4 (Streams and Delayed Evaluation); the SICP section can be found here: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_sec_3.5.4.

I’m using DrRacket version 5.2.1, set up with the SICP support language by Neil Van Dyke (SICP PLaneT 1.17), which can be found here: http://www.neilvandyke.org/racket-sicp/#%28part._installation%29.

The code, shown below, makes use of streams. With the environment set up as above, the procedures cons-stream, force and delay are already available from DrRacket. But stream-car and stream-cdr weren’t available; so, I had to define them. In the code below, I also define some generic stream functions: stream-map, stream-ref, add-streams and scale-stream.

The whole code I’m trying to make work is the following. It includes a procedure to solve first-order differential equations numerically (solve), using an integration procedure (integral), which uses a delayed argument (delayed-integrand); these procedures come from Section 3.5.4.

(define (stream-car stream) (car stream))
(define (stream-cdr stream) (force (cdr stream)))
(define (stream-map proc . argstreams)
  (if (stream-null? (car argstreams))
      the-empty-stream
      (cons-stream
       (apply proc (map stream-car argstreams))
       (apply stream-map
              (cons proc (map stream-cdr argstreams))))))
(define (stream-ref s n)
  (if (= n 0)
      (stream-car s)
      (stream-ref (stream-cdr s) (- n 1))))

(define (add-streams s1 s2)
  (stream-map + s1 s2))

(define (scale-stream stream factor)
  (stream-map (lambda (x) (* x factor)) stream))

(define (integral delayed-integrand initial-value dt)
  (define int
    (cons-stream initial-value
                 (let ((integrand (force delayed-integrand)))
                   (add-streams (scale-stream integrand dt)
                                int))))
  int)

(define (solve f y0 dt)
  (define y (integral (delay dy) y0 dt))
  (define dy (stream-map f y))
  y)

When I put the definitions above in DrRacket and click Run, no error occurs. However, an error occurs when I try to execute the following line in the interactions window:

(stream-ref (solve (lambda (y) y) 1 0.001) 1000)

The error message is:

mcar: expects argument of type <mutable-pair>; given #<undefined>

When this error occurs, DrRacket highlights the body of the definition of the procedure stream-car, as shown in the picture below:

DrRacket error


What is causing this error? I have already used the stream procedures above in previous examples (stream-car, stream-cdr, stream-map, add-streams and scale-stream) and they worked. The integral procedure also works when I use it outside of the solve procedure; for example, if I define (define ones (cons-stream 1 ones)) and then I define (define s (integral (delay ones) 1 1)) and then I execute (stream-ref s 1000), it correctly gives the output 1001.

  • 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-16T05:16:13+00:00Added an answer on June 16, 2026 at 5:16 am

    The error you’re reporting is rather weird, I can’t see where mcar is being used – or mutable state for that matter. Try this setup, it works for me without using Neil Van Dyke’s support language:

    #lang racket
    
    (define the-empty-stream '())
    
    (define (stream-null? stream)
      (null? stream))
    
    (define-syntax cons-stream
      (syntax-rules ()
        ((cons-stream head tail)
         (cons head (delay tail)))))
    
    (define (stream-car stream)
      (car stream))
    
    (define (stream-cdr stream)
      (force (cdr stream)))
    
    ; ... the rest is the same as in your question
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am currently running into a problem where an element is coming back from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.