Load Scala file into interpreter to use functions?

点点圈 提交于 2019-11-27 07:02:21

type :load /path/to/file in Scala REPL.

You can get complete list of available commands by typing :help

Suresh Babu

On occasions, :paste might be your better friend (than :load). Here is an example on how to use :paste.

scala> :paste
// Entering paste mode (ctrl-D to finish)

if (true)
  print("that was true")
else
  print("false")

[Ctrl-D]

// Exiting paste mode, now interpreting.

that was true

One can also use :paste to load a file using following command :paste [path]

scala> :paste ~/Desktop/repl_seeder.scala
Pasting file ~/Desktop/repl_seeder.scala...
defined object test1

scala> test1.main(Str)
my first scala program

Just reminder, put the complete path. I found problem in Linux by doing like this:

:load ~/fileName.scala

to get rid of error "That file does not exist" I did

:load /complete/path/fileName.scala

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