[Top][All Lists]

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

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

From: Tobia Conforto
Subject: Re: [Chicken-users] Problem with amb - or nice bug?
Date: Sat, 1 Nov 2008 03:39:44 +0100

I am learning scheme and am trying to implement the "amb" operator.

Hi. That's great!

Let me start with a piece of advice: consider learning syntax-rules, or hygienic, new-style macros instead of the old-style define-macro. Besides being Scheme's standard macro system, syntax-rules is much more friendly, readable and safe to use. The next version of Chicken (Chicken 4) will support syntax-rules by default and will remove define-macro. In Chicken 3 you can load one of a number of eggs that provide it, for example alexpander.

Your amb macro looks like this in syntax-rules:

(define-syntax amb
  (syntax-rules (m-fail)
    ((amb alt ...)
     (let ((mf m-fail))
         (lambda (sk)
             (lambda (ck)
               (set! m-fail
                 (lambda ()
                   (set! m-fail mf)
                   (ck 'fail)))
               (sk alt)))

Anyways, back to the problem you are having.

I traced it down to the use of (amb) in the top-level and I have a half idea I've stumbled into a bug in the Chicken interpreter, so I'm asking for confirmation from the more experienced Chicken hackers here.

In the meantime, as a workaround, you can convert your *street* global variable into a local variable:

(let ((street (list (make-house ;etc.
                    (make-house ;etc.
  (if (eq? (house-nationality (car street))
           (house-nationality (cadr street)))
  (map show-house street))

Written like this, it works.


Here are my findings.

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)
(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.


reply via email to

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