-
Notifications
You must be signed in to change notification settings - Fork 132
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
Support for initial commands in REPL #604
Comments
I'm not sure the Scala 3 REPL allows to specify initial code like this though (might be the same with the Scala 2 one). |
I am reading the documents for ammonite. It’s just that I don’t understand what initial commands are. Do you want scala-cli to support something like magic imports in ammonite ? |
You mean something like
|
Hi @lwronski so you mean using those commands for configuring scala-cli to import or open your preferred files in the current execution of repl or some other initial command in the string? Is it what you want me to implement? |
Don't know if that's what @lwronski is thinking about, but I think we'd want to use the For |
@zmerr If you run
so it would be great if it worked like this:
if that's not possible for Scala 2/3 REPL, then we can add this option only for Ammonite REPL
|
@lwronski Awesome. Now I got what it is that you actually want me to do. I am just curious, why are you still adding Hello.scala to the command, when you are already importing Hello.*? Sorry I am new to this. |
@lwronski I mean why not this:
or
|
If you run REPL without the source files, you have REPL without any loaded classes.
|
@lwronski thanks. So making it work that way, requires making change to repl as well. |
In scala 3 if you write your init script like this export Hello.* and you run val xxx = println("Hello") nothing will be printed until I type |
I've found one limitation of my solution: wildcard exports work correctly with objects but not with packages. |
@prolativ @Gedochao I tried to find among issues in dotty a discussion about export not working for packages. I think it really should, if possible, as I think that feature is very useful. Do you perhaps know where to find any potentially existing discussions about exporting top-level package members also, not just object members? This will allow init repl stuff to be used via scala-cli repl --scala-snippet as discussed in #1853 |
To make things clear: named exports from packages do work - only wildcard exports don't. I assume that's because of complications wildcard imports from packages would bring to incremental compilation. E.g.: // File1.scala
package pkg1
val x = "a" // File2.scala
package pkg2
export pkg1.* Now when this codebase gets compiled and a new file appears: // File3.scala
package pkg1
val y = "b" then the compiler would have to figure out that |
Thanks for the clear explanation @prolativ! So it's a trade-off between being restrictive or risk long compilation times. I guess my view is that if I introduce wild-card package exports then I want it, even if compilation times get higher. It would be nice though if the compiler or build tool gave me a warning that wildcard exports of packages may trigger a complete re-compilation when new files are added and thus increase compile times. |
I would say it's not only about longer compilation times but also about correctness of code, unless we give up incremental compilation and compile everything from scratch each time, which is most likely not what we would like in general. |
Aha! That makes sense. |
It seems like most of the benefits of an initial script ran in the beginning of Still, it'd be great to cover this edge case from Scala CLI's side, which would require supporting an initial script ran at the beginning of Also, this could be a good argument for spending more time on improving the repl itself - if the |
Thanks for the update @Gedochao ! Yes, ramping up the api of the REPL to make it more versatile would indeed be a nice thing! I think the Scala 3 REPL should have an api that let's it be embedded in an easy way, similar to how the |
Closing as duplicate of #604 with more recent discussion |
Is this a duplicate of itself :) or did you mean to link to another issue? @tgodzik |
I meant this #2185 😅 |
I'm not sure this is a duplicate of #2185 ; that issue is (also) about the I think being on feature parity with the sbt setting console / initialCommands := """import stuff.*""" The above works also for Scala 3. The use case is to prevent tedious re-typing of lot's of imports in every repl session. Should I open another issue or should we re-open this? I think it is important that this use case is not "forgotten". Also it might be easier to solve allowing pre-REPL import rather than supporting all the stuff discussed in #2185 so a seperate issue for the import use-case might make sense? |
Agreed, I think a new issue makes sense, given the number of different things that were discussed here and in #2185. |
OK I'll make a new issue soon and link to the other issues. |
Is your feature request related to a problem? Please describe.
Support for running initial commands for REPL
Describe the solution you'd like
Adding a flag to specify initial commands. It can be supported in two ways:
The text was updated successfully, but these errors were encountered: