Gleam (programming language): Difference between revisions

Content deleted Content added
Added more secondary sources and more example code.
Line 35:
| website = {{URL|https://gleam.run/}}
}}
'''Gleam''' is a [[General-purpose programming language|general-purpose]], [[concurrent computing|concurrent]], [[Functional programming|functional]] [[High-level programming language|high-level]] [[programming language]] that compiles to [[Erlang (programming language)|Erlang]] or [[JavaScript]] source code.<ref name="Homepage" /><ref>{{cite news | url=https://www.infoworld.com/article/3713460/gleam-language-available-in-first-stable-release.html | title=Gleam language available in first stable release | first=Paul | last=Krill | work=InfoWorld | date=5 March 2024 | access-date=26 March 2024}}</ref>
 
Gleam is a statically-typed language,<ref>{{cite news | url=https://www.infoq.com/news/2024/03/gleam-erlang-virtual-machine-1-0/ | title=Erlang-Runtime Statically-Typed Functional Language Gleam Reaches 1.0 | first=Sergio | last=De Simone | work=InfoQ | date=16 March 2024 | access-date=26 March 2024}}</ref> which is different from the most popular languages that run on Erlang’s virtual machine [[BEAM (Erlang virtual machine)|BEAM]], Erlang and [[Elixir (programming language)|Elixir]].
 
== Example ==
Line 43 ⟶ 45:
pub fn main() {
io.println("hello, friend!")
}
</pre>
 
Gleam supports [[tail call]] optimization:<ref>{{cite web | url=https://tour.gleam.run/flow-control/tail-calls/ | title=Tail Calls | website=The Gleam Language Tour | access-date=26 March 2024}}</ref>
<pre>
pub fn factorial(x: Int) -> Int {
// The public function calls the private tail recursive function
factorial_loop(x, 1)
}
 
fn factorial_loop(x: Int, accumulator: Int) -> Int {
case x {
1 -> accumulator
 
// The last thing this function does is call itself
_ -> factorial_loop(x - 1, accumulator * x)
}
}
</pre>