wrong number of arguments to continuation when escaping?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

wrong number of arguments to continuation when escaping?

Marco Maggi-2
Ciao,

  let's look at this script:

    (import (scheme)
            (chicken pretty-print))
    (define (doit)
      (call-with-current-continuation
          (lambda (escape)
              (pretty-print 'before)
              (pretty-print escape)
              (escape)
              (pretty-print 'after)
              (values))))
    (doit)

I compile and run it under CHICKEN 5.1.0:

$ csc -O1 -o demo demo.scm && ./demo
before
#<procedure (continuation . results)>

Error: bad argument count - received 0 but expected 1

        Call history:

        demo.scm:33: doit
        demo.scm:25: scheme#call-with-current-continuation
        demo.scm:27: chicken.pretty-print#pretty-print
        demo.scm:28: chicken.pretty-print#pretty-print
        demo.scm:29: escape             <--

I do not understand why some place expects 1 argument.  The problem goes
away if I replace:

   (escape)

with:

   (escape 1)

TIA
--
Marco Maggi

_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users
Reply | Threaded
Open this post in threaded view
|

Re: wrong number of arguments to continuation when escaping?

Peter Bex
On Thu, Jul 18, 2019 at 06:43:06AM +0200, Marco Maggi wrote:
> I do not understand why some place expects 1 argument.  The problem goes
> away if I replace:
>
>    (escape)
>
> with:
>
>    (escape 1)

Hi Marco,

This is a known "issue", see #1390 and #1601.  Improving this so
that such non-explicit "value" continuations accept different argument
counts would have a big impact on performance because every single
continuation would then need to start checking its argument count.

It's unfortunate, but easy to fix; just use something like "receive"
or "call-with-values" to explicitly allow the continuation to handle
multiple values.

Cheers,
Peter

_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: wrong number of arguments to continuation when escaping?

Marco Maggi-2
Peter Bex wrote:

> On Thu, Jul 18, 2019 at 06:43:06AM +0200, Marco Maggi wrote:
>> I do not understand why some place expects 1 argument.  The problem goes
>> away if I replace:

>>    (escape)

>> with:

>>    (escape 1)

> Hi Marco,

> This is a known "issue", see #1390 and #1601.  Improving this so
> that such non-explicit "value" continuations accept different argument
> counts would have a big impact on performance because every single
> continuation would then need to start checking its argument count.

> It's unfortunate, but easy to fix; just use something like "receive"
> or "call-with-values" to explicitly allow the continuation to handle
> multiple values.

Not sure if I understand.  The problem  lies in the context in which the
call to DOIT is performed?  The code expects 1 value from:

   (doit)

so error; it expects one value in:

   (begin
     (doit)
     #t)

so error; it expects one value in:

   (let ()
     (doit)
     #f)

so error; it expects any number of values in:

   (call-with-values
       doit
     (lambda args (apply values args)))

so no error?
--
Marco Maggi

_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users
Reply | Threaded
Open this post in threaded view
|

Re: wrong number of arguments to continuation when escaping?

Peter Bex
On Thu, Jul 18, 2019 at 08:13:53AM +0200, Marco Maggi wrote:
> Not sure if I understand.  The problem  lies in the context in which the
> call to DOIT is performed?

Yes, exactly.

> it expects any number of values in:
>
>    (call-with-values
>        doit
>      (lambda args (apply values args)))
>
> so no error?

Right.  call-with-values sets up a different type of continuation,
one that accepts an arbitrary number of values.  Standard continuations
allow only one argument.

Cheers,
Peter

_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: wrong number of arguments to continuation when escaping?

felix.winkelmann
> On Thu, Jul 18, 2019 at 08:13:53AM +0200, Marco Maggi wrote:
> > Not sure if I understand.  The problem  lies in the context in which the
> > call to DOIT is performed?
>
> Yes, exactly.
>
> > it expects any number of values in:
> >
> >    (call-with-values
> >        doit
> >      (lambda args (apply values args)))
> >
> > so no error?
>
> Right.  call-with-values sets up a different type of continuation,
> one that accepts an arbitrary number of values.  Standard continuations
> allow only one argument.
>

See also R5RS and R7RS. R5RS only accepts multiple values in
a context created by call-with-values (this is currently what CHICKEN
does, modulo some places where it is easy to be more lax).

R7RS explicitly allows a mismatch in the number of values in
the non-final position of expression sequences created by
"begin", "let", etc.


felix


_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users