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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:37:01+00:00 2026-05-15T11:37:01+00:00

I am having some trouble understanding the behavior of the following Scheme program: (define

  • 0

I am having some trouble understanding the behavior of the following
Scheme program:

(define c
  (dynamic-wind
    (lambda () (display 'IN)(newline))
    (lambda () (call/cc (lambda (k)
                     (display 'X)(newline)
                     k)))
    (lambda () (display 'OUT)(newline))))

As I understand, c will be bound to the continution created right before “(display ‘X)”.

But using c seems to modify itself! The define above prints (as I expected) IN, X and OUT:

IN
X
OUT

And it is a procedure:

#;2> c
#<procedure (a9869 . results1678)>

Now, I would expect that when it is called again, X would be printed, and it is not!

#;3> (c)
IN
OUT

And now c is not a procedure anymore, and a second invokation of c won’t work!

#;4> c    ;; the REPL doesn't answer this, so there are no values returned
#;5> (c)

Error: call of non-procedure: #<unspecified>

        Call history:

        <syntax>            (c)
        <eval>              (c)    <--

I was expecting that each invokation to (c) would do the same thing — print IN, X, and OUT. What am I missing?

  • 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-15T11:37:02+00:00Added an answer on May 15, 2026 at 11:37 am

    Running this in Racket is a little more helpful:

    -> (define c
         (dynamic-wind
           (lambda () (display 'IN)(newline))
           (lambda () (call/cc (lambda (k)
                                 (display 'X)(newline)
                                 k)))
           (lambda () (display 'OUT)(newline))))
    IN
    X
    OUT
    -> c
    #<continuation>
    -> (c)
    IN
    OUT
    define-values: context (defining "c") expected 1 value, received 0 values
    -> (c 99)
    IN
    OUT
    -> c
    99
    

    Note specifically that c gets bound to a continuation value — because your expression returns k as the value. And k itself is the continuation of the value expression, which means that this continuation is the one waiting to get a value to be bound to c. So invoking it requires a single value, as Racket requires, which helps clarifying what happens here (MIT Scheme seems to silently treat it as unspecified). Anyway, applying this continuation on 99 means that the return value from that expression is 99 — so you jump back into the context (printing IN) and return 99 to be bound to c, and print OUT on your way out. You’ve now modified c to have that 99 instead, so you can’t call it a third time.

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

Sidebar

Related Questions

I'm new to Ruby, so I'm having some trouble understanding this weird exception problem
I'm having some trouble understanding a bit of code. I've got 2 classes Company
I am having some trouble understanding how to retrieve the result of a calculation
I'm having some trouble understanding Outlook terms (CommandBarPopup, CommandBarButton etc) like what is what
I'm having some trouble understanding the IF clause at the end of this function
I am having some trouble understanding how to make System Sequence Diagrams, as I
I'm having some trouble understanding how to use prepared statements, when you need to
I'm having some trouble understanding how the delay macro works in Clojure. It doesn't
I am having some trouble understanding the MVC Pattern. I do understand we are
Hey having some trouble trying to maintain transparency on a png when i create

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.