Start from a main routine: Difference between revisions
Content deleted Content added
Adds Clojure section |
Scala added |
||
Line 194: | Line 194: | ||
A program may include multiple BEGIN and END blocks. BEGIN blocks are executed in the order they are encountered. END blocks are executed in reverse order. |
A program may include multiple BEGIN and END blocks. BEGIN blocks are executed in the order they are encountered. END blocks are executed in reverse order. |
||
=={{header| |
=={{header|Scala}}== |
||
[[Category:Scala Implementations]] |
|||
⚫ | |||
{{libheader|Scala}} |
|||
===No kidding and trickery=== |
|||
In Scala there are two concepts not available in another OO-languages e.g. Java. The concepts are <code>object</code> and <code>trait</code>. Both cannot have parameters. <code>object</code>'s are singletons (one and only one instance of a parameter-less class) and are static. Exactly the same as a <code>main</code>. By use of the <code>trait App</code> a main method is preprogrammed and brought in an <code>object</code> which can be called on the command-line. There are more the one different <code>object</code>'s possible each can be called by his object name on the command-line. In the trait <code>executionStart</code> field is initialized with the starting time. By submitting an <code>-Dscala.time</code> argument on the command-line the execution time can be reported. The field <code>executionStart</code> can also programmatically used. |
|||
{{out|Example}}<lang scala>object PrimaryMain extends App { |
|||
Console.println("Hello World: " + (args mkString ", ")) |
|||
} |
|||
object MainTheSecond extends App { |
|||
<lang sed># This code runs only for line 1. |
|||
Console.println("Goodbye, World: " + (args mkString ", ")) |
|||
}</lang> |
|||
=={{header|sed}}== |
|||
⚫ | A <code>sed</code> program repeats itself for each line of input, but your program can begin with commands that address line 1. (This requires that your input has a line 1. If your input is empty file, like <code>/dev/null</code>, then it is impossible to run commands.)<lang sed># This code runs only for line 1. |
||
1 { |
1 { |
||
i\ |
i\ |