Scala IDE - repl

Origin: https://www.assembla.com/spaces/scala-ide/wiki/Run_Selection_Interpreter  


Run Selection Interpreter

Starting with the beta 8 release of the version 2.0.0 Scala Development Tools, there is a new Scala Interpreter view (screenshot below). Features include stop interpreter, restart, replay, clear console, and replay on project rebuild.

Scala IDE - repl_第1张图片


An expression can be executed in the interpreter by selecting text in any Scala editor and either selecting the toolbar button (see screenshot) or by using the Ctrl+Shift+X key combination (Cmd+Shift+X on the Mac). The key combination can be changed by going to Keys -> Preferences and changing the binding for the command "Send Selection to Scala Interpreter"

Scala IDE - repl_第2张图片

Per-project Interpreters

On the first "Run Selection" on a file in a given project, a new interpreter session is created for that project, and code selected in any file in the same project will be run in the same session. The interpreter state can be reset by using the "stop" button in the Scala Interpreter view.

Scala IDE - repl_第3张图片

Interpreter Features

When a code selection is run in the interpreter, the code is shown in the view in a purple italic font with a gray background. Result and error output, as well as println statements, are displayed with a white background. This makes it easier to distinguish code and results in an interpreter session.

Toolbar Buttons

There are 5 toolbar buttons in the interpreter view: Replay All Commands, Terminate, Terminate and Replay, Clear Output, and Replay History on Project Rebuild (which is a toggle button).

Replay All Commands does not reload the classpath, but simple executes everything the current interpreter session.

26115018_K7aH.jpg

Terminate stops the interpreter session.

26115018_zKjz.jpg

Terminate and Replay resets the interpreter session (thus reloading classes) and re-executes all commands that have been entered.

26115019_fP70.jpg

Clear Console clears the interpreter view, but does not alter the interpreter session state.

26115019_9KJq.jpg

Replay History on Project Rebuild is a toggle button. If selected, interpreter history is replayed when the associated project is rebuilt.

26115020_BlCA.jpg

Expression Edit Bar

At the bottom of the interpreter view, there is an additional expression edit field. Here the user can execute expressions without typing in an editor window. The expression edit bar keeps a history of everything that has been typed into it, and the user may cycle through this history using the up/down arrow keys.

Scala IDE - repl_第4张图片

Note that features such as syntax highlighting, hyperlinking, completion, and multiline expressions are not available in the expression edit bar. In order to use such features, users should edit code in a regular Scala editor and use the toolbar button or key combination to run expressions.

Note: as of beta 8, "colon" commands (e.g., :implicits) that are available in the ordinary terminal REPL are not supported by the Run Selection interpreter, but this functionality will be present in the 2.0.0 final plugin.

Run Selection Interpreter versus Terminal REPL

The Run Selection interpreter provides a different form of interaction as compared with the terminal REPL, and this can be preferable in some usage scenarios. For instance, when typing directly in a REPL window, it is much harder to create an integrated transcript of all of the code that has been entered thus far, such as when values or definitions are changed. In contrast, when editing in a regular window. the user can keep the code in a consistent state and change definitions to match the current interpreter state. (For example, in the transcript def foo = "bar" then, much later, val foo = 42, the user must recognize that the meaning of the identifier foo has changed.)

Because of the document-oriented approach of this interpreter view, it is easier to create a final version of code based on testing in an interpreter session. Additionally, if you save the file in-between interpreter runs, Eclipse's local history will allow you to go back to previous versions.

Known Issues

·         Colon commands that are available in the terminal REPL are not supported.

·         The interpreter session cannot be forcibly killed, such as when it has entered an infinite loop or a long-running computation. A forcible interpreter stop will be available in the 2.0.0 final plugin.




转载于:https://my.oschina.net/u/854138/blog/110361

你可能感兴趣的:(Scala IDE - repl)