Lisp Flavoured Erlang and Pynchon, oh my!

Eric Bailey

Written on 6 August, 2015
Updated on 16 December, 2023
Tags: , , , ,

So, lately I've been getting increasingly into Lisp Flavoured Erlang (LFE). If you haven't tried it yet, or even if you have, check out the Exercism LFE track I helped organize. My latest endeavour is porting Robert Levy's swiss-arrows from Clojure to LFE. It's been going well so far, despite having to rename it to pynchon, since Erlang wasn't down with the hyphenated name and a few people on the LFE Google group suggested it.

Example

Without further ado, here's a contrived example. #'compose/2 comes from Duncan McGreggor's clj, Clojure functions and macros for LFE, which has since been merged into LFE.

(-<> "testing"
     (-!<>> (string:substr <> 1 4)
            (lists:duplicate 3)
            (compose #'list/1 #'lists:flatten/1)
            (lfe_io:format '"non-updating: ~p\n"))
     (string:substr 5)
     (++ "winn" <>))

The wild-looking form above expands to something more like the following.

(-<>
 (progn
   (lfe_io:format
    '"non-updating: ~p\n"
    (list
     (lists:flatten
      (lists:duplicate 3 (string:substr "testing" 1 4)))))
   "testing")
 (string:substr 5)
 (++ "winn" <>))

After that, it becomes apparent the "return track" is rather simple.

(++ "winn" (string:substr 5 "testing"))
> (-<> "testing"
       (-!<>> (string:substr <> 1 4)
              (lists:duplicate 3)
              (compose #'list/1 #'lists:flatten/1)
              (lfe_io:format '"non-updating: ~p\n"))
       (string:substr 5)
       (++ "winn" <>))
non-updating: "testtesttest" ; printed
"winning"                    ; returned