Does anyone know if it is possible to start a new lexical scope and if so how?
Naive use of a colon does not seem to work, even when I use the -Yindent-colons
options.
TIA
Does anyone know if it is possible to start a new lexical scope and if so how?
Naive use of a colon does not seem to work, even when I use the -Yindent-colons
options.
TIA
If you don’t want to use braces you could use the locally
function. It already exists in Scala 2 to overcome issues with defining local code blocks with just { }
.
$ bin/scala -Yindent-colons
Starting scala3 REPL...
scala> def foo =
| val a = 1
| locally:
| val a = 2
| println(a)
| println(a)
|
def foo: Unit
scala> foo
2
1
Wow. Was not aware of this. Thank you.