Justice's Blindfold (5) [Avatar] Offline
#1
It may be my version of Scala that I'm running, but...

On pages 68-69, we've created a local function called rSize, with a capital 'S', but are calling it from the caller's function (would it be appropriate to say: "the global function"?) size as rsize, with a lowercase 's'. On my version of Scala, that doesn't work.

One weird thing I found playing around. The size(Array('a')) returns an Int of 1, even though we have explicitly defined size to take an Array of Int, and Array('a') is explicitly an Array of Char. But size(Array("abc")) fails like I expected it to.
aslam.khan (50) [Avatar] Offline
#2
Re: rsize
Hi there

rsize should be rSize. That's a typo. So, it's nothing to do with versions.

Regarding size(Array('a')) working and size(Array("abc")) failing...
size() expects a param of type Array[Int]. When you pass in an Array[Char], then Scala does an implicit type conversion of Char to Int. In Scala, Char is an unsigned 16 bit integer. However, Array("abc") is of type Array[String] which Scala cannot implicitly convert to Array[Int].

I'm thrilled to see you playing around with the examples in the book like this. Messing around in the REPL is a great way to learn.