Load the Scala file into the interpreter to use functions?

I have some Scala functions defined in a file, not a class, and I would like to use them in a Scala interpreter. I know that I can tell scala filename.scala simply run the file and exit the interpreter, but I would like to run the file and then stay in the interpreter so that I can do some testing. Can someone tell me how easy it is to load the file into the interpreter so that I can use the functions defined inside it?

+64
scala interpreter
Sep 12 2018-11-11T00:
source share
3 answers

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

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

+87
Sep 12 2018-11-11T00:
source share

In some cases :paste can be your best friend (than :load ). Here is an example of 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 

You can also use :paste to download the file using the 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 
+10
Feb 11 '16 at 5:33
source share

Just remind, set the full path. I found the problem on Linux by following these steps:

: load ~ / fileName.scala

to get rid of the error "This file does not exist" I made

: download /complete/path/fileName.scala

+3
Dec 20 '15 at 14:25
source share



All Articles