ArticleslgStudy

science

LFE (programming language)

LFE (programming language) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand LFE (programming language) rather than just read about it. In short: Lisp Flavored Erlang (LFE) is a functional, concurrent, garbage collected, general-purpose programming language and Lisp dialect built on Core Erlang and the Erlang virtual machine (BEAM). LFE builds on Erlang to provide a Lisp syntax for writing distributed, fault-tolerant, soft real-time, non-stop applications.

LFE (programming language) — main illustration
LFE (programming language) — illustration

Key takeaways

  • LFE (programming language) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect LFE (programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of LFE (programming language) from memory before moving on to harder problems.

Reference excerpt

Lisp Flavored Erlang (LFE) is a functional, concurrent, garbage collected, general-purpose programming language and Lisp dialect built on Core Erlang and the Erlang virtual machine (BEAM). LFE builds on Erlang to provide a Lisp syntax for writing distributed, fault-tolerant, soft real-time, non-stop applications. LFE also extends Erlang to support metaprogramming with Lisp macros and an improved developer experience with a feature-rich read–eval–print loop (REPL). LFE is actively supported on all recent releases of Erlang; the oldest version of Erlang supported is R14.

History

Initial release 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 Questions mail 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.

Features A language targeting Erlang virtual machine (BEAM) Seamless Erlang integration: zero-penalty Erlang function calls (and vice versa) Metaprogramming via Lisp macros and the homoiconicity of a Lisp Common Lisp-style documentation via both source code comments and docstrings Shared-nothing architecture concurrent programming via message passing (Actor model) Emphasis on recursion and higher-order functions instead of side-effect-based looping A full read–eval–print loop (REPL) for interactive development and testing (unlike Erlang's shell, the LFE REPL supports function and macro definitions) Pattern matching Hot loading of code A Lisp-2 separation of namespaces for variables and functions Java inter-operation via JInterface and Erjang Scripting abilities with both lfe and lfescript

Syntax and semantics

Symbolic expressions (S-expressions) 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, (list 1 2 'foo) is a list whose elements are the integers 1 and 2, and the atom [[foo|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 (or n-ary), able to take any number of arguments.

Lambda expressions and function definition 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:

LFE:

List comprehensions Erlang:

LFE:

Or idiomatic functional style:

Guards Erlang:

LFE:

cons'ing in function heads Erlang:

LFE:

or using a ``cons`` literal instead of the constructor form:

Matching records in function heads Erlang:

LFE:

Receiving messages Erlang:

LFE:

or:

Examples

Erlang interoperability Calls to Erlang functions take the form (<module>:<function> <arg1> ... <argn>):

Functional paradigm Using recursion to define the Ackermann function:

Composing functions:

Concurrency Message-passing with Erlang's light-weight "processes":

Multiple simultaneous HTTP requests:

References

External links Official website LFE on GitHub LFE Quick Start LFE User Guide LFE on Rosetta Code

Illustrations

LFE (programming language) illustration
LFE (programming language): Robert Virding
Robert Virding

Worked examples

Example 1 — a first encounter with LFE (programming language)

Start with the simplest possible case. Write down what LFE (programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to LFE (programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about LFE (programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of LFE (programming language)

In research
LFE (programming language) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses LFE (programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
LFE (programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Lisp programming language family, Pattern matching programming languages, Programming languages, so understanding it makes those chapters shorter.
In everyday life
Look for LFE (programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study LFE (programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what LFE (programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain LFE (programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is LFE (programming language) in simple terms?

Lisp Flavored Erlang (LFE) is a functional, concurrent, garbage collected, general-purpose programming language and Lisp dialect built on Core Erlang and the Erlang virtual machine (BEAM). LFE builds on Erlang to provide a Lisp syntax for writing distributed, fault-tolerant, soft real-time, non-sto…

Why does LFE (programming language) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study LFE (programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on LFE (programming language).

Tags

  • Lisp programming language family
  • Pattern matching programming languages
  • Programming languages

Keep exploring