Xref: utzoo comp.arch:10642 comp.lang.misc:3077 Path: utzoo!attcan!utgpu!watmath!watdragon!watyew!dwtill From: dwtill@watyew.waterloo.edu (Dave Till) Newsgroups: comp.arch,comp.lang.misc Subject: Multiple Return Values From Functions (was Re: Language Tenets) Keywords: multiple-valued expressions, function parameter lists Message-ID: <15141@watdragon.waterloo.edu> Date: 14 Jul 89 15:38:56 GMT References: <1207@quintus.UUCP> Sender: daemon@watdragon.waterloo.edu Reply-To: dwtill@watyew.waterloo.edu (Dave Till) Followup-To: comp.lang.misc Organization: Computer Science Department, University Of Waterloo Lines: 45 In article <1207@quintus.UUCP> pds@quintus.UUCP (Peter Schachte) writes: >All is not lost, though. In C, you can have > > divrem(top, bottom, "ient, &remainder) > >and something similar is possible with VAR parameters in Pascal (and >Modula-2, I think). This is symmetrical and reasonably elegant. More >elegant, I think, than complicating a language with multiple value >expressions without adding enough power to do anything other than assign >them to something. I think it would be more elegant to allow the returning of multiple values, as in [quotient,remainder] = divrem(top,bottom); because then it would be clear that "quotient" and "remainder" are return values, not input parameters or in-out parameters. Using multiple return values also allows the user to remove unnecessary dereferencing operations from the called function. >Basically, there's not much you can do with a multiple-value expression >except ignore all but the first value (which happens if you nest a MV >expression within a function call) and assign its results to variables. I may have misunderstood what you are saying here, but I disagree: I believe it is possible to use a multi-valued expression as part of a parameter list for a function call. In fact, I believe that a parameter list for a function call *is* a multiple-value expression. I am trying to determine the applications of multiple-value expressions and multiple return values from functions as part of my master's thesis work, and would be happy to discuss this by e-mail with anyone who is interested. (I have written a C preprocessor which implements constructs such as the above, and am trying to figure out how useful these constructs are.) Followups directed to comp.lang.misc, since this isn't really an architecture-related issue any more. -- --Dave Till, Computer Science Department, University of Waterloo (dwtill@watyew.waterloo.edu) ...!watmath!watyew!dwtill "Bottle, say after me, I must learn the difference between a lion and a spider." -- Eccles to Bluebottle, the Goon Show, "Ned's Atomic Dustbin"