com-lihaoyi / Ammonite

Scala Scripting
http://ammonite.io
MIT License
2.6k stars 367 forks source link

Definitions not available from repl.load.exec in home predef #658

Open ches opened 7 years ago

ches commented 7 years ago

I noticed the entry in the release notes of 1.0.0 (congrats on the release 🎉 ):

interp.load.exec and interp.load.apply have been moved to repl.load.exec and repl.load.apply, and are now not available when running scripts: they never had a really well-defined semantic when run within scripts. Using repl.load.exec or repl.load.apply within the predef.sc of your REPL is still possible

I updated my predef.sc accordingly and the file I exec is executed, but its definitions aren't available in the REPL session as expected. My predef.sc is as follows:

repl.prompt() = "\n> "
interp.configureCompiler(_.settings.nowarnings.value = false)

// Load utility definitions I share with default scala REPL
try repl.load.exec(ammonite.ops.home/".config"/'scala/"replinit.scala")
catch { case _: Exception => println("=== replrc not loaded! ===") }

If the replinit.scala contains this:

println("===== Running replinit exec =====")
val accessible = "yay"

Then:

$ amm
Loading...
Compiling /Users/ches/(console)
===== Running replinit exec =====
Welcome to the Ammonite Repl 1.0.0
(Scala 2.12.2 Java 1.8.0_112)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi

> accessible
cmd1.sc:1: not found: value accessible
val res1 = accessible
           ^
Compilation Failed

> repl.load.exec(ammonite.ops.home/".config"/'scala/"replinit.scala")
Compiling /Users/ches/(console)
===== Running replinit exec =====

> accessible
res3: String = "yay"
lihaoyi commented 7 years ago

huhh i thought i made it work, clearly i must've messed up somwhere. Thanks for the report!