Gleam @FOSDEM 2023

Feb 5, 2023   Kero van Gelder

A little Report

4 gleamers identified in a big room (up to about 100 people).

There was interest in Gleam, judging from the questions on Harry's and Hayleigh's talk: When will v1.0 be there? Is there an XYZ library for in the browser?

Intro into Elixir — Tonći Galić

Elixir has Ruby syntax and piping. And macros. Also introduced hex to make package management easier (good for us gleamers to know some history). Docs accessible from REPL and other places. Culture to welcome newcomers.

Mentioned highlights:

Intro into Gleam — Harry Bairstow

Gleam: produces both Erlang and JS, with typed safety! BEAM performance. The syntax is friendly and the community is friendly!

Gave various introductory Gleam code examples. List(a) enforces that all elements in a list are of the same type. While elements in tuples can be of unequal type, like in Erlang. What I did not know is that you can address items in a tuple by index:

fn f() {
  let bla = #("sd", 5)
  bla.0  // "sd"
  bla.1  // 5
}

And of course Gleam comes with pattern matching, as in Erlang, yet type-safe.

A Discord bot with Shimmer

just a few percent of the shimmer code is Erlang (namely ffi for network libs).

Let's write a bot!

import shimmer/handlers

pub fn main() {
  handlers.new("TOKEN")
  |> handlers.connect
  |> handlers.on_message(fn(event, _client) {
    case event.message.contens {
      "!" <> command -> todo
      message -> io.println("received: " <> message)
    }
  })
}

and that's really the gist of it.

Talk binary to "Smart" things — Troels Brødsgaard

"Smart" things are heat pumps, etc. They do not know JSON or alike, they speak binary. This talk is introductory on the binary speak. Although aimed at Elixir, this comes from Erlang, hence the tag in the title.

Bit syntax comes from a place with pain. Big Endian and Little Endian names find their root in Gulliver's Travels, where it was used to indicate the side at which you break an egg. I did not know that!

The beauty of bit syntax is that you can provide the number of bits (not bytes) to en/decode data. The second beauty is that creating the binary concatenation and decomposing it use the same syntax, where for decomposing it is actually template matching.

Gleam bit syntax is pretty much the same:
fn f() {
  let ten = 10
  let five = 5
  let byte = <<ten:5, five:3>>
  let <<t:5, f:3>> = byte  // t == 10, f == 5
}

LiveView keeps you Warm — Arjan Scherpenisse

Take a nice, large (industrial) knitting machine. "It's like a printer, but for yarn". It has a UI resembling a FAX (scanning part). Strip it out, replace it with an Arduino (viz Hackers Bamberg), and hook it up to LiveView.

History of web 2.0 to explain: LiveView does most/all dynamics on the server, but then with a websocket. The diff rendering is done server-side and sent over the socket.

Distributed music programming with Gleam, BEAM, and the Web Audio API — Hayleigh Thompson

PhD on Prog lang design, esp about distributed audio.

Make collaborative music. Take the Web Audio API. That is low-level, synthesizer-like, with oscillators and such.

const ctx = new window.AudioContext

const osc = ctx.createOscillator()
const amp = ctx.createGain()
const dac = ctx.audioDestination

osc.frequency.value = 880
osc.type = "square"
amp.gain.value = 0.5

osc.connect(amp)
amp.connect(dac)

osc.start()
Much better with a declarative DSL!
osc([ freq(880.0), waveform("square") ], [
amp([ gain(0.5) ], [
dac
])
])
Add glisten and mist for the back end, and lustre on the front end. Stir in websockets.

Then two types of messages toBackend and toFrontend enable synchronizing between musicians. It's even LiveView-like!

Demo!

Q: Could you use this for co-op live coding? In principle, yes, the types guarantee you know the changes in the code, which the client can render.

The Actor Model as a Load Testing Framework — Nelson Vides

Comparison of old, solid bridges which can handle much more than they were designed for, compared to modern bridges that are 'JIT'

Talk is about the interaction of processes, traffic capacitity, amplifying factor, and existing behaviour having new impacts.

We need a definition: An actor can, in response to a message it receives: Load testing is like any testing: setup, run. You can user the Actor model in the testing: throttle some users/actors, and coordinate them in other ways.

The library is A Murder of Crows. You should aim to reach some load where things break. (Do you?)

Shorter feedback loops with Livebook — Linus De Meyere

LiveBook is a REPL on steroids.

Advantages:

Flow is a lib that builds upon gen_stage; Ecto is a database lib?

Running Erlang and Elixir on microcontrollers with AtomVM — Davide Bettio

AtomVM implements (most of) OTP20-25 VM opcodes. Focus is on memory.

125 erlang module functions implemented, plus a bunch of libs.

Some extras to poke regitsers, etc.

Supporting ESP32, STM32, Raspberry PI 2040, more coming, help wanted!

No SMP, no hot code reloading

Dealing with a Monster Query — Mackenzie Morgan

Post that can be queried in 4 ways. Could parallelize into 4 queries and be done with it.