On Mar 23, 2007, at 4:28 PM, Chris Little wrote: >>> Functions should return one value. >> > I agree that being able to return multiple values would be useful. > I'm not > sure I like how you've proposed it. Coming from a C++ background > the classic > solution is to return a tuple or a result object. This keeps the > return > syntax the same. I didn't see in your FR how you would return the > multiple > values or how you would assign them at the point of calling. Could you > provide an example of what you have in mind?
Multiple lvalues would be allowed on an assignment: words(), counts() = CountWords(someString) A function can declare multiple return values: Sub CountWords(s As String) As string(), integer() If the number of lvalues differs from the number of return values, then: - if there are more lvalues, the excess values are Nil/0/""/etc - if there are excess return values, the excess are ignored. Notice that these semantics lets the function return values in the order that is most useful. CountWords then doubles as a handy "unique words" function: uniqueWords() = CountWords(someString) There is also no problem with nested function calls: the first value returned is passed to the outer functions: x = SomeFun(CountWords(SomeString)) It would be handy if the function result can also be treated as an array: wordCounts = CountWords(someString)(1) but REALbasic currently doesn't support that kind of call even on a regular function that returns an array (try it). Regards, Guyren G Howe Relevant Logic LLC guyren-at-relevantlogic.com ~ http://relevantlogic.com REALbasic, PHP, Ruby/Rails, Python programming PostgreSQL, MySQL database design and consulting Technical writing and training _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives: <http://support.realsoftware.com/listarchives/lists.html>
