Published 20 Sep, 2021 by Louis Pilfold
Gleam is a type safe and scalable language for the Erlang virtual machine and JavaScript runtimes. Today Gleam v0.17.0 has been released! Let’s take a look at some of the new changes.
Better code generation
The JavaScript code generated by the compiler has been redesigned making it easier to debug, easier to use from JavaScript, and to reduce generated code size.
The previous design would use JavaScript arrays and objects to create Gleam’s immutable data structures. This could be confusing when printed or when the code is read, and it was unclear how to create these data structures from JavaScript. Now the constructors can be imported and used like normal JavaScript code.
import { List, Ok, Error, inspect } from "gleam_package/gleam.js";
// Construct a list of results
let list = List.fromArray([
new Ok(1),
new Ok(2),
new Error("Oh no!"),
]);
// Print the list in Gleam syntax
console.log(inspect(list));
It is intended for Gleam code to be easy to use from other languages, so the developer experience of Gleam when writing Gleam or when writing other languages is something we want to always be improving.
Cross platform libraries
With the previous v0.16 release Gleam gained a new backend for the compiler that targets JavaScript, enabling Gleam to run anywhere JavaScript can run. With this release Gleam’s standard library and HTTP library have been updated to work both with Erlang or with JavaScript.
Erlang specific code in the standard library (such as the module for working with Erlang atoms) has been extracted out into the Gleam Erlang library.
For JavaScript a Gleam JavaScript library has been created with type safe bindings for arrays, mutable references, promises, and more.
JavaScript build script
When compiling to Erlang Gleam projects typically piggyback off of Erlang or Elixir by using their build tools rebar3 and mix. To give JavaScript based Gleam projects a way to get going a JavaScript build script has been created that can compile a project and its dependencies.
To see it in action along with the libraries above check out this micro Gleam serverless app deployed to CloudFlare Workers. See the app running here.
In future we will release the upcoming Gleam build tool which will replace this script along with mix and rebar3 for Gleam projects. ✨
Conditional compilation
To enable cross-platform libraries that work on both Erlang and JavaScript Gleam v0.17.0 introduces a limited form of conditional compilation. With this feature statements can be included or excluded from compilation based upon the compiler target.
In this code the current_target
constant is defined to an appropriate value
depending on the target.
if erlang {
pub const current_target = "Erlang"
}
if javascript {
pub const current_target = "JavaScript"
}
In addition to these this release also includes support for basic bit string
literals when compiling to JavaScript, support for patterns with the try
keyword, and a ton of bug fixes. For all the details check out the
changelog.
How can I try it?
Instructions on how to install the latest version of Gleam can be found on the getting started page of the website.
Once installed you can follow the guide for information on getting started compiling to Erlang, or this Gleam JavaScript template can be used for writing and running Gleam code on JavaScript.
The CloudFlare Workers template can be used if you’d like to try their serverless platform with Gleam.
Supporting Gleam
If you would like to support me in making Gleam please consider sponsoring Gleam or asking your employer to sponsor Gleam. Every donation makes a difference, no matter how small, so thank you for your help.
Thank you
Gleam is made possible by the support of all the people who have sponsored and contributed to the project. Thank you all!
- Adam Bowen
- Adam Brodzinski
- Adam Mokan
- Adi Iyengar
- alexander
- Alexander Flatter
- Ali Farhadi
- Andy Thompson
- Arno Dirlam
- Arto Bendiken
- Ben Marx
- Ben Myles
- Bruno Michel
- Chew Choon Keat
- Chris Lloyd
- Chris Young
- Christian Meunier
- clangley
- Cole Lawrence
- Colin
- Connor Lay (Clay)
- Cristine Guadelupe
- Damir Vandic
- Dan
- Dan Mueller
- Dave Lucia
- David Bernheisel
- David Flanagan
- David Lewis
- David Pedersen
- Dennis Dang
- Derek Mahar
- Edgar Gomes
- Edon Gashi
- Eric Meadows-Jönsson
- Erik Terpstra
- Florian Kraft
- Gitpod
- Guilherme de Maio
- Herdy Handoko
- human154
- Ian González
- Ilya Klyuchnikov
- Ingmar Gagen
- inoas
- Ivar Vong
- James MacAulay
- Jechol Lee
- Jeff Kreeftmeijer
- jiangplus
- Joe Corkerton
- John Palgut
- JohnDoneth
- Jonathan Arnett
- josh rotenberg
- José Valim
- João Veiga
- Jussi Norlund
- Kapp Technology
- Lars Lillo Ulvestad
- Lars Wikman
- Marcel Lanz
- Marcin Puc
- Marius Kalvø
- Mark Markaryan
- Markus
- Matheus Consoli
- Matthew McMillan
- Memo
- Michael Chris Lopez
- Michael Jones
- Michael Kumm
- Michał Kowieski
- Michał Łępicki
- Michele Riva
- Mike Lapping
- Mike Roach
- Milton Mazzarri
- Moritz Ploss
- Nick Reynolds
- NicklasXYZ
- NineFX
- OldhamMade
- Ole Michaelis
- Oliver Evans
- Parker Selbert
- Patrick Ryan
- Pete Jodo
- Peter Saxton
- porkbrain
- Praveen Perera
- qingliangcn
- Raphael Megzari
- Raúl Chouza
- Redmar Kerkhoff
- Reio
- René Klačan
- Robert Attard
- Robin Mattheussen
- Sam Aaron
- Sascha Wolf
- Saša Jurić
- Scott Wey
- Sean Jensen-Grey
- Sebastian Porto
- ShalokShalom
- Shane Sveller
- Shunji Lin
- silicium14
- Simone Vittori
- SkunkWerks GmbH
- Strand Communications
- Terje Bakken
- Tim Buchwaldt
- Tomasz Kowal
- Tomochika Hara
- Topher Hunt
- Tristan Sloughter
- tynanbe
- Utkarsh Kukreti
- Vladimir Kuznetsov
- Wilson Silva
- Wojtek Mach
- YourMother-really
- Yu Matsuzawa
- Zoo Sky
Thanks for reading! Have fun! 💜