Skip to content

Conversation

@lihaoyi
Copy link
Contributor

@lihaoyi lihaoyi commented Oct 26, 2025

Possibly the last feature to port from Ammonite, as documented at https://ammonite.io/#Embedding. Can be used via

dotty.tools.repl.ReplMain().run(
  "key1" -> value1,
  "key2" -> value2,
  ...
)

We basically wrap the ReplDriver in a convenient ReplMain class that lets you call .run and pass in a bunch of (String, Any) key value pairs, with some implicit macros to also capture the type names. ReplMain stores these in a threadlocal Map[String, Any] and generates a REPL predef that reads the threadlocal map and assigns them to local defs in the REPL

Like Ammonite's implementation, this doesn't handle more sophisticated use cases like binding types or binding path-dependently-typed values. But for most day-to-day use it should be enough

Covered by unit tests, and tweaked runUntilQuit slightly to allow an optional hardcodedInput: java.io.InputStream to be passed to simplify testing

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant