Initial work on LFE began in 2007, when Robert Virding started creating a prototype of Lisp running on Erlang. This work was focused primarily on parsing and exploring what an implementation might look like. No version control system was being used at the time, so tracking exact initial dates is somewhat problematic. Virding announced the first release of LFE on the Erlang Questionsmail list in March 2008. This release of LFE was very limited: it did not handle recursive letrecs, binarys, receive, or try; it also did not support a Lisp shell. Initial development of LFE was done with version R12B-0 of Erlang on a Dell XPS laptop.
Motives
Robert Virding has stated that there were several reasons why he started the LFE programming language:
He had prior experience programming in Lisp.
Given his prior experience, he was interested in implementing his own Lisp.
In particular, he wanted to implement a Lisp in Erlang: not only was he curious to see how it would run on and integrate with Erlang, he wanted to see what it would look like.
Since helping to create the Erlang programming language, he had had the goal of making a Lisp which was specifically designed to run on the BEAM and able to fully interact with Erlang/OTP.
He wanted to experiment with compiling another language on Erlang. As such, he saw LFE as a means to explore this by generating Core Erlang and plugging it into the backend of the Erlang compiler.
Like Lisp, LFE is an expression-oriented language. Unlike non-homoiconic programming languages, Lisps make no or little syntactic distinction between expressions and statements: all code and data are written as expressions. LFE brought homoiconicity to the Erlang VM.
Lists
In LFE, the list data type is written with its elements separated by whitespace, and surrounded by parentheses. For example, is a list whose elements are the integers and, and the atom foo|. These values are implicitly typed: they are respectively two integers and a Lisp-specific data type called a symbolic atom, and need not be declared as such. As seen in the example above, LFE expressions are written as lists, using prefix notation. The first element in the list is the name of a form, i.e., a function, operator, or macro. The remainder of the list are the arguments.
Operators
The LFE-Erlang operators are used in the same way. The expression
evaluates to 42. Unlike functions in Erlang and LFE, arithmetic operators in Lisp are variadic, able to take any number of arguments.
LFE has lambda, just like Common Lisp. It also, however, has lambda-match to account for Erlang's pattern-matching abilities in anonymous function calls.
Erlang idioms in LFE
This section does not represent a complete comparison between Erlang and LFE, but should give a taste.
Pattern matching
Erlang: 1> =.
2> Msg. "Trillian"
LFE: > #) # > msg "Trillian"
List comprehensions
Erlang: 1>
LFE: > )
Or idiomatic functional style: > ')
Guards
Erlang: right_number when X 42; X 276709 -> true; right_number -> false.
LFE: )) 'true) )
cons'ing in function heads
Erlang: sum -> sum. sum -> Total; sum -> sum.
LFE: ) total) ))
or using a ``cons`` literal instead of the constructor form: ) total) )
Using recursion to define the Ackermann function: )
))
Composing functions:
))
)
))
Concurrency
Message-passing with Erlang's light-weight "processes": ))
))) ))) ))
Multiple simultaneous HTTP requests: "Given one or more command-line arguments, extract the passed values. For example, if the following was passed via the command line: $ erl -my-flag my-value-1 -my-flag my-value-2 One could then extract it in an LFE program by calling this function:
... ) In this example, the value assigned to the arg variable would be a list containing the values my-value-1 and my-value-2." )) )) "With no argument, assume 'url parameter was passed via command line."