[Gambas-user] Array.Sort
Tobias Boege
taboege at ...626...
Thu Jan 8 14:19:28 CET 2015
On Wed, 07 Jan 2015, Lewis Balentine wrote:
> Do I have it correct now ??
> The program runs and operates as expected.
> My concern is more to the proper nomenclature than function.
>
Array.Sort() is a *method* :-)
It rearranges the elements of the object it is applied to and returns that
object afterwards. That is, you will always have
aArray == aArray.Sort()
where == should be read as "are the same object", despite == not being a
Gambas operator (I use it here to distinguish between the same-object
relation and an assignment).
So, the actual work is done on the object you use to the method on and the
return value is just for brevity in certain applications like
Print aArray.Sort().Join(",")
' or
For Each sElt In aArray.Sort()
Print sElt
Next
' or
With EliminateSuccessiveDuplicates(aArray.Sort())
Print .Count;; "unique elements:"
For iInd = 0 To .Max
Print .[iInd]
Next
End With
If you want truly function-like semantics, then you can use the idiom
aArray.Copy().Sort()
Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list