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.

26115015_t8ml.jpg


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"

26115015_qkQB.jpg

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.

26115016_zKSY.jpg

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.

26115020_9sov.jpg

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值