I'll take a stab.
Probably cos 'to' was chosen in cobra to act as the 'casting' operator ( from VB ?) to retype an object to something else up or down its inheritance or implementation hierarchy.
Personally I wouldnt say its advantageous to provide a language construct/operator to provide a mapping to a public library class conversion method unless you want to mask the Library access in some way especially given that language evolution has tended to be in the opposite direction (toward providing such capability via libraries directly rather than language builtins/RunTime Support systems)
and the range of possible conversions is arbitrarily large while the range of valid conversions is bounded.
- Code: Select all
# Invented examples and syntax...
a = foo to Window
# Cannot convert foo which is Type Array (of ?) to Type Window
a = foo to CheeseBurgaz
# Cannot convert foo which is Type Array (of ?) to Type CheeseBurgaz
a = foo to List
Note that you can get something close to your conversion (array to List) using a cast from an array to an IList (interface) since an array implements IList (directly or indirectly)
- Code: Select all
an = @[10,20,30] # array
al = an to Collections.IList
for item in al
print item