Gleam doesn't compile to Erlang source anymore

(gleam.run)

153 points | by ingve 6 hours ago

14 comments

  • giancarlostoro 36 minutes ago
    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.
    • ch4s3 4 minutes ago
      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.
  • zachrip 3 hours ago
    Shout out to Giacomo's twitch streams. He has taught me about some features of Gleam, Rust, and on top of that he's just a very chill person. He takes time away from his focus to answer questions politely and without judgement. There are dozens of programming streams where the streamer forgets to leave their ego at the door and he is not one of them. I highly recommend following it.
  • 0x69420 3 hours 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...

    2: https://www.erlang.org/doc/apps/stdlib/qlc.html#q/2

    3: https://www.erlang.org/doc/apps/syntax_tools/merl.html

  • MichaelNolan 1 hour ago
    Gleam is such a beautiful language. I wish I had the opportunity to use it more. If it could compile (transpile) to a native target like rust or go, it would be truly perfect.
    • packetlost 32 minutes ago
      I feel like Go would be a great backend target for Gleam
      • lpil 5 minutes ago
        Go's garbage collection isn't well suited for an immutable language like Gleam, so the performance would likely be disappointing compared to other targets.
        • ch4s3 1 minute ago
          The concurrency model in Go is also poorly suited to the BEAM's process model. Goroutines share a heap so you can't do a lot of things safely that processes can do. Having independent memory space for a process allows you to free it safely when work is done without GCing everything and you can also safely share data because you have a copy not a ref.
    • whalesalad 1 hour ago
      I am working on a language called blasphemy which intends to do this.
      • znpy 6 minutes ago
        Looking forward to be able to claim to be “proficient in blasphemy” on my cv! /s
    • fggbbjnvh 1 hour ago
      [flagged]
  • __jonas 2 hours ago
    Pretty exciting change that I didn’t see coming —- I wonder if someone will end up implementing an integration with the Whatsapp Erlang debugger
    • lpil 1 hour ago
      The only thing that would be needed for this is for 2 flags to be passed to the Erlang compiler. It would be very trivial!
  • impoppy 1 hour ago
    This raises an obvious question. Why Gleam team weren't doing that in the first place? Obviously they didn't have direct Gleam AST -> Erlang source pipeline, they must have had to build some their own custom Erlang AST representation that they then translated into the source code.
    • lpil 1 hour ago
      We did not (and still don't) have an internal Erlang AST representation in the compiler. Previously we did have a Gleam AST -> printing algebra -> Erlang source pipeline, now we construct a buffer of bytes with the data encoded as Erlang Term Format.

      Source was the previous target as at the time Erlang Abstract Terms was not established as the go-to format (Core Erlang was more popular but it did not have a stable API outside of the BEAM, so Gleam's in-Rust compiler could not construct it), and due to the newness of the language having an "escape hatch" where one could abandon Gleam and eject to Erlang was highly valuable. It also meant we could use the Erlang build tool until the Gleam one was ready for use.

  • lexx 2 hours ago
    Amazing news! Thank you!
  • jazzypants 1 hour ago
    Let me guess: still no string interpolation in a language ostensibly intended for building user interfaces?
    • lpil 1 hour ago
      Gleam is not ostensibly intended for building user interfaces.
      • jazzypants 23 minutes ago
        Then, why is JavaScript a compilation target? If you're not using it on the client-side, then why not stay exclusive to the BEAM?
        • lpil 3 minutes ago
          JavaScript is useful in lots of places, and even if one compile target is especially good for in-browser user interfaces that doesn't mean that language is specifically intended for user interface development.
        • yladiz 19 minutes ago
          You can do a lot more with JavaScript than building UIs.
          • jazzypants 16 minutes ago
            Yeah. I know. I use it every day. That doesn't answer my question. Why would I want to write something in Gleam if I want it to run in a JavaScript engine? When would that ever make sense? Could you please just engage with me in good faith?

            Multiple compilation targets require increased implementation complexity so you would think they would have a good reason for when you would compile to one target or the other. I couldn't find any information about it on their website, so I was hoping you would actually respond with something helpful rather than... that.

            • yladiz 6 minutes ago
              So, you started by making a pointed comment about that the language has no string interpolation when it's ostensibly for building UIs, so I'm not sure why you're surprised you're getting responses like mine or the one from lpil. Gleam is not ostensibly meant for building UIs just because it targets JS, and while you don't get string interpolation in the way you might get in other languages you can go pretty far with the <> syntax.

              To answer your question about why you would use Gleam when you're running code in a JS engine, it's the same about any language that compiles down to another, such as Clojure, and you can take your pick of those reasons: preference, syntax, pragmatism, etc. I'm not sure what kind of answer you're looking for beyond that.

      • whalesalad 1 hour ago
        I still don't know what gleam is for tbh. I like it conceptually. But interop with for instance elixir libraries is not as seamless as you'd like.
        • lpil 2 minutes ago
          It's a general purpose programming language, like OCaml, Python, or Scheme. It's not intended for any specific business domain.
        • __jonas 54 minutes ago
          I use it mostly for web APIs / services, it's great for that!

          Interop is not seamless since Elixir does not have the same static type system, but it is possible and that does help sometimes. When resizing images for example, I fall back to Elixir's bindings to libvips. I've also used Oban from Gleam in the past.

    • dematz 1 hour ago
      gleam is very much a language of "no" which if you like that, cool, if not, also cool :)
  • vortegne 3 hours ago
    Congratulations to the team! I love Gleam and am genuinely having fun every time I write Gleam code.
  • karel-3d 1 hour ago
    What is Gleam? Where would I want to use it?

    All I understand from the frontpage is that it's typesafe. Good I guess? Then there is something about Erlang which I never used.

    • jeltz 0 minutes ago
      It is if you want Erlang but typesafe and with a modern syntax. And why would you want Erlang? Erlang was built for making it easy to build fault-tolerant concurrent applications, for example in telecom.
    • lpil 1 minute ago
      Gleam is a simple functional programming language which leans into static typing , friendly tooling, and a one-way-to-do-it style. You'd want to use it if you enjoy the programming experience it provides.
  • quietFalcon 3 hours ago
    [flagged]
  • phcreery 3 hours ago
    The misuse of commas is distracting; at least it’s better than reading ai blogs.
    • gamache 2 hours ago
      Your semicolon would be more effective as a comma followed by "but". HTH
    • dominikh 2 hours ago
      Which commas are misplaced?
      • Joker_vD 2 hours ago
        Before the "and", "but", "so", "while", etc. — while most European languages, indeed, (usually) require commas before conjunctions, English is following a somewhat reversed convention. Well, at least the author remembered that they need to omit a comma before "that".
        • shakna 1 hour ago
          Apart from in Australian [0] and Canadian [1] English, where it is generally optional, but used where it can increase clarity or meter.

          [0] Australian Government Publishing Service's Style Manual for Authors, Editors and Printers, ISBN: 978 0 7016 3648 7

          [1] The Canadian style: a guide to writing and editing https://archive.org/details/canadianstylegui0000unse

        • pipe01 1 hour ago
          As a non-native English speaker I'm always so self conscious when using commas, it feels like I'm always using either too many or too few
          • GrantMoyer 33 minutes ago
            Informally, commas are "misused" regularly even by native writers, and almost no one notices or cares unless the misuse is frequent and egregious.

            Formally, most comma use is an issue of style, not grammar, and style guides differ on when they should and shouldn't be used. The main rule that's actually a matter of grammar is this: commas cannot be used to join two "clauses" (phrases which could be independent sentences) without a conjunction.

            • Joker_vD 11 minutes ago
              So putting the commas in "I'm eating a hot dog, she's listening to radio, we are having a wonderful time." is grammatically wrong? TIL, I guess.
          • john_strinlai 1 hour ago
            i dont think anyone actually cares unless you are in english class or someone wants to feel smug on the internet (you can ignore the 2nd one completely).
          • zulux 1 hour ago
            Don't worry about it.

            The lack or excess of commas doesn't upset any reasonable person in the slightest.

          • steele 1 hour ago
            You're doing fine. English grammar pedants speak infrequently. Mostly due to the disinterest of the listener.
          • tenuousemphasis 1 hour ago
            As a native English speaker, same.
        • sarchertech 1 hour ago
          You do need a comma before a conjunction if it connects two independent clauses.
          • Joker_vD 1 hour ago
            So it's "You do need a comma before a conjunction, if it connects two independent clauses" then — "you need a comma before a conjunction" and "it connects two independent clauses" are two fully formed simple sentences, each having its own subject and predicate. See what I mean?

            And almost nobody writes sentences like "I love her and she loves me back" with a comma before "and".

  • nwalkr 2 hours ago
    idk, i'm not sure about wording. erlang abstract form still is erlang source, it's ast of erlang source text. one call to erl_prettypr:format and text source is back. word 'transpiler' is still there and there is nothing "pejorative" in it, it's transpilers all the way down everywhere.

    but talking pejorative, i was surprised. my opinion of gleam was already pretty low, but i did not expect to see post-1.0 compiler emitting text erlang source. maybe it's not that good of idea to implement compiler in language completely foreign to target ecosystem.

    • lpil 1 hour ago
      I don't think your "it is source as you can convert it back into source" argument holds water as all the Erlang formats can be decompiled into Erlang source code, including the final bytecode itself.

      I think you're overthinking the cost of compiling to source, and also underestimating how common it is.