Gleam doesn't compile to Erlang source anymore
gleam.run313 points by ingve 2 days ago
313 points by ingve 2 days ago
to those curious, erlang abstract form[1] is the AST representation used by the erlang compiler/etc. per [1], you can see that it's canonically made of erlang terms, and you have easy access to routines for manipulating this representation from the standard library; it's really comfy when you need it! it's also the target elixir compiles down to, and the representation manipulated by parse transforms, which in base erlang are the way syntactic sugar (notably qlc[2] and some of the more cutesy pattern matches in merl[3] (which, in turn, manipulates the very same representation to do its job. very meta!)) is done.
most BEAM languages actually settle on erlang abstract format. you'd think core erlang would be more common since it feels more like a traditional functional IR, but basically only LFE does this, because it's a moving target without any particular stability guarantees from release to release.
1: https://www.erlang.org/doc/apps/stdlib/erl_parse.html#t:abst...
LFE used to compile to core Erlang, but it now also compiles to abstract forms.
https://github.com/lfe/lfe/blob/387d0aa1092bdda0ca17481869e8...
https://github.com/lfe/lfe/blob/387d0aa1092bdda0ca17481869e8...
Erlang is one of those runtimes I've loved since learning about it all the way back in 2008, but I never took time to learn the syntax, but Elixir and Gleam have had me fiddling with the Erlang VM over the years. Happy to see Gleam growing into maturity.
I just learned Erlang this year and I love the syntax. Ending expressions with periods took getting used to, but capital first letters distinguishing variables, non-rebindable variables, semicolons between function clauses, a lack of boilerplate (defmodule et al), a fraction of end keywords, commas separating expression, ... all make for a very fun to use and ergonomic language, IMO.
I haven't tried Gleam yet, though. I'm interested in the focus on simplicity but a little wary because I understand they sacrificed niceties to minimize the language footprint, e.g., pattern matching in function heads. I intend to give it a shot the next time I'm greenfielding something.
Erlang is my favorite functional language out of all the ones I've tried. The matchers, guards, etc are all done very well. But I don't like functional. I used to think it was cool, gave it a real chance using Erlang for years, and eventually decided it's not a good fit for many use cases. Like at some point the neatness of doing all loops as recursion wears off and it's just tiring. It's not like CS algo homework, and even there you often want DP/memoization.
Edit: pure* functional
> Like at some point the neatness of doing all loops as recursion wears off and it's just tiring.
Odd, but I believe you, lol. Elixir's list comprehensions take a `:reduce` option which makes accumulating values a bit more "familiar" and I often use over `reduce`:
for a <- list, reduce: []
acc ->
[a | acc]
end
Not sure if there is something like that in Erlang (or Gleam for that matter).If you already have a list in Erlang, you can use map and the foldl/foldr reducers. But there's no general for-loop. You're expected to use tail recursion.
Also tbh, I don't like reduce either. I agree with that article posted on HN a while back about devs not liking reduce. Just want to insert into my list or whatever, not have to check how exactly reduce works in this particular language.
> you can use map and the foldl/foldr reducers
Ya, I was saying as an alternative to a more dynamic-looking loop. And I should note that `for` is confusing in Elixir because it is not a for loop, it's a list comprehension. Also, `<-` is actually a match operator and can cause confusion if you think of it as a for loop. I'm actually not sure why they went with `for`. At one point it was `lc`. I do think `for` is better than `lc`, heh.
But yes, I don't hate reduce, but I do try and avoid it in favour of a higher level version if its available. My only real problem with reduce is that I sometimes forget the parameter order, which is why I like using list comprehensions since the accumulator gets labelled.
The "for" might be inspired by Python list comprehension
I'm pretty sure it's just inspired by `for` from several languages to give the illusion that "Elixir has a `for` loop" for beginners? Actually, as I say that out loud I'm unsure. Who knows!
I'm the same. I thought I was an oddball because so many people seemed to prefer Elixir but I like Erlang and its syntax. I wish I had more chances to use it at work but so far it's just been for hobby projects or playing with.
I'd say if you know and like Rust, then Gleam should be easy to pick up but otherwise I'd try Elixir. You can learn most of the language in a few days and be experimenting with BEAM and supervision concepts basically on day one. As a learning exercise I think its worth peoples' time because actors/processes are one of the concurrency models you don't see everywhere but solve interesting problems well.
I don't think that's the case, Rust and Gleam have almost nothing in common beyond having static type systems, and those type systems are very different too.
https://gleam.run/frequently-asked-questions/#How-does-Gleam...
You don't think that Gleam has more familiar syntax to a Rust dev than Elixir? Or that the type system might feel more familiar?
I think a Rust programmer is more likely to prefer Gleam to Elixir, but I don't think there is much link between Gleam and Rust, and I especially do not thing that Gleam should only be considered over Elixir if you are already a Rust programmer.
So I said:
> I'd say if you know and like Rust, then Gleam should be easy to pick up
And you think that:
> a Rust programmer is more likely to prefer Gleam to Elixir
Are we maybe splitting hairs here?
You said: >I'd say if you know and like Rust, then Gleam should be easy to pick up but otherwise I'd try Elixir.
This is way too strong and narrow statement. Gleam is statically typed garbage collected language, closer to OCaml than Rust. Elixir if you like dynamically typed instead.
Obligatory comment that elixir is now gradually typed: https://news.ycombinator.com/item?id=48388324