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

Re: [Scheme-reports] Comments on draft 6 about call/cc



On Sun, Feb 26, 2012 at 11:56 PM,  <oleg@x> wrote:
>
> The implementation of delimited control in terms of call/cc is much more
> complex and subtle than it appears from Filinski's code.
[...]
> There are far bigger practical problems. See the slides of Chung-chieh
> Shan's ICFP06 talk
>        http://www.cs.rutgers.edu/~ccshan/dynscope/talk.pdf
>
> particularly slide 31 and the ones leading to it.

Is that the correct URL?  It has only 20 slides.

>> With mutation, call/cc can implement delimited continuations.  The
>> inverse is not so - delimited continuations can't implement call/cc
>> nor many uses of it such as amb.
>
> I am yet to come across any practical use of specifically undelimited
> continuations at all. I came to believe that call/cc per se has no
> practical use. I am intrigued by your mention of amb: certainly amb
> can be expressed using delimited control, I've done it many times in
> many languages.

Sorry, disregard that, I'm not sure what I was thinking.

There do exist uses of undelimited continuations, but
as you say the question is whether they are any use.
I'm still trying to think of a good example.

As a circular example, delimited continuations can't
implement the call/cc form.  Even if all practical uses
of call/cc can be replaced with delimited continuations,
existing code would need to be re-written.

> Finally, practically speaking call/cc captures a delimited
> continuation anyway. Many Scheme systems put an implicit reset around
> the REPL. (When a debugger is entered, the reset is put around it as
> well. If a Scheme provides a threading facility, sometimes implicit
> resets are placed around threads.)
>
>
> For example, in Petite Chez:
>
> (let ((k0 #f))
>  (call/cc (lambda (k) (set! k0 k)))
>  (display "OK") (newline)
>  (k0 #f))
>
> That code prints the unending stream of OK.
>
> Now, I change the code to put each operation on its own line
> (evaluated by its own REPL).
>
>
> (define k0 #f)
> (call/cc (lambda (k) (set! k0 k)))
> (display "OK") (newline)
> (k0 #f)
>
> The result:
> OK
> #f
>
> So, call/cc has captured the identity continuation. Not only
> undelimited continuations have no practical use -- undelimited
> continuations don't even exist in practice. In practical systems,
> call/cc captures delimited continuation, which can certainly be
> implemented with shift.

This is an artifact of one particular implementation
of the REPL.  If your REPL views the input as a
proper stream (as in the following simple definition)
then it gives the same result as the let-wrapped version:

(define (repl)
  (define unread (list 'unread))
  (define (make-stream) (list unread))
  (define (stream-car stream)
    (if (eq? unread (car stream))
        (let ((expr (begin (display "> ") (read))))
          (set-car! stream expr)
          expr)
        (car stream)))
  (define (stream-cdr stream)
    (if (not (pair? (cdr stream)))
        (set-cdr! stream (make-stream)))
    (cdr stream))
  (let lp ((stream (make-stream)))
    (let ((expr (stream-car stream)))
      (cond
       ((not (eof-object? expr))
        (let ((res (eval expr)))
          (cond ((not (eq? res (if #f #f)))
                 (write (eval res))
                 (newline))))
        (lp (stream-cdr stream)))))))


-- 
Alex

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports