Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run an external file from within the scala interactive interpreter (REPL)?

I have a file with several lines of scala code -- imports, list value assignments, etc. that I often use to initialize some things when using the REPL.

Currently I just open up the file in a text editor and copy-and-paste it into the REPL, but is there a way to do it by calling the external file in a more direct manner so I don't have to copy-and-paste every time?

In some interactive database tools like SQL Plus, it is done by typing @filename at the prompt. Is there something similar in the Scala REPL? Preceding the filename with @ doesn't work, eval doesn't work either.

like image 317
Gigatron Avatar asked Mar 05 '12 02:03

Gigatron


1 Answers

Type:

:help

and you see, that

:load <path>               load and interpret a Scala file

solves your problem.

In some circumstances, pasting the code might be preferable though, but then

:paste

might be your friend then. It helps inserting a whole block without feedback, line by line, until you hit Ctrl + D. In some cases this is significant for the code interpretation.

like image 154
user unknown Avatar answered Oct 12 '22 22:10

user unknown