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

Re: [Scheme-reports] multiple values module

Eli Barzilay scripsit:

> IMO implementations that do some half-baked reification of multiple
> values as first-class values are broken.  Things like (list (values 1
> 2) 3) or (define x (values 1 2)) should throw an error.

Well, you can write a conformant implementation that does so.  Or you
can have one that does it CL-style.  Or you can use a unique type, or
even a non-unique type.  Because multiple values are only conformant in
specific contexts, *all* of those implementations, with their different
tradeoffs, are allowed, and portable programs don't have to care about
the differences.  Chibi's use cases just aren't anything like Racket's.

Ultimately, if you want R6RS, you know where to find it.

> > Chibi actually implements multiple purely in Scheme by returning a
> > list with a unique CAR, which prints as "(value)".
> Ugh.  If the above is broken, then this is a train wreck.

Remember that Chibi is intended to be small in code size and storage
space, but not necessarily fast.  Here's the total 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))))

Completely conformant.  If you use multiple values anywhere else, you'll
get the implementation showing through, of course.  So it goes.

> I'm sure that there are reasons for implementing things this way, but
> making an argument out of it sounds insane.  (Or a camouflaged attemt
> to make multiple values so useless that it's as if they're not in...)

On the contrary.  It is an argument that multiple values belong in
the core, because even the tiniest conformant implementation *can*
provide them.

Eric Raymond is the Margaret Mead               John Cowan
of the Open Source movement.                    cowan@x
        --Bruce Perens,                         http://www.ccil.org/~cowan
          some years ago

Scheme-reports mailing list