Skip to content

Words about Predef in REPL #1077

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

Merged
merged 1 commit into from
Jun 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions _overviews/repl/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,47 @@ The REPL also provides some command facilities, described below.
An alternative REPL is available in [the Ammonite project](https://github.com/lihaoyi/Ammonite),
which also provides a richer shell environment.

### Features

Useful REPL features include:

- the REPL's IMain is bound to `$intp`.
- the REPL's last exception is bound to `lastException`.
- use tab for completion.
- use `//print<tab>` to show typed desugarings.
- use `:help` for a list of commands.
- use `:load` to load a file of REPL input.
- use `:paste` to enter a class and object as companions.
- use `:paste -raw` to disable code wrapping, to define a package.
- use `:javap` to inspect class artifacts.
- use `-Yrepl-outdir` to inspect class artifacts with external tools.
- use `:power` to enter power mode and import compiler components.
- use `:settings` to modify compiler settings; some settings require `:replay`.
- use `:replay` to replay the session with modified settings.

Implementation notes:

- user code can be wrapped in either an object (so that the code runs during class initialization)
or a class (so that the code runs during instance construction). The switch is `-Yrepl-class-based`.
- every line of input is compiled separately.
- dependencies on previous lines are included by automatically generated imports.
- implicit import of `scala.Predef` can be controlled by inputting an explicit import.

**Example:**

scala> import Predef.{any2stringadd => _, _}
import Predef.{any2stringadd=>_, _}

scala> new Object + "a string"
<console>:13: error: value + is not a member of Object
new Object + "a string"
^

scala> import Predef._
import Predef._

scala> new Object + "a string"
res1: String = java.lang.Object@787a0fd6a string

### Power Mode

Expand Down