arrays of nilable single; Array.copy method
Posted: Mon Feb 18, 2013 1:53 pm
1)
on the two lines of code above that include the word "nil", the compiler balks and complains that i'm trying to assign (or evaluate) nil to a float32. i thought, but obviously am mistaken, that my numerator, denominator and quotient were all declared as arrays of type nilable float32?. where did i go wrong, please?
2)
in pursuit of the ".copy" method, why must i cast type today and yesterday to type "Array"? why doesn't array of "float32" have its own .copy method? what is type "Array"? in short, can someone please point me to a link that explains the difference between type "Array" and one of the specific array types like float32[] ? i can't find a discussion of the difference, because no doubt i'm looking for the wrong words or concepts, or perhaps I'm not properly grasping an inheritance issue. thanks.
- Code: Select all
def arrayDivision( numerator as float32[]?, denominator as float32[]?) as float32[]?
assert numerator.length == denominator.length
quotient = float32[](numerator.length) to ? #proper cobra instantiation of array of nilable singles?
for i in numerator.length
if numerator[i] == nil or denominator[i] == nil
quotient[i] = nil
else
quotient[i] = numerator[i] / denominator[i]
return quotient
on the two lines of code above that include the word "nil", the compiler balks and complains that i'm trying to assign (or evaluate) nil to a float32. i thought, but obviously am mistaken, that my numerator, denominator and quotient were all declared as arrays of type nilable float32?. where did i go wrong, please?
2)
- Code: Select all
def doSomething( today as float32[]? ) as float32[]?
yesterday = float32[](today.length) to ?
Array.copy(today to Array, 1, yesterday to Array, 2, today.length - 2)
return yesterday
in pursuit of the ".copy" method, why must i cast type today and yesterday to type "Array"? why doesn't array of "float32" have its own .copy method? what is type "Array"? in short, can someone please point me to a link that explains the difference between type "Array" and one of the specific array types like float32[] ? i can't find a discussion of the difference, because no doubt i'm looking for the wrong words or concepts, or perhaps I'm not properly grasping an inheritance issue. thanks.