unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* A question on a piece of code written using call/cc
@ 2010-09-01  4:10 Yi DAI
  2010-09-01 15:35 ` Andy Wingo
  0 siblings, 1 reply; 2+ messages in thread
From: Yi DAI @ 2010-09-01  4:10 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 509 bytes --]

Hi,


I recently test a piece of code written using call/cc on Guile and several
other Scheme implementations, but get different results. The code piece is
as follows:

(let ((n 0)
      (c (call/cc (lambda (k) k))))
  (display n)
  (newline)
  (set! n (+ n 1))
  (c c))

What I wanna do is try to print out the sequence of natural numbers using
call/cc. On Guile, it works well. But other implementations (Chicken,
Bigloo, Racket) all print out (an infinite sequence of) 0. I am puzzled. Any
idea?


-- 
DAY

[-- Attachment #2: Type: text/html, Size: 1167 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: A question on a piece of code written using call/cc
  2010-09-01  4:10 A question on a piece of code written using call/cc Yi DAI
@ 2010-09-01 15:35 ` Andy Wingo
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Wingo @ 2010-09-01 15:35 UTC (permalink / raw)
  To: Yi DAI; +Cc: guile-user

Hi Yi,

On Tue 31 Aug 2010 21:10, Yi DAI <plm.day@gmail.com> writes:

> (let ((n 0) 
>       (c (call/cc (lambda (k) k))))
>   (display n)
>   (newline)
>   (set! n (+ n 1))
>   (c c))
>
> What I wanna do is try to print out the sequence of natural numbers
> using call/cc. On Guile, it works well. But other implementations
> (Chicken, Bigloo, Racket) all print out (an infinite sequence of) 0. I
> am puzzled. Any idea?

Guile from master returns a sequence of zeros as well. I'm not sure why
older Guile behaves differently.

I think in any case for your program to be correct, you need to use let*
instead of let.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-09-01 15:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-01  4:10 A question on a piece of code written using call/cc Yi DAI
2010-09-01 15:35 ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).