Load Scala file into interpreter to use functions?

前端 未结 3 1904
执念已碎
执念已碎 2020-11-30 02:07

I have some Scala functions defined in a file, not in a class, and I would like to use them in the Scala interpreter. I know I can say scala filename.scala to s

相关标签:
3条回答
  • 2020-11-30 02:38

    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

    0 讨论(0)
  • 2020-11-30 02:51

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

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

    0 讨论(0)
  • 2020-11-30 02:54

    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
    
    0 讨论(0)
提交回复
热议问题