Skip to content

Commit 8d68bc0

Browse files
Add scripting docs
1 parent 6e7209f commit 8d68bc0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/docs/usage/getting-started.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,19 @@ In case you have already installed Dotty via brew, you should instead update it:
7474
```bash
7575
brew upgrade dotty
7676
```
77+
78+
### Scala 3 for Scripting
79+
If you have followed the steps in "Standalone Installation" section and have the `scala` executable on your `PATH`, you can run `*.scala` files as scripts. Given a source named Test.scala:
80+
81+
```scala
82+
@main def Test(name: String): Unit =
83+
println(s"Hello ${name}!")
84+
```
85+
86+
You can run: `scala Test.scala World` to get an output `Hello World!`.
87+
88+
A "script" is an ordinary Scala file which contains a main method. The semantics of the `scala Script.scala` command is as follows:
89+
90+
- Compile Script.scala with scalac into a temporary directory.
91+
- Detect the main method in the *.class files produced by the compilation.
92+
- Execute the main method.

0 commit comments

Comments
 (0)