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

Re: [Scheme-reports] Opinion about R7RS



Jean-Michel HUFFLEN writes:

>     The description of the "call/cc" function begins with:
> It is an error if "proc" does not accept one argument.

It's saying that (call/cc (lambda () ...)) is an error, as is (call/cc
(lambda (x y) ...)). Call/cc calls its argument with one argument, the
continuation.

>     That is the standard case, but as it is recalled later in the
> text: Except for the continuations created by the "call-with-values"
> procedure [...], all continuations take exactly one value.
>     I think that the first sentence should be reformulated.

It's fine and not at all deep.

>     The "values" function should be defined better about the equivalence:
>        (values X) == X
> The report reads:
>     The "values" procedure might be defined as follows:
> (define (values . things)
>    (call/cc (lambda (cont) (apply cont things))))

First it says that values passes its arguments to its continuation,
just like the suggested implementation does. Procedures always return
their values by passing them to their continuation, so it's that
continuation that has to be special and accept different numbers of
arguments.

> In such a case, we can easily prove that (values X) ==> X. But
> "might be defined" can be interpreted "might be defined or might not
> be defined".

The real definition is "passes its arguments to its continuation".

> A rough implementation of this function is:
> (define (values . things)
>    (lambda (f) (apply f things)))

That passes to its continuation one value, a procedure that is not any
of its arguments. No good. But there was an implementation that I even
used when the real thing was not available:

(define (values . things)
   (if (or (null? things) (pair? (cdr things)))
       (cons <special-tag> things)
       (car things)))

Then arrange call-with-values to recognize <special-tag> and apply its
second argument to the things:

(define (call-with-values thunk think)
   (let ((x (thunk)))
      (if (and (pair? x) (eq? (car x) <special-tag>))
          (apply think (cdr x))
          (think x))))

Something like that. But the draft is fine.

Incidentally, there is one other procedure in Scheme that can be used
as an identity function for one argument.


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