[Top][All Lists]

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

Re: [Chicken-users] Re: A few questions

From: John Cowan
Subject: Re: [Chicken-users] Re: A few questions
Date: Thu, 31 Jan 2008 23:47:22 -0500
User-agent: Mutt/1.5.13 (2006-08-11)

Elf scripsit:

> sorry, clarify what you mean by 'multiple arguments' then?

I mean neither more nor less than allowing procedures to have more
than one argument.  (I suspect you are reading "multiple arguments"
and interpreting it as "a rest argument".)

> >>values isnt a first-class object, its just a hack.
> >
> >Only in the sense that passing multiple arguments rather than allowing
> >just one (a list, not a curried function) is a hack.  If it's a hack,
> >it's pretty basic to Scheme and most other languages (excepting ML,
> >Haskell, and Q).
> its not basic to scheme, as it didnt exist pre-r5.

I worded that badly.  I meant to say that *multiple arguments* are basic
to Scheme and almost all other languages.

> its also not first-class:

Neither is multiple arguments.  The only language I know of where multiple
arguments and multiple values are first-class is Mesa, in which

        (x, y) = foo(1, 2, 3)

creates a record whose slot names are those of foo's formal arguments
and values are 1, 2, and 3 respectively, and which returns a record
whose slot names are likewise defined by foo and which is unpacked
by the callee (conceptually, at least) into the variables x and y.
You can use full record-literal syntax if you want, thus combining the
advantages of keyword and positional arguments, or even pass a record
stored in a variable of appropriate type.

> the most common cases of call-with-values that i see are for wrapping 
> macros and continuations where the return value(s) are not known beforehand,

Well, the more people write procedures that return multiple values
(typically a fixed number of them) the less this will be so.

> so i have a real question: can you give an instance of where multiple values
> (in the call-with-values sense) is clearly a space/time/efficiency/sanity/
> readability saver/improvement/benefit over some other means of return? 

Well, since I continue to hold that multiple values are the dual of
multiple arguments, I ask: is it clearly better for people to write (assoc
key alist) than (assoc (list key alist)) or (assoc (args key alist))?
I think so.  And I think that wherever a procedure naturally delivers
more than one result, it is better to do so directly as multiple values
rather than consing up an otherwise useless return object ad hoc, just
as it is better to transmit multiple arguments directly rather than
consing up an otherwise useless argument object.

> im honestly wondering where it would be used and more-or-less
> unambiguously determined a good thing

Well, quo+rem and sin+cos are classic examples, where the algorithm easily
and naturally delivers more than one result.  Unix pipe is another.

> im not trying to go nitpicking and ill try not to argue any point, its just
> that while i said earlier that there were clear cases, i havent been able 
> to think of one (except fork, but thats a different scenario altogether).

I started to say that I think the real answer is that most languages
don't have multiple values, and the ones that do, rarely use them, so
programmers are not used to thinking in terms of them.

But that answer lacks historical perspective.  The fact is, outside the
Lisps pure call by value is quite rare.  Languages commonly provide call
by reference, call by result, call by value result, or call by name --
all of which are basically syntactic sugar for returning multiple values,
one value per "output" argument.  Even Java, which has none of these
things, has mutable objects which can serve as boxes, as do many Lisps
and Schemes as nonstandard extensions.

Those features weren't put into non-Lisp languages from Fortran onwards
because the implementors thought they would be cool even though nobody
needed them for anything.

John Cowan  address@hidden
Arise, you prisoners of Windows / Arise, you slaves of Redmond, Wash,
The day and hour soon are coming / When all the IT folks say "Gosh!"
It isn't from a clever lawsuit / That Windowsland will finally fall,
But thousands writing open source code / Like mice who nibble through a wall.
        --The Linux-nationale by Greg Baker

reply via email to

[Prev in Thread] Current Thread [Next in Thread]