Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!hsdndev!husc6!carlton From: carlton@husc10.harvard.edu (david carlton) Newsgroups: comp.lang.scheme Subject: Re: Multiple return values Message-ID: Date: 3 Apr 91 03:25:54 GMT References: <1991Mar26.155905.12906@daffy.cs.wisc.edu> <1991Apr1.181633.12561@snitor.uucp> Sender: news@husc6.harvard.edu Organization: Citizens for Boysenberry Jam Lines: 55 In-reply-to: jinx@zurich.ai.mit.edu's message of 2 Apr 91 18:57:22 GMT I guess that most of the questions that I have dealing with multiple return values are on how strictly the number of arguments returned should be enforced. That is, should the it be an error if the caller does not expect the number of values returned by the callee? There are, of course, two possibilities here: 1) Yes, they have to match. 2) No, they don't have to match. What are the pros and cons of each of these possibilities? The ones that I can think of are: 1) This is conceptually neater. After all, if the number of arguments in a function call has to match, then it is only sensible for the number of values in a function return to match. This also fits in quite well with the continuation passing way of looking at things, since function returns are function calls to the continuation. And it provides more error checking for your programs. 2) If they don't have to match then you can mimic the Common Lisp behaivour that Jinx wanted, namely to be able to drop unwanted additional return values. It is also a bit more efficient, requiring one fewer error check, but by the same token may open up another source of difficult-to-find errors. It allows procedures which currently return an unspecified value to return no value without breaking existing code, whereas requiring the number of arguments to match would screw up code which called such a function in a position requiring a value. That last statement itself needs elaboration - where would values be required in a Scheme program? (Assuming that we are following possibility #1, that checking this number is enforced.) In some cases, it is clear - for example, the first form in an 'if' statement should return one value. Presumably, all but the last form in a 'begin' statement should return no value. Though that itself is problematic - what if you call a function which performs a side effect _and_ returns a useful value? (append!, say.) Such a function clearly has to return a value, but you might also want to call it from the middle of a 'begin' statement. So perhaps it would be best to allow the forms in the middle of a 'begin' statement to return an arbitrary number of values. Similarly, the 'eval' part of a repl loop should be allowed to return an arbitrary number of values. (Never mind that the standard doesn't really admit the existence of a repl loop.) So what have I left out? Apologies if this posting seems a bit simplistic - I'm trying to figure out my opinion on these matters and the potential implications of my opinion as I write this, so it's not as polished as it might otherwise be. Which Schemes already implement multiple return values? T is the only one that I know of, but there must be more. What are the experiences of people using such systems? david carlton carlton@husc9.harvard.edu