Using unicode variables in Scala tuple assignment

val ©® = 1
val (©, ®) = (1, 2)

Line 1 works fine in both Scalac and REPL, but on two lines on both.

This is mistake? Or is there a special syntax that I am missing?

Disclaimer: I know that using variable names other than ASCII is a terrible idea. I came across this in a complete accident. My code base is not full of stupid characters, I swear. Please do not lynch me :)

+4
source share
1 answer

Perhaps this helps:

scala> val (x, y) = (1, 2)
x: Int = 1
y: Int = 2

scala> val (X, Y) = (1, 2)
<console>:7: error: not found: value X
       val (X, Y) = (1, 2)
            ^
<console>:7: error: not found: value Y
       val (X, Y) = (1, 2)
               ^

, , unicode , , , , "" " ", , .

:

val © = 1
val ® = 3

(1, 2) match {
  case (©, ®) => "Both match"
  case (_, ®) => "Second matches"
  case (©, _) => "First matches"
  case _      => "None match"
}

res0: java.lang.String = First matches
+7

Source: https://habr.com/ru/post/1535660/


All Articles