<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Thomas Gebert on Medium]]></title>
        <description><![CDATA[Stories by Thomas Gebert on Medium]]></description>
        <link>https://medium.com/@tombert?source=rss-4f0c09e501eb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_SbYERaydYzQWiMm.png</url>
            <title>Stories by Thomas Gebert on Medium</title>
            <link>https://medium.com/@tombert?source=rss-4f0c09e501eb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 12:42:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tombert/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Writing a Web Framework with Lisp Flavoured Erlang, Part II: Route Parsing.]]></title>
            <link>https://medium.com/@tombert/writing-a-web-framework-with-lisp-flavoured-erlang-part-ii-route-parsing-eb8d2e34fe48?source=rss-4f0c09e501eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb8d2e34fe48</guid>
            <category><![CDATA[macro]]></category>
            <category><![CDATA[erlang]]></category>
            <category><![CDATA[lisp]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[lfe]]></category>
            <dc:creator><![CDATA[Thomas Gebert]]></dc:creator>
            <pubDate>Fri, 26 Apr 2019 00:06:47 GMT</pubDate>
            <atom:updated>2019-04-26T16:37:22.933Z</atom:updated>
            <content:encoded><![CDATA[<p>Last time, we got the “hello world” of Cowboy working in LFE.</p><p>While the vanilla version of Cowboy isn’t terribly difficult to use, and no one would judge you for just sticking with that, it certainly wouldn’t be much of a web-framework tutorial if that’s where it ended.</p><p>In order to satisfy the core tenet of Frameworkey, we will need to write a custom router. This part is especially exciting to me because, unlike the previous three versions of Frameworkey, this one is going to have the routes parsed at compile-time instead of runtime by exploiting LFE’s Lisp Macros.</p><p>LFE uses a Common-Lisp style macros, which are unhygenic, but I think that since this will be run as effectively compile-time configuration, that shouldn’t be an issue.</p><p>I forgot to mention this in the last section, but part of the appeal of Lisp programming has always been the ability to use the interactive REPL. I don’t want to break from this tradition, and neither does LFE. To add support for REPL development into our project, simply make your plugins block in the rebar3 config look something like this:</p><pre>{plugins, [<br> {&#39;lfe-compile&#39;,<br>  {git, &quot;<a href="https://github.com/lfe-rebar3/compile.git">https://github.com/lfe-rebar3/compile.git</a>&quot;, {tag, &quot;0.3.0&quot;}}},<br>  {&#39;lfe-repl&#39;,<br>    {git, &quot;<a href="https://github.com/lfe-rebar3/repl.git">https://github.com/lfe-rebar3/repl.git</a>&quot;, {tag, &quot;0.2.1&quot;}}}<br>]}.<br></pre><p>After that, if you run rebar3 lfe repl you should be able to load up an interactive LFE shell that has full scope to your project.</p><p>The first step for this is simply creating a file called src/routing.lfe. Let’s get a basic stub set up.</p><pre>(defmodule routing (export (routemap 1)))</pre><p>The routemap will make more sense as we move along.</p><p>We are also going to keep the routes in a JSON file, at least for now. Create a JSON file at the root of the project called routes.json (we will probably be moving this later) and put something like this in there:</p><pre>{&quot;GET /hello&quot;: &quot;Controller.action Controller2.action&quot;}</pre><p>We aren’t going to be working on the dispatcher today, just the route parser, but the gist of this is that we are going to compose Controller.action and Controller2.action together like they were one big function, and return the result of this to the user. Remember, the whole gist of Frameworkey is “compose all the things via configuration”.</p><h3>Parsing the JSON</h3><p>For the JSON parsing, for now, we are going to use the Jiffy parsing library. I have no real reason for choosing this library other than “it was one of the first things that came up when I searched for ‘Erlang JSON Parser’”.</p><p>Add the Jiffy dependency to your Rebar3 config…your dependencies should look something like this:</p><pre>{deps, [<br> {cowboy, &quot;2.6.3&quot;},<br> jiffy]<br>}.</pre><p>Then run rebar3 compile and that should pull everything in. Open up a REPL and see if it’s loading correctly. As a note, Jiffy works on binary strings, not the regular double-quoted strings, so make sure you denote that with a #.</p><pre>$ rebar3 lfe repl</pre><pre>&gt; (jiffy:decode #&quot;{\&quot;hello\&quot;:\&quot;world\&quot;}&quot;)<br>#((#(#&quot;hello&quot; #&quot;world&quot;)))</pre><p>By default, Jiffy likes to return a tuple of Key, value. I personally think that since Erlang (and consequently LFE) has had first-class maps for years now, I’d much rather work with them, since they map more-cleanly to JSON’s natural structure. Fortunately, Jiffy supports this as well:</p><pre>&gt; (jiffy:decode #&quot;{\&quot;hello\&quot;:\&quot;world\&quot;}&quot; &#39;(return_maps))<br>#M(#&quot;hello&quot; #&quot;world&quot;)</pre><p>Isn’t that nice?</p><p>Anyway, now we need to read the JSON file we created as a string and parse it. To load the file, we are going to use the built-in Erlang function file:read_file/1.</p><pre>&gt; (file:read_file &quot;routes.json&quot;)<br>#(ok #&quot;{\n  \&quot;GET /hello\&quot;: \&quot;Controller1.action Controller2.action\&quot;\n}\n&quot;)</pre><p>Ok, so now that we have the ability to load our JSON, we can parse it with Jiffy.</p><pre>&gt; (let (((tuple &#39;ok my-string) (file:read_file &quot;routes.json&quot;))) (jiffy:decode my-string &#39;(return_maps)))<br>#M(#&quot;GET /hello&quot; #&quot;Controller1.action Controller2.action&quot;)</pre><p>We will also need a way to split the string. Erlang has an unsurprisingly-named built-in function string:split/2 to handle this:</p><pre>&gt; (string:split #&quot;Controller1.action Controller2.action&quot; #&quot; &quot;)<br>(#&quot;Controller1.action&quot; #&quot;Controller2.action&quot;)</pre><p>So now we’ve gotten all the parts we need to parse the routes. Now to glue everything together. For this, we are going to use a macro.</p><p>As a quick aside, to the unfamiliar, Lisp macros are metaprogramming, though reducing it down to that is kind of reductive.</p><p>I’ll give a quick rundown of how Lisp macros work.</p><p>Lisp is “homoiconic”, which is just a fancy way to say “the entire language is expressed in terms of its core data structures”. When I type the expression (io:format &quot;hello&quot;), it isn’t just a function call. The lexer first desugars it into (: io format &quot;hello&quot;), and then reads that as a list of four elements, with the first being a :, the second being io, the third being format, and the last being the string &quot;hello&quot;. Once it has read it as a list, depending on the context, it can then figure out what to do with it.</p><p>Why is this relevant? Because the core data structure of Lisp is the list (LISt Processing), when writing a macro, you’re doing code generation by simply creating a list or lists at compile time, which will then be read by the regular compiler.</p><p>This is why Lisp has to have all the parentheses, and when you see the occasional question pop up on Stackoverflow asking for a “Lisp without parentheses”, it shows that they don’t really get the point.</p><p>Since they can be difficult to debug, macros should be used with caution, but they are incredibly powerful tools occasionally. Since all the cost of a macro is paid during compile-time, they can occasionally be an optimization technique, and while I haven’t done this with LFE, it can be useful to be able to automatically generate bindings to an external library using reflection.</p><p>Anyway, now that we have all the tooling set up for our route parsing, let us write a macro to parse our routes.</p><pre>(defmacro make-routes (path) <br>  (letrec-function ((build-fun (match-lambda ((args &#39;())<br>           `(lambda (x) ,args))<br>          ((args (cons (cons module (cons func &#39;())) funcs))<br>          (build-fun `(: ,(list_to_atom (binary_to_list module)) ,(list_to_atom (binary_to_list func)) ,args) funcs)))))</pre><pre>(let* (((tuple &#39;ok my-string) (file:read_file path))<br>  (my-json (jiffy:decode my-string &#39;(return_maps)))<br>  (a (maps:map (lambda (key value)  <br>   (let* ((actions (string:split value #&quot; &quot;))<br>          (actions2 (lists:map (lambda (x) (string:split x #&quot;.&quot;)) actions))<br>          )<br>     (build-fun &#39;x actions2))) my-json)))<br>    `(defun routemap () ,a ))))</pre><p>This is probably scary, so it’s break it down step by step.</p><p>The first step with (defmacro make-routes (path)) should be fairly familiar now; this is similar to the defun from before, taking an argument called path.</p><p>letrec-function is something new, however. We need a way to create the function composition, and since Erlang and LFE do not have loops, you need to do this recursively. Since I have no need to use this function outside of this macro, using an internal letrec-function is useful, since it allows you to assign a temporary name to your temporary function ( build-fun in this case) and call it from anywhere inside the macro.</p><p>Inside build-fun you will see some funky syntax with backticks and regular ticks and commas. One thing you need to get the hang of when writing Lisp is how quotations work. Quotes in Lisp are almost exactly as they sound: a means of putting down a literal value. When you have a symbol that you want to refer to appear literally, without being evaluated, you can quote it by prefixing it with a &#39;.</p><p>Prefixing everything with a tick can get pretty ugly and tedious though; sometimes it’s useful to assume everything is quoted by default, and have a way of specifying the few parts that aren’t.</p><p>These are called “quasiquotes”. Quasiquotes took a bit to wrap my head around, but they’re fairly straightforward in concept. By prefixing an expression with a backtick, everything inside the expression is quoted, unless preceded by a , (called an “unquote”).</p><p>In the case of build-fun, I am creating a recursively growing list, with function calling the previous function. Once I’ve exhausted all the functions, I wrap them in a list that will eventually evaluate to a lambda and return that. We are exploiting LFE’s pattern matching in order to avoid some manual unboxing syntax, which does admittedly look a bit messy with these nested functions.</p><p>Since we will parse the JSON as binary strings, we need to convert them to atoms to refer to the functions. For some reason, I had trouble getting the erlang:binary_to_atom function working, so converting it to a list first was necessary.</p><p>A little bit below this definition, we grab the JSON file defined in the path variable. We parse this as a map, and loop over the values, separating first by spaces to separate the composition parts, and then by the . to separate the modules from the functions.</p><p>We pass these into our build-fun , and this should give us our new map.</p><p>We have finally finished our code-generation, and we have a map of routes to a composed function, and thus our first bit of routing logic is done.</p><p>I couldn’t find a better way to deal with this, but I found the easiest way to get this is to simply generate a wrapper getter function that returns the map. I’ll probably go back and fix this once I figure out a more clever way.</p><p>That wraps up our route parsing lesson. Next time we will work on passing this into the Cowboy dispatcher, and actually wiring these routes up.</p><p>📝 Read this story later in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_read_later_text">Journal</a>.</p><p>🗞 Wake up every Sunday morning to the week’s most noteworthy Tech stories, opinions, and news waiting in your inbox: <a href="https://usejournal.com/newsletter/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_text">Get the noteworthy newsletter &gt;</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb8d2e34fe48" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing a Web Framework with Lisp Flavoured Erlang, Part I: Getting Cowboy Working.]]></title>
            <link>https://medium.com/@tombert/writing-a-web-framework-with-lisp-flavoured-erlang-part-i-getting-cowboy-working-1c70c8a01a05?source=rss-4f0c09e501eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c70c8a01a05</guid>
            <category><![CDATA[lfe]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[erlang]]></category>
            <dc:creator><![CDATA[Thomas Gebert]]></dc:creator>
            <pubDate>Mon, 22 Apr 2019 03:40:50 GMT</pubDate>
            <atom:updated>2019-04-25T17:12:05.536Z</atom:updated>
            <content:encoded><![CDATA[<p>Yesterday I posted an article about working with Lisp Flavoured Erlang (LFE) on the GRiSP development board.</p><p>Working on that project made me realize how much I had missed writing Erlang, and combining it with Lisp only made it sweeter. This led to an overwhelming desire to start working on another big project and I figured a good place to start would be to write a Frameworkey. After all, I had already written one in Erlang, maybe it’s time to take-on Lisp</p><p>To the uninitiated, “Frameworkey” is my codename for all the web frameworks I’ve written (<a href="https://gitlab.com/tombert/frameworkey">three</a> <a href="https://gitlab.com/tombert/frameworkeyPromiseEdition">thus</a> <a href="https://gitlab.com/tombert/Frameworkey-Erlang">far</a>), and they all follow a few core tenets:</p><ul><li>A controller action is simply a function inside a module.</li><li>Routes are defined in a configuration file (such as JSON or YAML), and specifically <em>not</em> in code directly.</li><li>Routing is handled via a composition of controller actions, where the output of the first action is fed into the next (e.g. &quot;GET /endpoint&quot; : &quot;my_module:first_action another_module:second_action yet_another_module:third_action&quot; (<a href="https://gitlab.com/tombert/frameworkeyPromiseEdition/blob/master/config/routes.coffee">example</a>)</li><li>In the routing definition, there should be the ability to add an optional error-handler to the controller action (e.g. &quot;METHOD /route&quot; : &quot;ControllerName.ActionName!ControllerName.errorHandler ControllerName.ActionName2 @ ControllerName.catchAllErrorHandler&quot;).</li><li>Policies are handled by functions that return a boolean and status code for whether the request is allowed to continue (example).</li><li>The mapping of policies is done on a per-action level by a separate configuration file (e.g. JSON or YAML). The default permission can be applied set in this file as *.</li></ul><p>These may not seem like much, and as far as I know I might have actually invented this paradigm, but it actually ends up being an incredibly pleasant way to write a web framework, since everything is purposefully very decoupled and as a result nearly everything can be reused and composed with everything else.</p><p>These axioms will make more sense as we move along.</p><p>The first step of this project is, well, creating the project. Assuming you have rebar3 installed, you can run the following command:</p><pre>rebar3 new app frameworkey_lfe</pre><p>After that, add LFE support to your rebar.config:</p><pre>{provider_hooks, [{pre, [{compile, {lfe, compile}}]}]}.<br>{plugins, [<br> {&#39;lfe-compile&#39;,<br>  {git, &quot;<a href="https://github.com/lfe-rebar3/compile.git">https://github.com/lfe-rebar3/compile.git</a>&quot;, {tag, &quot;0.3.0&quot;}}}]}</pre><p>Now we get into the philosophical discussion: what server backend do we want to use?</p><p>There are a lot of Erlang HTTP servers out there, like YAWS and even one built-in to OTP, but to be honest, the one I found easiest to use while maintaining good speed is <a href="https://ninenines.eu/">Cowboy by NineNines,</a> so we will be using that. Feel free to email me explaining why I’m wrong for this.</p><p>Anyway, to add Cowboy, we need to add it to our rebar.config file:</p><pre>{deps, [<br> {cowboy, &quot;2.6.3&quot;}]<br>}.</pre><p>After that, you need to open up src/frameworkey_lfe.app.src and add Cowboy to your applications:</p><pre>{applications,<br>   [ kernel,<br>     stdlib,<br>     cowboy<br>   ]},</pre><p>OK, so now we need to start coding.</p><p>I recommend deleting the file src/frameworkey_lfe_app.erl since we want to work in LFE. Create a new file called src/frameworkey_lfe_app.lfe. Let’s get a bit of code written. Here’s what I have to get started, lifted and ported right from the Cowboy Getting Started guide:</p><pre>(defmodule embyerlang_app<br>    (behaviour application)<br>    (export (start 2) (stop 1)))</pre><pre>(defun start (_start-type _start-args)<br>  (let ((Dispatch (cowboy_router:compile <br>      (list <br>        (tuple &#39;_ (list (tuple &quot;/&quot; &#39;hello_handler &#39;())))))))<br>    (let (<br> ((tuple &#39;ok _blah) (cowboy:start_clear<br>     &#39;my_http_listener <br>     (list (tuple &#39;port 8080)) <br>     (map &#39;env (map &#39;dispatch Dispatch))))<br> ((tuple &#39;ok sup-pid) (embyerlang_sup:start_link)))<br>    (tuple &#39;ok sup-pid))))</pre><pre>(defun stop (_state) &#39;ok)</pre><p>You will also need to create another file called src/hello_handler.lfe .</p><pre>(defmodule hello_handler (export (init 2) (terminate 2)))<br></pre><pre>(defun init (req0 state) <br>  (let ((req (cowboy_req:reply 200 #M(#&quot;content-type&quot; #&quot;text/plain&quot;) #&quot;Hello LFE!&quot; req0)))<br>    (tuple &#39;ok req state)<br>    ))</pre><pre>(defun terminate (_req _state) &#39;ok)</pre><p>This is pretty much a direct port, so it should be pretty straightforward to read (though I’m sure I’m missing some LFE shorthand since I’m still new to the language).</p><p>You should now be able to run:</p><pre>$ rebar3 compile<br>$ rebar3 shell</pre><p>This should start up, and you can now open your browser and go to <a href="http://localhost:8080/">http://localhost:8080</a> in your favorite browser. You should get the string Hello LFE! and life should be wonderful.</p><p>Cowboy works by compiling the routes by binding to a module, and looking for a function called init. This creates a dispatch object, which you then feed to the start_clear function.</p><p>Personally, I actually really dislike this; I have always hated forced creation of files, since I think it creates a lot of clutter and makes things difficult to find. We will be getting around this by writing our own dispatcher in the future, since the way Cowboy does dispatching is fairly antithetical to the Frameworkey design and philosophy.</p><h3>Conclusion</h3><p>This will be broken up into multiple parts, since there are a lot of moving pieces to a web framework, but I think this will be a pretty fun project. I’m thinking about the best way to exploit the superpowers of for this, and I’m definitely open to suggestions/corrections should anyone have any.</p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_image"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2IVAl0TbsfES9cFGYr40g.png" /></a></figure><p>📝 Read this story later in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_read_later_text">Journal</a>.</p><p>🗞 Wake up every Sunday morning to the week’s most noteworthy Tech stories, opinions, and news waiting in your inbox: <a href="https://usejournal.com/newsletter/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_text">Get the noteworthy newsletter &gt;</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c70c8a01a05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RIP Joe Armstrong]]></title>
            <link>https://medium.com/@tombert/rip-joe-armstrong-b6252ff93654?source=rss-4f0c09e501eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6252ff93654</guid>
            <category><![CDATA[erlang]]></category>
            <category><![CDATA[sad]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Thomas Gebert]]></dc:creator>
            <pubDate>Sat, 20 Apr 2019 23:25:57 GMT</pubDate>
            <atom:updated>2019-05-06T21:47:15.014Z</atom:updated>
            <content:encoded><![CDATA[<p>Wow, some timing. Almost literally immediately after I wrote my blog post about Lisp Flavoured Erlang, I hear news about Joe Armstrong dying.</p><p>Joe was someone that I admired greatly, and it’s not just because he created Erlang. He was a fun character, so I imagine there are two million stories about him floating around, but I thought I should share my (limited) experience with him.</p><p>Back in 2012, I knew almost nothing about distributed or concurrent programming. I had some vague idea of what a thread was, and I had heard that locks exist for this, but that was effectively <em>all</em> I knew. I knew that the internet had to be distributed, but there was no concept of concurrency theory in my brain, nor did I understand any properties of it.</p><p>One day I decided that I am going to start learning this stuff. After a quick search for “distributed programming language”, and traversing through a few forum posts, I stumbled across Erlang.</p><p>Erlang’s Prolog-esque syntax was weird (the only languages I knew in any kind of detail were C++ and Java and a bit of Haskell), and at first I dismissed it, largely because I was completely ignorant of <em>why</em> it existed, and any language that didn’t look like C was malformed, and while the seed was planted, I brushed aside Erlang.</p><p>But eventually the urge grew large enough to where I had to actually <em>try</em> the language, and upon writing a basic server and getting it to compile, I realized that I had stumbled upon something kind of magical.</p><p>Because I figured that whomever created this language must know a lot about this whole concurrency nonsense, I found Joe Armstrong’s email address and sent him a message asking some questions that make me cringe a little now, and much to my surprise, he responded back! I seem to have lost the email that I sent, but here is his response (the &gt; is him quoting me).</p><blockquote>&gt; Hello!</blockquote><blockquote>&gt; I am learning Erlang and <em>really</em> liking it.</blockquote><blockquote>Great</blockquote><blockquote>&gt; I am finding myself really liking the immutability in regards to being able to reason about my code, but that leaves me with a probably easy question: why does immutability make concurrency easier?</blockquote><blockquote>Tricky I guess it makes parallel execution easier (no locks) — it certainly makes programming easier closures really are closures :-)</blockquote><blockquote>&gt; Is it because it’s difficult to have something in a thread reach-across and modify the state of another thread?</blockquote><blockquote>That’s not really immutability — actually I hate threads — the difference between a thread and a process is crucial — threads can modify shared state (horrible) -</blockquote><blockquote>In distributed systems there is no real shared state (imagine one machine in the USA another in Sweden) where is the shared state? In the middle of the Atlantic? — shared state breaks laws of physics. State changes are propagated at the speed of light — we always know how things were at a remote site not how they are now. What we know is what they last told us. If you make a software abstraction that ignores this fact you’ll be in trouble.</blockquote><blockquote>&gt; Does that mean concurrency wouldn’t be so bad if you kept state mutations contained within one thread?</blockquote><blockquote>Yes — if you use the word process, not thread. Processes were invented to provide protection from other computations and to share resources in a clean way — threads share resources in a messy way.</blockquote><blockquote>&gt; If you don’t have time to answer right now, a link or some guidance into the right resource would be appreciated!</blockquote><blockquote>I think what you’re interested in is the distinction between message-passing-concurrency and shared-memory-concurrency.</blockquote><blockquote>Java/C++/etc uses shared-memory concurrency (evil) — Erlang uses message passing concurrency.</blockquote><blockquote>AS Alan-Kay said — the big thing about OO is message passing not all the other stuff …</blockquote><blockquote>&gt; &gt; I love Erlang, and I appreciate you reading my message!</blockquote><blockquote>Have fun</blockquote><blockquote>/Joe</blockquote><p>I thought that this was fantastic. I had expected him to simply send me an Amazon link for a book, or to even simply ignore my email, but instead he went into good detail about these things, and it stuck. Suddenly, a lot of the concurrency problems that I had neglected made sense, and I knew the path forward to learning this: Erlang.</p><p>Fast forward about a year. I have focused fairly heavily on functional programming, and I finally get a job building a chat server Erlang, much to my excitement. I enthusiastically sent Joe an email to thank him, and happily he responded back again.</p><blockquote>&gt; Hello!</blockquote><blockquote>&gt; Just under a year ago I send you a message asking you about multi-process computing and the like. You gave me a long, detailed email that not only answered my questions, but also explained in pretty-decent detail. &gt;</blockquote><blockquote>&gt; I was so impressed by that email that I actually purchased your “Programming Erlang” book, and enjoyed that just as much, and today I started my first job doing Erlang full-time (well, mostly; there’s some JS involved).</blockquote><blockquote>Great — thanks a lot for buying the book — these kind of stories make it feel all worth while</blockquote><blockquote>&gt; I just wanted to thank you for the help. I know a compsci-celebrity probably gets bombarded with emails,</blockquote><blockquote>Actually not — I guess it’s a ‘being polite’ thing — I rather like twitter it lowers the entry barrier for communication between people.</blockquote><blockquote>I have in the past mailed several of my CS “heros” — and was always rather reluctant to do so. Then to my great surprise I often got long and helpful replies (from Niklaus Wirth, Alan Kay, Jim Gray)</blockquote><blockquote>This kind of fits in with my view of life — 95% of people are basically helpful.</blockquote><blockquote>I’ve always thought that converts were gained “one at a time” — imagine a drip drip drip of water falling into a pan — one day it overflows.</blockquote><blockquote>We always think it’s fantastic to hear the stories of what you guys do with Erlang. (I say we because the Erlang you’re using is the product of many people fantastic work) — I’m just the fall guy who writes the books and happened to start it all :-)</blockquote><blockquote>I was sat listening to Brian Acton who founded WhatsApp and made 3.5B$ and thought “I invented this crap” — which is a great feeling — and they gave me a tee-shirt.</blockquote><blockquote>So the side effect of what I do is I get to meet loads of interesting people and do what I want.</blockquote><blockquote>Anyway thank again, and I hope things go well for you.</blockquote><blockquote>&gt; and I think it’s really cool that you took a good amount of time responding to some random guy on the internet asking for help.</blockquote><blockquote>Well every body is a random guy until you share stories.</blockquote><blockquote>My wife was a random woman before we met.</blockquote><blockquote>Anyway life would be very boring if it were not for random events.</blockquote><blockquote>I never run for busses or trains — it was after I read about a guy who missed a train and had a random conversation with a guy on the platform who had also missed the train — this gave them an idea that they turned in a multi-million dollar business.</blockquote><blockquote>I guess the other reason that you get long replies is that I’m an author and I don’t do short mails.</blockquote><blockquote>&gt; As usual, keep up the great work.</blockquote><blockquote>I’m trying — though I’ve recently retired — gives me more time for hobby programming — though I have to tend my garden and so on</blockquote><blockquote>Cheers</blockquote><blockquote>/Joe</blockquote><p>While this email wasn’t as technical, it was even more insightful. Clearly Joe cared more about teaching than his ego, and it’s something I’ll never forget.</p><p>These emails were incredibly influential to me, and I like to think that my life has substantially improved as a result of them.</p><p>Over the years, I seen him as even more of a mentor; his excited and enthusiasm about all-things-tech was infectious, and I hope to achieve at least 1% of the positive influence on someone else that he did for me.</p><p>Joe, you will be sorely missed.</p><p>📝 Read this story later in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_read_later_text">Journal</a>.</p><p>👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. <a href="https://usejournal.com/newsletter/noteworthy-in-tech/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_text">Read the Noteworthy in Tech newsletter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6252ff93654" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with Lisp-Flavoured-Erlang on the GRiSP platform]]></title>
            <link>https://medium.com/@tombert/working-with-lisp-flavoured-erlang-on-the-grisp-platform-b9d387e28558?source=rss-4f0c09e501eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9d387e28558</guid>
            <category><![CDATA[erlang]]></category>
            <category><![CDATA[post]]></category>
            <category><![CDATA[grisp]]></category>
            <category><![CDATA[lfe]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Thomas Gebert]]></dc:creator>
            <pubDate>Sat, 20 Apr 2019 20:12:28 GMT</pubDate>
            <atom:updated>2019-04-22T19:23:10.321Z</atom:updated>
            <content:encoded><![CDATA[<p>A few months ago I saw a post on Hacker News mentioning a new development board called the “GRiSP”, designed specifically for IoT and real-time applications, with the primary development language and platform being one of my favorite things out there: Erlang.</p><p>While I’m not someone overly familiar with systems programming, I have always enjoyed writing in Erlang (and am even one of the few privileged people that can honestly say they’ve done it for a living, though not in four years or so). Personally, while I <em>do</em> like Erlang, the pseudo-Prolog syntax in it can still trip me up, so as of lately I’ve become very interested in running Lisp on the Erlang platform.</p><p>I posted a question on that HN thread, asking if it would be possible to get something like Lisp-Flavoured-Erlang (LFE) or Joxa running on the board, and one of the engineers working on the project got back to me saying that there shouldn’t be any technical reason why it wouldn’t work, and with this, I got a board to play with.</p><p>I was then tasked with choosing the language: do I want to choose LFE or Joxa for this project? While I tend to prefer Joxa’s Lisp-1 semantics, and despite me having a strong aversion to the British spelling of the word “flavor”, I decided on working with LFE, due to its more-direct mapping to the Erlang platform and due to Robert Virding’s (the creator of LFE and one of the co-creators of Erlang) help on the Erlangers Slack server.</p><p>I’ll assume that you’re starting from scratch on this, so I’ll show you the steps that I went through to get it working.</p><h3>Installing Erlang</h3><p>You can’t do a lot of anything with Erlang until you actually install Erlang. While you can usually get away with something like sudo apt-get install erlang or brew install erlang, I tend to prefer to go and download the distribution from the Erlang Solutions website (available <a href="https://www.erlang-solutions.com/resources/download.html">here</a>), since that tends to be well-supported and have the latest release of the OTP platform in an easy-to-install package.</p><p>This installation tends to be pretty straightforward, but in case you’re doing the “copy-paste-all-the-things-in-the-post” strategy, here’s the command I used to install it on Ubuntu Linux:</p><pre>$ sudo dpkg -i esl-erlang_21.3.5-1\~ubuntu\~cosmic_amd64.deb<br>$ sudo apt-get install -f # this is to install all the deps required by the deb package. <br>$ sudo dpkg -i esl-erlang_21.3.5-1\~ubuntu\~cosmic_amd64.deb</pre><h3>Installing rebar3</h3><p>If you’re working with Erlang, you are probably using rebar3 anyway, but if you are new to the platform, rebar3 is similar to Stack for Haskell, or npm for Node.js; a build platform for Erlang, which can handle dependencies, scaffolding of a project, and a whole slew of other neat features.</p><p>Just as a note, rebar2 and rebar3 are <em>not </em>compatible with each other. It depends on your operating system, but you should probably avoid doing something like sudo apt-get install rebar and installing from the upstream rebar3 website (available <a href="https://www.rebar3.org/docs/getting-started">here</a>).</p><p>The documentation on the site is pretty straightforward, but again, if you’re just copy-pasting what I’m doing, here are the commands I ran.</p><pre>$ mkdir ~/bin<br>$ cd ~/bin<br>$ wget &quot;<a href="https://s3.amazonaws.com/rebar3/rebar3">https://s3.amazonaws.com/rebar3/rebar3&quot;</a><br>$ chmod +x rebar3<br>$ echo &quot;export PATH=\$PATH:`pwd`&quot; &gt;&gt; ~/.bashrc #or .zshrc<br>$ source ~/.bashrc</pre><p>Just as a note, while I actually really like the erlang.mk project (an alternative to rebar3), all the GRiSP and LFE documentation assumes the use of rebar3, so I’d stick with that, at least for now.</p><h3>Creating the GRiSP Project</h3><p>I figured the best place to start would be to port over the <a href="https://www.grisp.org/articles/intro/your-first-grisp-app/">getting-started project</a> on the official GRiSP website to LFE.</p><p>The project page is pretty good, and I installed the GRiSP plugin for rebar3 by opening ~/.config/rebar3/rebar.config in Vim and adding rebar3_grisp into the plugins list.</p><p>After that, I created a project using the following command.</p><pre>rebar3 new grispapp name=robot dest=/media/tombert/GRISP # the dest should be wherever your SD card is mounted to.</pre><p>This will create a bunch of files, including some basic stubbed-out Erlang files to make a basic application. This would be really useful if we were doing Erlang, but I’m an eccentric and I’m using Lisp, so as a result, you will need to delete the src/robot.erl file. Seriously, I cannot overstate this. I wasted an embarrassing amount of time trying to figure out why my LFE didn’t seem to be loading because I had forgotten to delete the regular Erlang file.</p><p>Next, open up the rebar.config file in your favorite text editor and make your plugins block looks like this:</p><pre>{&#39;lfe-compile&#39;,<br>     {git, &quot;<a href="https://github.com/lfe-rebar3/compile.git">https://github.com/lfe-rebar3/compile.git</a>&quot;, {tag, &quot;0.3.0&quot;}}}</pre><p>This should allow us to mix and match Erlang and LFE files however we’d like.</p><p>OK, so now we can actually code something. Let’s write a simple bit of code to simply flash a yellow LED a bunch of times. Create the file src/robot.lfe and open it with a text editor.</p><p>Here’s the code that I wrote, and I’ll break it down line-by-line afterwards.</p><pre>(defmodule robot<br>    (behaviour application)<br>    (export (start 2) (stop 1)  ))</pre><pre>(defun start (_Type _Args) <br>  (let (((tuple &#39;ok super) (robot_sup:start_link)))<br>    (lists:map <br>      (lambda (x) <br> (grisp_led:flash 1 &#39;yellow 500)) (lists:seq 1 100 ))<br>    (tuple &#39;ok super)<br>    ))</pre><pre>(defun stop (_State)  &#39;ok)</pre><p>Compile this with rebar3 compile on the command line (with your SD card plugged in and mounted), and then run:</p><pre>rebar3 grisp deploy -n robot -v 0.1.0</pre><p>Plop the microSD card into the GRiSP board, and give it power. It takes awhile to boot (about a minute and a half based entirely on my gut feelings and not any empirical data), but once it does, you should have a flashing yellow LED blinking in half-second intervals.</p><h3>The Code Breakdown.</h3><p>The defmodule robot part should be self-explanatory…I’m defining a module called robot that implements the behaviour named application and exports two functions: start and stop, taking 2 and 1 arguments respectively. I have come to terms with the fact that the British spelling of “behavior” is also wrong and I just have to live with that.</p><p>(defun start (_Type _Args) is my direct port of the code that was generated in Erlang by rebar3 from before. The _Type and _Args are more useful if you get into more elaborate Erlang/LFE programming, but that’s beyond the scope of this tutorial.</p><p>The (tuple &#39;ok super) (robot_sup:start_link) starts the supervisor process, which returns back a tuple with the atom ok and the PID of the supervisor. LFE gives us all the wonderful Erlang pattern-matching goodness, so I was able to unbox this immediately (despite the fact that I’m not really using them here). (NOTE: In LFE atoms are quoted with a &#39;. LFE doesn’t do the same thing Erlang does where anything lower-case becomes an atom).</p><p>After this, I wanted to make something that would flash the LED. The grisp_led:flash function takes in the number of the LED you want to power, the color you want to flash (as an atom), and the flash-time in milliseconds. I figured it would be more interesting if I made it flash repeatedly, so I ran it in a lists:map over a sequence of 100 elements.</p><p>After all this, to satisfy OTP semantics, we return back a tuple with the status ( &#39;ok in this case) and the supervisor pid.</p><h3>Conclusion</h3><p>This pretty much wraps it up. It turns out that due to the excellent work of the GRiSP and LFE teams, getting a basic application set up to run Lisp on the GRiSP isn’t terribly difficult.</p><p>I think the GRiSP is an incredibly cool device, and I think that the hard-real-time-world could really benefit from the OTP platform, due to its fault-tolerant guarantees and its overall simplicity compared to a language like C or C++. I look forward to doing more with this board, and I’ll be sure to provide updates here as I do.</p><p>There is currently a <a href="https://www.kickstarter.com/projects/peerstritzinger/grisp-2">KickStarter</a> for the GRiSP 2 going on. If anything I wrote here seems interesting, I highly recommend you check it out.</p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_image"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2IVAl0TbsfES9cFGYr40g.png" /></a></figure><p>📝 Read this story later in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_read_later_text">Journal</a>.</p><p>🗞 Wake up every Sunday morning to the week’s most noteworthy Tech stories, opinions, and news waiting in your inbox: <a href="https://usejournal.com/newsletter/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_text">Get the noteworthy newsletter &gt;</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9d387e28558" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pragmatics]]></title>
            <link>https://medium.com/@tombert/pragmatics-fb09f2d0a9a7?source=rss-4f0c09e501eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb09f2d0a9a7</guid>
            <category><![CDATA[life]]></category>
            <category><![CDATA[introspection]]></category>
            <category><![CDATA[philosophy]]></category>
            <dc:creator><![CDATA[Thomas Gebert]]></dc:creator>
            <pubDate>Sun, 29 Jul 2018 23:19:59 GMT</pubDate>
            <atom:updated>2018-07-29T23:19:59.776Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve never been especially good at the pragmatics, and I probably never will be. My interests rarely coincide with the the needs of a capitalist society, and as such most of my jobs inevitably morph into a futile attempt at a profession doing research into whatever topic I’m interested in for the day. Be it bizarre mathematics, an esoteric programming language, or something a bit more arcane like facts about old cartoons, I am unashamed and addicted autodidact.</p><p>A few months ago, my manager left me feedback at my job performance. Overall, it was fairly positive, basically saying that I’m smart and a relatively-ok worker, but the one blaring criticism ended up being “I wish Tom could get more excited about the stuff he’s working on”.</p><p>It was not surprising to read, but it was surprising how much the line stuck with me. Like most Americans, I typically try and deflect criticism and pretend that it doesn’t apply to me, but unlike most things like this, I couldn’t think of enough cognitive dissonance or mental gymnastics to dismiss the allegation. I didn’t (and couldn’t) care about what I was working on.</p><p>It’s not like the work was particularly uninteresting on any kind of inherent level, nor was it that the work wasn’t going anywhere. It was the ad-tech team of a relatively large corporation, and we were responsible for driving around eighty percent of the sales to the site. It’s not even that there wasn’t some fun to be had with the problems, since I would semi-regularly have to come up with semi-elaborate answers to computer science problems. I just didn’t care about what we were doing.</p><p>Since that day, I am sad to say, not a lot has changed. I still don’t particularly care about the work I’m doing, and I have to retreat to my fantasies of surviving entirely on trying out new things.</p><p>Three years ago I moved to New York to take a job that had the ostensible title of “Junior Research Scientist”. Somehow, I was going to manage, as a dropout, getting the profession of my dreams. I was going to defy all odds and join the ranks of yuppie intellectuals and drink fancy wine and talk about how much I like cheese or something.</p><p>It didn’t work out this way; “Junior Research Scientist” was just a catchall title for pretty much anyone that’s ever been within two-hundred feet of one of the campuses. There wasn’t a lot of research involved in the project I was working on, and even less for the “junior scientists”, and a large percentage of ended up being me working on working on a shitty web framework based on a slightly-modified AngularJS. Slowly, but consistently, I ended up withdrawing myself more and more from the work, becoming increasingly apathetic, accomplishing very little and caring even less.</p><p>I was eventually fired from that job. It was sad, but not unexpected; near the end I was showing up late, leaving early, and pushing one commit a day.</p><p>And so ended my first, and thus far only, gateway into research.</p><p>I don’t know how much longer I’m going to be at my current job. It’s a decent place, I my coworkers are nice, but I don’t think they really empathize with my dilemma. In a bizarre twist, that’s almost how I prefer it. Sometimes it’s better to be the only person who’s right instead being one of many.</p><p>The solitude of the pseudo-intellectual is as addictive as it is somber. I was not granted the genes of team-spirit, and I can live with that.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb09f2d0a9a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I’m trying out medium.]]></title>
            <link>https://medium.com/@tombert/im-trying-out-medium-bf792c8a17a7?source=rss-4f0c09e501eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf792c8a17a7</guid>
            <dc:creator><![CDATA[Thomas Gebert]]></dc:creator>
            <pubDate>Sat, 07 Feb 2015 00:58:52 GMT</pubDate>
            <atom:updated>2015-02-07T00:58:52.931Z</atom:updated>
            <content:encoded><![CDATA[<p>Blogging is a pain.</p><p>It’s weird, there are so many damn blogging platforms out there, and all of them suck in their own unique way. Ghost and Wordpress are ok, but they have ads if you host it yourself. Maybe Medium does too; I don’t know, I use ad-block, so I guess me worrying about it is irrelevant.</p><p>The WYSIWYG is nice, though I’d prefer to use Markdown. Oh well, I’ll play around with it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf792c8a17a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>