Ordiel
Ordiel

Reputation: 2633

Call scala script function

I have:

sum.scala

def sum(a : Int, b : Int) = println(a+b)

and I want to call that function from the CLI by doing something like:

scala sum.scala.sum(3, 4) 

Is that even possible?, and if so what is the syntax of the command that I need to type in the CLI to make it work?

I want to do it without creating an object to wrap the function.

Upvotes: 1

Views: 197

Answers (1)

Chris Martin
Chris Martin

Reputation: 30736

Run scala -help to see the CLI options.

The options you need here are:

-i <file>    preload <file> before starting the repl
-e <string>  execute <string> as if entered in the repl

Example:

> scala -i sum.scala -e "sum(3, 4)"
7

Upvotes: 3

Related Questions