Jump to content

Command-line arguments: Difference between revisions

Added Scala
(Added Scala)
Line 495:
myprog a -h b c
=> ["a","-h","b","c"]
 
=={{header|Scala}}==
Calling Scala from command line means invoking a method called <code>main</code>, defined on an
<code>object</code>, whose type is <code>(Array[String])Unit</code>, meaning it receives an
array of strings, and returns unit. That array contains the command line arguments.
 
<lang scala>object T {
def main(args: Array[String]) {
println("Received the following arguments": + args.mkString("", ", ", "."))
}
}</lang>
 
When running a Scala script, where the whole body is executed, the arguments get stored in
an array of strings called <code>argv</code>:
 
<lang scala>println("My arguments are: "+argv.mkString("", ", ", "."))</lang>
 
=={{header|Scheme}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.