bug-guile
[Top][All Lists]
Advanced

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

Re: shift and reset, plus "while"


From: Wolfgang J Moeller
Subject: Re: shift and reset, plus "while"
Date: Thu, 28 Apr 2011 16:44:26 +0200 (CEST)

Hi Andy,

>[...]
> On Mon 04 Apr 2011 15:05, Wolfgang J Moeller <address@hidden> writes:
>
> > (a) to always have a well-defined result
> > (b) to allow for (break arg ...)
>
> I have implemented this in stable-2.0.  It did not make it into 2.0.1
> however.  Incidentally it should be compatible with the old 1.6 `while'.

Great. Thanks!

No more reason to consider my "last resort":

> On Wed, 13 Apr 2011, Andy Wingo wrote:
> >[...]
> > >From Guile 1.6:
> >[...]
> > It did indeed happen to return #t on a normal termination, and have
> > (break ARG).  It has lots of other bugs though.  I would prefer (break)
> > to return zero values, and (while #f 1) as well, but that is
> > incompatible with 2.0.  Bummer.
>
> OK, that explains why I have an old & lengthy program that does use
> (break arg), and why I had to keep my macro compatible.
>
> Last resort: Once we do allow for argument(s) to (break),
>
>    (while #t ... (break x) ... (break y) ...)
>
> allows for full functionality, plus returning all well-defined results,
> without necessarily requiring well-defined (or even different) results
> from (break) and (while #f).
>
> Only that this construct might better be called "loop/return" ...

Sorry, this was meant as a loop that would _only_ be terminated
[conditionally] by (BREAK arg . optargs) forms [at various places].

I had proposed this, so - for compatibility - both of the other forms
         (while #f ... )
and      (break) w/o arguments within (while ...)
could return whatever values you'd like (including #<unspecified>).

Maybe you just did implement point (a) above this way ...

===

>[...]
> (define-syntax with-yield
>   (lambda (x)
>     (syntax-case x ()
>       ((_ yield exp exp* ...) (identifier? #'yield)
>        #'(let ((tag (make-prompt-tag)))
>            (define (handler k . args)
>              (define (resume . args)
>                (call-with-prompt tag
>                  (lambda () (apply k args))
>                  handler))
>              (apply values resume args))
>
>            (call-with-prompt
>             tag
>             (lambda ()
>               (let-syntax ((yield (syntax-rules ()
>                                     ((_ arg (... ...))
>                                      (abort-to-prompt tag arg (... ...))))))
>                 exp exp* ...))
>            handler))))))
>
> Then you can
>
>   (with-yield yield
>     (while #t ... (yield) ...))

While not asked for, great macro anyway ;-)

I eventually got to try it out and check if it's "call/cc-compatible"
[remember my (solved) problem to have general reset/shift-based co-routines?].

===

Next going to play with 2.0.1 !


Best regards,

Wolfgang J. Moeller, Tel. +49 551 47361, wjm<AT>heenes.com
37085 Goettingen, Germany | Disclaimer: No claim intended!
http://www.wjmoeller.de/ -+-------- http://www.heenes.com/



reply via email to

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