-
Notifications
You must be signed in to change notification settings - Fork 1k
Use scala-cli in Getting Started page #3072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
23d6dda
0ff5ba0
0959275
a85e51e
8e84db6
57efc0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -145,6 +145,144 @@ To install them manually: | |||||||||||||
or [AdoptOpenJDK 8/11](https://adoptopenjdk.net/). Refer to [JDK Compatibility](/overviews/jdk-compatibility/overview.html) for Scala/Java compatibility detail. | ||||||||||||||
1. Install [sbt](https://www.scala-sbt.org/download.html) | ||||||||||||||
|
||||||||||||||
## Using the scala-cli command | ||||||||||||||
|
||||||||||||||
Create a file named `hello.scala` with following code: | ||||||||||||||
```scala | ||||||||||||||
@main | ||||||||||||||
def hello(): Unit = | ||||||||||||||
println("Hello, World!") | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
You can define a method with `def` keyword and mark it as a "main" method with the `@main` annotation, designating it as | ||||||||||||||
the entry point in program execution. The method's type is `Unit`, which means it does not return a value. `Unit` | ||||||||||||||
can be thought of as an analogue to `void` keyword found in other languages. The `println` method will print the `"Hello World!"` | ||||||||||||||
string to standard output. | ||||||||||||||
|
||||||||||||||
To run the program, execute `scala-cli run hello.scala` command. The file will be compiled and executed, with console output | ||||||||||||||
similar to following: | ||||||||||||||
``` | ||||||||||||||
$ scala-cli run hello.scala | ||||||||||||||
Compiling project (Scala 3.4.2, JVM (20)) | ||||||||||||||
gkepka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||
Compiled project (Scala 3.4.2, JVM (20)) | ||||||||||||||
Hello, World! | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
### Handling command-line arguments | ||||||||||||||
|
||||||||||||||
Let's rewrite the `hello.scala` file so that the program greets the person running it. | ||||||||||||||
|
Let's rewrite the `hello.scala` file so that the program greets the person running it. | |
Rewrite the `hello.scala` file so that the program greets the person running it. |
Same thing everywhere. The existing style of this page is to use imperative tenses for all the things the user should do. We should stick to that writing style.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def countFiles(): Unit = | |
val paths = os.list(os.pwd) | |
println(paths.length) | |
def countFiles(): Unit = | |
val paths = os.list(os.pwd) | |
println(paths.length) |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a real version number, for reproducible outputs. We definitely don't want this page's example to stop working when a new version of the toolkit gets released.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def countFiles(): Unit = | |
val paths = os.list(os.pwd) | |
println(paths.length) | |
def countFiles(): Unit = | |
val paths = os.list(os.pwd) | |
println(paths.length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this section should be removed, or moved to a separate page.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -160,38 +160,49 @@ package, so can be accessed from anywhere in a program. | |||||
|
||||||
> **Note:** The following assumes you are using Scala on the command line | ||||||
|
||||||
If we save the above program in a file called | ||||||
`HelloWorld.scala`, we can run it by issuing the following | ||||||
command (the greater-than sign `>` represents the shell prompt | ||||||
and should not be typed): | ||||||
|
||||||
```shell | ||||||
> scala-cli run HelloWorld.scala | ||||||
``` | ||||||
|
||||||
The program will be automatically compiled (with compiled classes somewhere in the newly created `.scala-build` directory) | ||||||
and executed, producing a similar output: | ||||||
|
and executed, producing a similar output: | |
and executed, producing an output similar to: |
("a similar output" in English refers to another output that was previously mentioned; there is no such thing here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a
// using
clause for the Scala version, for reproducible outputs.