chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Problem with amb - or nice bug?


From: Alaric Snell-Pym
Subject: Re: [Chicken-users] Problem with amb - or nice bug?
Date: Mon, 3 Nov 2008 10:40:38 +0000


On 1 Nov 2008, at 2:39 am, Tobia Conforto wrote:

I got the same results with all these (amb) implementations:
- the one in the amb egg;
- the define-macro in the OP;
- my hygienic one above, both in Chicken 3 with alexpander and in
Chicken svn head;
so it's not a problem in the specific macro.

This is the smallest example that fails: it prints the unreacheable
message instead of raising the appropriate "Program failed!" or
"expression tree exhausted" error.

(amb 1 2)
(amb)
(print "if you read this, there's a bug somewhere")

To see it fail, you need to:
- put these three calls at the top level, NOT inside any lambda or
begin;
- load the file with csi -s or with (load), NOT compiling it;
- remember to reset the top amb exception (m-fail or amb-failure-
continuation) between tests, better yet if you start a new csi each
time.

Ah. It only fails when you're trying to use continuations to roll back
the state of csi itself, as when you enter three expressions at the
top level, it's csi that's iterating through them.

However, continuations explicitly do NOT restore the state of input
streams. Such as stdin. So if you do an (amb) and roll back the state
of the system, then you more or less undo things you've typed into csi
since the point it chooses to roll back to - it won't redo everything
again...

Plus there may be other gotchas with rolling back csi! (amb) doesn't
work well with side effects (and csi, converting an  input stream of
expressions to an output stream of results, is very side effectful).

Putting the entire amb program into a single expression, of course,
avoids touching csi, so you don't have the problem any more.

ABS

--
Alaric Snell-Pym
Work: http://www.snell-systems.co.uk/
Play: http://www.snell-pym.org.uk/alaric/
Blog: http://www.snell-pym.org.uk/?author=4






reply via email to

[Prev in Thread] Current Thread [Next in Thread]