Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazy vals aren't lazy in the REPL #1655

Closed
scabug opened this issue Jan 20, 2009 · 4 comments
Closed

lazy vals aren't lazy in the REPL #1655

scabug opened this issue Jan 20, 2009 · 4 comments
Assignees

Comments

@scabug
Copy link

scabug commented Jan 20, 2009

because the interpreter immediately uses the value in order to print it:

  ~> scala
Welcome to Scala version 2.7.3.final (Java HotSpot(TM) Client VM, Java 1.5.0_16).
Type in expressions to have them evaluated.
Type :help for more information.

scala> lazy val x = 3
x: Int = 3

this might seem like a fairly trivial issue, but I think it has potential to confuse people who are trying stuff out in the REPL in order to understand the language.

@scabug
Copy link
Author

scabug commented Jan 20, 2009

Imported From: https://issues.scala-lang.org/browse/SI-1655?orig=1
Reporter: @SethTisue
Attachments:

@scabug
Copy link
Author

scabug commented Jan 20, 2009

Geoffrey Alan Washburn (washburn) said:
After some quick investigation this looks like it might be feasible. However, I won't have time to work on this myself, so I am going to assign it to scala_community. Whenever the REPL gets a new owner, they can consider whether to tackle this enhancement.

@scabug
Copy link
Author

scabug commented Feb 3, 2009

@paulp said:
I have implemented this, patch attached.

scala> lazy val x1 = { println("I'm a lazy x1") ; 5 }
lazy val x1: Int = <deferred>

scala> lazy val x2 = { println("I'm a lazy x2") ; 55.3 }
lazy val x2: Double = <deferred>

scala> x2 + x1
I'm a lazy x2
I'm a lazy x1
res0: Double = 60.3

scala> x2 + x1 + 5
res1: Double = 65.3

I thought I'd be able to just dash it off but it was harder than I thought -- though the final patch only adds a net of five lines to the interpreter, I'm sure I had 100-150 lines going at the peak. At least I learned a lot about the repl along the way. Please let me know if this is inadequate and I'll do whatever else is needed.

@scabug
Copy link
Author

scabug commented Feb 6, 2009

@paulp said:
Implemented in r17050.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants