[plt-scheme] What is wrong with this program ?
Good day Jos,
Thank you, it is now clear.
Andre
-----Message d'origine-----
De : Jos Koot [mailto:jos.koot at telefonica.net]
Envoyé : October-06-08 5:48 AM
À : andre.mayers at usherbrooke.ca; plt-scheme at list.cs.brown.edu
Objet : Re: [plt-scheme] What is wrong with this program ?
See further below how to avoid the problem.
The original value of cont is a continuation that finishes the definition of
variable cont. This means that when the continuation is called the
definition is finished for a second time, which apparently is detected as a
redefinition. At module top level, no variable can be defined more than
once. Note that results depend on how promts are handled. When using debug,
the results are:
Welcome to DrScheme, version 4.1.1 [3m].
Language: Module; memory limit: 800 megabytes.
bonjour
bonsoir
#<procedure>
>
In this case (cont (lambda (var) ...)) is evaluated twice. (cont (lambda
(var) ...)) is included in the original continuation. The redefinition is
not detected and the definition is finished twice. #<procedure> signifies
the value of (lambda (var) ...)). I assume the PLT team is aware of the
different behaviour of run and debug for #lang scheme. The debugger
necessarily has to use other prompts and cannot optimize as well as run.
Nevertheless run and debug should treat refinishing a definition in the same
way, I think.
When removing the line "#lang scheme" and using language Pretty Big, the
results are:
Welcome to DrScheme, version 4.1.1 [3m].
Language: Pretty Big; memory limit: 800 megabytes.
bonjour
>
In this case (cont (lambda (var) ...)) is executed once. It is not included
in the original continuation. Pretty Big does allow redefinition at top
level (not to be confused with module top level) and it does not include
subsequent top level forms in its continuations.
You can avoid the problem as follows:
#lang scheme
(define cont #f)
(set! cont (call/cc (lambda (k)
(display 'bonjour)
(newline)
k)))
(cont
(lambda (var)
(display 'bonsoir)
(newline)
var))
Jos
----- Original Message -----
From: "Andre Mayers" <andre.mayers at usherbrooke.ca>
To: <plt-scheme at list.cs.brown.edu>
Sent: Monday, October 06, 2008 3:35 AM
Subject: [plt-scheme] What is wrong with this program ?
#lang scheme
(define cont (call/cc (lambda (k)
(display 'bonjour)
(newline)
k)))
(cont
(lambda (var)
(display 'bonsoir)
(newline)
var))
==RESULT==
Bienvenue dans DrScheme, version 4.1.1 [3m].
Langage: Module personnalisé; memory limit: 256 megabytes.
bonjour
define-values: cannot re-define a constant: cont
>
_________________________________________________
For list-related administrative tasks:
http://list.cs.brown.edu/mailman/listinfo/plt-scheme