1

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.

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

Not as "smooth" as I would have liked it to be but it works. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.