Create a new project:
gleam new some_name
Run a project (from inside the project directory):
gleam run
Syntax example:
import gleam/io
pub fn main() {
io.println("Hello, world!")
}
Printing to the command line can be done either with (e.g.) io.println
or the simple echo
keyword (which also prints the line):
import gleam/io
pub fn main() {
io.println("Hello, world!")
echo "Hello, world!"
}
Import parts of the standard library:
import gleam/float
import gleam/int
import gleam/string
pub fn main() {
echo string.reverse("Hello, world!")
echo int.max(234, 567)
echo float.max(2.34, 5.67)
}
One really horrible thing is: there are different operators for working with integers and floats. For example, the simple +
can be used with integers but not with floats; instead, floats must be added with +.
, like this:
pub fn main() {
echo 234 + 567
echo 2.34 +. 5.67
}
Strings:
<>
pub fn main() {
echo "foo" <> "bar"
echo "
This is
a multi-line
string.
"
}