question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blocks are top level in REPL (Scala 2 repl will assign the block to a variable)

See original GitHub issue

Compiler version

3.0.0-RC1

Minimized code + Output

$ scala
Welcome to Scala 2.13.6 (OpenJDK 64-Bit Server VM, Java 11.0.11).
Type in expressions for evaluation. Or try :help.

scala> { val local = 42 }

scala> local
       ^
       error: not found: value local

scala> 
:quit

$ scala3-repl
scala> { val local = 42 }
val local: Int = 42

scala> local                                                                                             
val res0: Int = 42

Expectation

Scala 3 in REPL should work as Scala 2 and as compiled Scala 3. The language ref says that local names are local and Scala 3 should give the same result above as Scala 2.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
smartercommented, Jun 18, 2021

Also, no matter what we do, the REPL will always have slightly different semantics than typing code in a file (e.g. if you type class X, then object X on the next line, that doesn’t define a companion), if this bothers you, I suggest teaching students using worksheets instead of the REPL (this is what the scala mooc does), worksheets are also somewhat magic but behave a lot more like regular code.

0reactions
bjornregnellcommented, Jun 18, 2021

@som-snytt That would be great! @smarter Yeah we talk alot about that you e.g in REPL can re-define the same name many times without compilation error but the students seem to grok quickly that this exception is convenient… I’ll have to live with “fixed in ammonite” ideals 😃 But nice with paste. I’ll redo my exercises on name space in REPL and open an object Locally: instead or even just a new hand-rolled def local = val invisibleOutside = 42 etc to show the name space thing. So there are workarounds of course. (But I still like regularity, buyt convenience is nice as well)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 2. Getting started - Scala in Action - liveBook · Manning
The objective of this chapter is for you to become comfortable with the basics of the Scala language and its environment so you...
Read more >
The Scala REPL | Scala Book
This page shares an introduction to the Scala REPL. ... The first variable is res0 , the second one is res1 , etc.:...
Read more >
Scala Tutorial - code blocks, coding style, closures, scala ...
The last line of that block is what the result of the overall mapValue for that element (here, indicated by the variable range)...
Read more >
3. Expressions and Conditionals - Learning Scala [Book]
An expression has its own scope, and may contain values and variables local to the expression block. The last expression in the block...
Read more >
Scratch tutorial on repl.it?... - Replit
This tutorial will give you the basics of D in one place. ... 6, 2020: Split the "Important data types and variables" section...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found