The way I've always thought that multiple returns could be handled would
be like this:
Declare the function:
Function do_something( myParam As Integer ) As Integer, Dictionary
Then, to use the function would be like this:
Function do_something( myParam As Integer ) As Integer, Dictionary
Dim d As New Dictionary
d.Value( "james" ) = myParam
// And now to return two values:
Return 1, d
End Function
Then, to receive two values would look like this:
Dim i As Integer
Dim d As Dictionary
i,d = do_something( 500 )
In the same way that parameters are ordered, so are the return values.
So, to use them in a comparison would look like this:
If do_something( 6504 ) > 500, <> Nil Then
MsgBox "Great!"
End If
I agree that it complicates the syntax, but I think it would be
feasible. It simply means that the "expression" would not be complete
until all the return values have been handled.
The question is, would this really be useful, or should people just
return a structure or class object that can contain multiple values.
I mean, that is one of the reasons to return a class object, because you
can essentially return multiple values in a nice object.
My vote is that this is basically unnecessary and would just be a new
area for problems to arise.
- Ryan Dary
Norman Palardy wrote:
> On Mar 23, 2007, at 3:20 PM, Charles Yeomans wrote:
>
>> Well, Perl appears to find everything a useful feature. Perhaps the
>> ability to return multiple values could be useful, but I am not
>> entirely convinced. Consider your example of returning lists of
>> words and counts for each word in a string. On grounds of
>> efficiency, it would almost certainly be better to be able to compute
>> and return both at the same time. But perhaps the better way to do
>> it would be to introduce an object to represent the concept of a word
>> count -- a dictionary with a more focused interface.
>>
>> One reason I would not find convincing would be the ability to return
>> both a function result and an error code; that still has the usual
>> problems that come with returning error codes.
>
> Syntax and usage would /could be complicated
>
> How would you use it in a case like
>
> if FunctionReturningAndIntAndString() = ? then
>
> which item gets used as the part of the comparison ?
> The first returned value ?
> The one that matches the type ?
>
>
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>
>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>