Introduction
The latest release of Gleam, v1.17, marks a significant milestone for developers working on the Erlang virtual machine. This update introduces the ability to create single-file Gleam programs using escript, greatly simplifying the distribution process. In this article, we will explore the details of this feature, its benefits, and how it can transform your workflow.
What is Gleam?
Gleam is a type-safe and scalable programming language designed for the Erlang virtual machine (BEAM) and JavaScript runtimes. Its goal is to provide a language that combines type safety with performance, essential for modern applications.
The Issue with Multiple Files
Traditionally, Gleam code is compiled into a series of .beam files, each containing bytecode for a single Gleam module. While this works well for programs distributed via package managers or containers, it can be cumbersome for small command-line programs.
Introduction of escript
In the JavaScript world, this problem is solved with 'bundlers' that combine multiple modules into a single executable file. Erlang offers a similar solution: escript. An escript is a single file containing all the modules of a program as pre-compiled bytecode, executable on any machine with Erlang installed.
The New gleam export escript Command
With Gleam version 1.17, the gleam export escript command is introduced. This command compiles the project, verifies the validity of a main function, and creates an escript file from the compiled bytecode. This greatly simplifies the process for Gleam developers.
Practical Example
Let's consider a simple Gleam project. After writing and testing your code, simply run the command:
`` louis ~/src/my_project $ gleam export escript ``
In seconds, your escript is generated, ready to be executed on any system with Erlang.
Other Enhancements
This update also brings IDE improvements, such as variable reference highlighting through the Gleam language server. This allows for easier navigation and understanding of your code.
Conclusion
Gleam v1.17 simplifies the creation and distribution of programs with escript, further cementing Gleam's position as an ideal language choice for the Erlang virtual machine. Whether you're a seasoned developer or new to the Erlang ecosystem, this feature will make your life easier.
Let's discuss your project in 15 minutes.