{"path": "/posts/lfe-lisp-for-the-beam-erlangelixir/", "title": "LFE - Lisp for the BEAM (erlang/Elixir) 1/N · Bruno Dias", "html": "<!doctype html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"utf-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <meta name=\"description\" content=\"Introduction to writing sophisticated applications using the power of lisp.\">\n  <title>LFE - Lisp for the BEAM (erlang/Elixir) 1/N · Bruno Dias</title>\n  <link rel=\"canonical\" href=\"https://diasbruno.github.io/posts/lfe-lisp-for-the-beam-erlangelixir/\" data-post-metadata>\n  <meta name=\"author\" content=\"Bruno Dias\" data-post-metadata>\n  <meta property=\"og:type\" content=\"article\" data-post-metadata>\n  <meta property=\"og:title\" content=\"LFE - Lisp for the BEAM (erlang/Elixir) 1/N\" data-post-metadata>\n  <meta property=\"og:url\" content=\"https://diasbruno.github.io/posts/lfe-lisp-for-the-beam-erlangelixir/\" data-post-metadata>\n  <meta property=\"article:published_time\" content=\"2025-10-30T17:30:18+00:00\" data-post-metadata>\n  <meta property=\"og:image\" content=\"https://diasbruno.github.io/assets/site/substack/lfe-lisp-for-the-beam-erlangelixir/figure-1.jpg\" data-post-metadata>\n  <link rel=\"icon\" href=\"/assets/site/signature.svg\" type=\"image/svg+xml\">\n  <link rel=\"alternate\" type=\"application/atom+xml\" title=\"diasbruno\" href=\"/atom.xml\">\n  <link rel=\"alternate\" type=\"application/json\" href=\"/posts/lfe-lisp-for-the-beam-erlangelixir/content.json\">\n  <link rel=\"stylesheet\" href=\"/assets/site/tokens.css\">\n  <link rel=\"stylesheet\" href=\"/assets/site/site.css\">\n  <link rel=\"stylesheet\" href=\"/assets/site/footer.css\">\n\n</head>\n<body class=\"light\">\n<div id=\"site-page\">\n<a class=\"skip-link\" href=\"#content\">Skip to content</a>\n<header class=\"site-header\">\n  <a class=\"brand\" href=\"/\" data-site-navigation aria-label=\"Bruno Dias, home\">\n    <img src=\"/assets/site/signature.svg\" width=\"24\" height=\"34\" alt=\"\">\n  </a>\n  <nav aria-label=\"Main navigation\">\n    <ul>\n<li><a class=\"nav-vrn\" href=\"/vrn/\" data-site-navigation><span class=\"nav-label\">vrn</span> <span class=\"nav-badge\">research</span></a></li>\n<li><a class=\"nav-posts\" href=\"/posts/\" data-site-navigation aria-current=\"location\">Posts</a></li>\n<li><a class=\"nav-projects\" href=\"/projects/\" data-site-navigation>Projects</a></li>\n<li><a class=\"nav-about\" href=\"/about/\" data-site-navigation>About</a></li>\n</ul>\n  </nav>\n</header>\n\n<main class=\"section\" id=\"content\" tabindex=\"-1\">\n  <article class=\"post-detail\">\n    <header class=\"section-header\">\n      <p class=\"post-category\">Post</p>\n      <h1>LFE - Lisp for the BEAM (erlang/Elixir) 1/N</h1>\n<p class=\"post-subtitle\">Introduction to writing sophisticated applications using the power of lisp.</p>\n      <p><time datetime=\"2025-10-30T17:30:18+00:00\">2025-10-30</time></p>\n    </header>\n    <div class=\"post-columns\">\n      <section class=\"post-body\" aria-label=\"Article\">\n\n<figure><img src=\"/assets/site/substack/lfe-lisp-for-the-beam-erlangelixir/figure-1.jpg\" alt=\"\" loading=\"lazy\" width=\"1456\" height=\"840\">\n</figure>\n<p></p>\n<p>LFE is already, at least, 17 years old. The current state of the project is good. It still needs some work on infrastructure, but that’s what we do as society, and why we make projects open-source - so people can help improve it.</p>\n<p>We can create a full project using LFE and, as it targets the BEAM, it can be used together with other languages. It’s rebar compatible (and mix) and also have test frameworks, so, everything we need.</p>\n<hr>\n<h2>A little bit of Lisp</h2>\n<p>The easiest way to explain the lisp syntax is that it only contains parentheses (you can use other symbols like brackets and curly braces, but they are optional).</p>\n<p>The difference from other languages is just that as everything is a list, the lisp expression evaluation has a few rules:</p>\n<ul><li><p>If the first atom of the list is a symbol, it is a function call and the rest are the arguments.</p>\n</li>\n</ul>\n<pre><code><code>(my-function 1 2)</code></code></pre>\n<p>There are a few of keywords like <code>defmacro</code> (to define macro), <code>defun</code> (to defined functions), and other forms that are provided by the compiler/interpreter. But even this names can be used.</p>\n<ul><li><p>You can control the evaluation of everything. </p>\n</li>\n</ul>\n<pre><code>(+ a 1)</code></pre>\n<p>This expression would evaluate <code>a</code> and sum with 1.</p>\n<pre><code>(+ ‘a 1) </code></pre>\n<p>This expression would try to evaluate <code>‘a</code> (called “quote a”) to the keyword <code>a</code>. The result would be an error since we can’t sum a keyword and a number.</p>\n<pre><code>`(+ a 1)</code></pre>\n<p>The backquote allows us to evaluate parts of the expression. This one would result in the list as is <code>(+ a 1)</code>.</p>\n<pre><code>(let ((a 1))\n  `(+ ,a 1))</code></pre>\n<p>The comma in this expression would try to find if <code>a</code> is bound to any value like <code>a = 1</code>. This would result in the expression <code>(+ 1 1)</code>.</p>\n<p>This control over evaluation gives us so much power that we need to be careful to not abuse it.</p>\n<h2>Anonymous/lambda functions</h2>\n<p>They work as any other language.</p>\n<pre><code>(lambda (x) x)</code></pre>\n<p>It’s the same as in python, ruby, javascript and others:</p>\n<h6>Python</h6>\n<pre><code>(lambda x: x)(1)</code></pre>\n<h6>Ruby</h6>\n<pre><code>(-&gt;(x){ x }).call(1)</code></pre>\n<h6>Javascript</h6>\n<pre><code>((x) =&gt; x)(1)</code></pre>\n<h2>Defining functions</h2>\n<p><code>defun</code> is how we declare a function.</p>\n<pre><code>(defun x (arg)\n  arg)</code></pre>\n<p>Although it seems simplistic in the normal form, we can go to extremes using macro to generate all kinds of function with any combination of arguments.</p>\n<h2>Targeting the BEAM</h2>\n<p>Everything that is used on other languages that target the BEAM are still available in LFE. Although, they tend to be unnecessarily in some sense, because you can write everything pretty easily.</p>\n<h6>Defining a module</h6>\n<pre><code>(defmodule my-module\n  (behavior gen_server)\n  (export all))\n\n(defun my-function (x) x)</code></pre>\n<p>Or if you want to control each export.</p>\n<pre><code><code>(defmodule my-module\n  (behavior gen_server)\n  (export my-function/1))\n\n(defun my-function (x) x)</code></code></pre>\n<h2>Conclusion</h2>\n<p>This post is just an introduction to LFE. On the next, we are going to talk more about how to control evaluation and creating macros.</p>\n<hr>\n<p>References:</p>\n<p><a href=\"https://lfe.io\">Official lfe.io</a></p>\n<p><a href=\"https://github.com/lfe/lfe\">GitHub lfe/lfe</a></p>\n<p><a href=\"https://cnbbooks.github.io/lfe-manual/fm/title-page.html\">LFE MACHINE MANUAL</a> (I love this cover art)</p>\n<figure><img src=\"/assets/site/substack/lfe-lisp-for-the-beam-erlangelixir/figure-2.jpg\" alt=\"Cover of the LFE Machine Manual by Duncan McGreggor and Robert Virding.\" loading=\"lazy\" width=\"500\" height=\"652\">\n</figure>\n\n      </section>\n      <aside class=\"post-links\" aria-labelledby=\"post-links-heading\">\n        <h2 id=\"post-links-heading\">Links</h2>\n        <ul>\n<li><a href=\"/posts/\" data-site-navigation>All posts</a></li>\n<li><a href=\"/posts/lfe-lisp-for-the-beam-erlangelixir-c87/\" data-site-navigation>LFE - Lisp for the BEAM (erlang/Elixir) 2/N</a></li>\n<li><a href=\"https://diasbruno.substack.com/p/lfe-lisp-for-the-beam-erlangelixir\">Original on Substack</a></li>\n        </ul>\n      </aside>\n    </div>\n  </article>\n</main>\n\n<footer class=\"site-footer\">\n  <div class=\"site-footer-inner\">\n    <a class=\"site-footer-home\" href=\"/\" data-site-navigation>Bruno Dias</a>\n    <ul aria-label=\"Footer links\">\n      <li><a href=\"https://github.com/diasbruno\">GitHub</a></li>\n      <li><a href=\"/atom.xml\">Atom feed</a></li>\n    </ul>\n  </div>\n</footer>\n\n</div>\n<script type=\"module\" src=\"/assets/site/navigation.js\"></script>\n</body>\n</html>\n"}
