Skip to content

REPL predef functionality #17694

@mpollmeier

Description

@mpollmeier

The REPL currently doesn't have predef functionality, i.e. the ability to execute some code automatically on startup. I didn't find this being discussed or worked on. I happen to have that need, and this was asked on Discord in the past.

The below suits my needs, but I thought it might make sense to bring this into the standard repl, e.g. as a parameter, since it's a fairly common functionality of a repl.

import dotty.tools.repl._
val repl = new ReplDriver(replArgs)
val predefCode =
  """
    |def foo = 42
    |import Int.MaxValue
    |""".stripMargin
val state = repl.run(predefCode)(repl.initialState)
repl.runUntilQuit(state)

For reference: Ammonite has are three distinct ways to pass predef code:

  • ~/.ammonite/predef.sc - runs every time this user starts ammonite
  • amm --predef-code 'def foo = 42'
  • amm --predef someFile.sc

Would you be open to a contribution that adds a predef functionality to the REPL, or is the intention to keep the repl as small as possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions