Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!cernvax!chx400!chx400!ugun2b!ugun2a!defrance From: defrance@uni2a.unige.ch Newsgroups: comp.lang.scheme Subject: Re: Multiple return values Message-ID: <1991Apr4.104632.914@uni2a.unige.ch> Date: 4 Apr 91 08:46:32 GMT Organization: University of Geneva, Switzerland Lines: 68 (Doug Moen) debates in a previous posting about the Scheme multiple return value proposal and his counter-proposal. Here is my counter-counter-proposal: 1. (values x ...) The procedure 'values' takes an arbitrary number of arguments, including none, and returns all of these arguments as its results. 2. In a nested call, multiple values are bind to subsequent formal args: Suppose bar is a function with returns the three values 1 2 4 and foo a function with returns a b e.g. (define bar (lambda () (values 1 2 4)) (define foo (lambda () (values a b)) Then (+ (bar)) would return 7! That's quite powerful: Do you want the list of values? That's (list (bar)) But also (list (bar) (foo)) -> (1 2 4 a b) Only the first? (define firstval (lambda l (car l))) (firstval (foo)) -> a (firstval (bar) (foo)) -> 1 And also VERY elegant: (call-with-values producer consumer) is replaced by (consumer (producer)) (let ( ) ) can still be replaced by ((lambda ) ) : (let ((a b c) (bar)) (* (+ a b) c)) -> 12 which is actually equivalent to ((lambda (a b c) (* (+ a b) c)) (bar)) -> 12 It would have at least two (minor?) disadvantages. The first is that since you can't tell how many values an application will return, Scheme has to wait until all the actual parameters are evalued before binding the formals, or it has to force the order of evaluation. The second is that current mono-valued standard procedures cannot be redefined as multiple values procedures without affecting compatibility with previously written code (That could be an advantage, actually). Maybe the Scheme community can tell me if something is wrong with this proposal. Anyway, since this seems to be the only way for everybody down here to suggest things to the Scheme deciders, I'd like to have as much echo as possible on the net, if you like this idea of multiple values. Bye -Massimo --------------------------------------------------------------------------------- MASSIMO DE FRANCESCO email: massimo@cuisun.uinige.ch Computer Science Center University of Geneva, SWITZERLAND ---------------------------------------------------------------------------------