How to save REPL session?

假如想象 提交于 2019-11-30 12:43:22
som-snytt

This is possible as of Scala 2.11. Example usage:

scala> 1
res0: Int = 1

scala> 2
res1: Int = 2

scala> 3
res2: Int = 3

scala> :save xxx

scala> :load xxx
Loading xxx...
res3: Int = 1
res4: Int = 2
res5: Int = 3

You can :reset before a :load to get correct references to results:

scala> 1
res0: Int = 1

scala> res0 + 1
res1: Int = 2

scala> :save xxx

later that day...

scala> 7
res0: Int = 7

scala> :reset
Resetting interpreter state.
Forgetting this session history:

7

Forgetting all expression results and named terms: $intp

scala> :load xxx
Loading xxx...
res0: Int = 1
res1: Int = 2

Note that you have in addition of the native Scala REPL the shell-scripting project Ammonite, which does have a Save/Loadd Session feature:

Apart from plain saves and loads, which simply discard everything after the most recent save, you can also provide a name to these functions.
That lets you stop working on a branch, go do something else for a while, and be able to come back later to continue where you left off:

@ val (x, y) = (1, 2)
x: Int = 1
y: Int = 2

@ sess.save("xy initialized")

@ val z = x + y
z: Int = 3

@ sess.save("first z")

@ sess.load("xy initialized")

@ val z = x - y
z: Int = -1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!