This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: values (Re: R5RS)
On Mon, Feb 28, 2000 at 03:52:26PM -0500, Jim Blandy wrote:
> Going cheerfully but completely off-topic: sure. But I don't consider
> using Scheme's data structures as containers for arguments and return
> values to be practical, because it's so inconvenient. It's simply
> nicer to write
>
> (define (fetch type source) ...)
>
> than
>
> (define (fetch . args)
> (let ((type (car args))
> (source (cadr args)))
> ...))
>
> I mean, really. Whereas in ML, it's just
>
> fun fetch (type, source) = ...
>
> The ( , ) syntax is *not* specifically for function arguments. It's
> the syntax for building tuples.
> [...deleted]
> Then I can say:
>
> let val (quotient, remainder) = divide (a, b)
> in ...
>
> You get multiple return values in a completely natural, consistent,
> and convenient form.
That sort of thing would be useful, but a new data type isn't
necessary. Perhaps you could add something like a list binding macro,
where you bind elements in a list to variables. Like, if we called it
"list-let", it could look like this:
(define (l)
'("First" "Second" "Third"))
(list-let (a b c) (l)
(display a) (newline)
(display b) (newline)
(display c) (newline))
and you'd get:
First
Second
Third
If the list you're using is too short, just plug in empty lists (or maybe
#f) for the remaining variables; if the list is too long, the extra list
elements are ignored.