On Mar 22, 2007, at 11:31 PM, Guyren Howe wrote:
> On Mar 22, 2007, at 11:52 PM, Guyren Howe wrote:
>
>> <http://www.realsoftware.com/feedback/viewreport.php?
>> reportid=gvzcbkhx>
>>
>> Allowing a function to return multiple values:
>>
>> Dim WordCounts(s As String) As Words() As String, Counts() As Integer
>>
>> would be immensely useful and more beginner-friendly.
>
> Also worth mentioning that all of the recently-popular "new"
> languages (PHP, Python, Perl, Ruby) support multiple returns from a
> function. It's really not that scary.
As well as classic languages such as C and Pascal.
And all API's from various operating systems. For example, many Apple
Functions return data "by reference" and an error or status code for
the value of the function, where, for example, status of NoError
means the data is valid. Consider, from Apple's Carbon Library, the
pascal call:
FUNCTION FSRead(refNum: INTEGER; VAR count: LONGINT; buffPtr: UNIV
Ptr): OSErr;
Where:
refNum is a reference to an open file (like a FolderItem)
count (a 32 bit Integer) is passed in as the desired number of
bytes and returned as the actual number of bytes read,
buffPtr (address of a MemoryBlock) is allocated by the caller
and to be filled with the data requested,
the function return of OSErr is an integer understood as an
error code.
So the big boys "return" or modify multiple variables on a single
call, the Question I guess is clarity of syntax... the ByRef
construct appears the clearest to me, BUT, I am a grizzled Pascal
grunt. Seems to me that the proposed syntax above would make it
confusing to create RB equivalents to Mac API's (Declares); you would
still need ByRef, such as:
FUNCTION FSRead(refNum as INTEGER, byref count as INTEGER, buffPtr as
MemoryBlock) as INTEGER
There are only two things for sure in a programmer's life : bugs and
syntax... :-)
gary
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>