On Sun, Sep 06, 2009 at 04:06:46AM -0400, John Cowan wrote:
> Here's the chibi-scheme implementation:
> 
> (define *values-tag* (list 'values))
> 
> (define (values . ls)
>   (if (and (pair? ls) (null? (cdr ls)))
>       (car ls)
>       (cons *values-tag* ls)))
> 
> (define (call-with-values producer consumer)
>   (let ((res (producer)))
>     (if (and (pair? res) (eq? *values-tag* (car res)))
>         (apply consumer (cdr res))
>         (consumer res))))

Which, though less wrong than MIT Scheme, is incomplete:

(define call-with-current-continuation
  (let ((ur-call/cc call-with-current-continuation))
    (lambda (f)
      (ur-call/cc
       (lambda (k)
         (f (lambda a (k (apply values a)))))))))

As I may have mentioned the last time this came up, values is just
semantic sugar for call/cc, and call-with-values is the inverse of
(delimited) continuation capture.  More to the point, as long as
call/cc is in the language, the equivalence between multiple value
return and multiple argument passing is manifest; relegating only one
to second-class-blob status may not have the desired effect on the
language's elegance.

-- 
(let ((C call-with-current-continuation)) (apply (lambda (x y) (x y)) (map
((lambda (r) ((C C) (lambda (s) (r (lambda l (apply (s s) l))))))  (lambda
(f) (lambda (l) (if (null? l) C (lambda (k) (display (car l)) ((f (cdr l))
(C k)))))))    '((#\J #\d #\D #\v #\s) (#\e #\space #\a #\i #\newline)))))

_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to