Is there a quick way to show the code of a method declared in the Scala Console?

霸气de小男生 提交于 2019-12-23 09:05:36

问题


I frequently use the Scala console to evaluate and test code before I actually write it down in my project. If I want to know the contents of a variable, I can just enter it and scala evaluates it. But is there also a way to show the code of methods I entered?

I know there's the UP-key to show single lines, but what I was searching for is to show the whole code at once.


回答1:


There's a file in your home directory named .scala_history that contains all of your recent REPL history. I regularly copy and paste code from this file into project source files. It's not exactly the same as showing the code for individual methods in the REPL, but it might help you accomplish the same goals.

See the comments by Paul Phillips in this issue for a discussion of some related functionality in the REPL (grouping statements in the history):

At some point I implemented the logic for this, but the real obstacle is jline. It has enough trouble figuring out where the cursor is under the simplest conditions. Start throwing big multiline blocks into the history and it breaks down in tears. Would love to see this and SI-2547 addressed by the community.

...

I expect to fix this soon too, but it depends on how well the recent jline work goes. I implemented it long ago, and display issues are the impediment.

Both of these comments are over two years old, so I wouldn't hold your breath.




回答2:


I dont know a command to load all the code from command line. What you can do is to :load path/to/my/file.scala to load some complex code and re- :load it when you changed the code in the file.



来源:https://stackoverflow.com/questions/11561719/is-there-a-quick-way-to-show-the-code-of-a-method-declared-in-the-scala-console

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