Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the limitations and walkarounds of Scala interpreter?

What kind of constructs need 'scalac' compile and how to make an equivalent that will work in interpreter?

Edit: I want to use scala instead of python as a scripting language. (with #!/usr/bin/scala)

like image 215
Łukasz Lew Avatar asked Jan 22 '23 11:01

Łukasz Lew


1 Answers

You ought to be able to do anything in the REPL that you can do in outside code. Keep in mind that:

  • Things that refer to each other circularly need to be inside one block. So the following can't be entered as-is; you have to wrap it inside some other object:

    class C(i : Int) { def succ = C(i+1) }
    object C { def apply(i: Int) = new C(i) }

  • The execution environment is somewhat different, so benchmarking timings will not always come out the same way as if you run them from compiled code.

  • You enter the execution path a different way; if you want to call a main method, though, you certainly can from inside the REPL.

  • You can't just cut-and-paste an entire library into the REPL and have it work exactly like the library did; the REPL has a different structure than normal packages do. So drop the "package" declarations during testing.

like image 75
Rex Kerr Avatar answered Feb 23 '23 20:02

Rex Kerr