Skip to the content.

LFE (Lisp Flavored Erlang)

Information

LFE (Lisp Flavored Erlang) is a Lisp (S-expression) syntax for Erlang, providing a full-featured Lisp system that runs on the Erlang VM (BEAM). Created by Robert Virding (one of the original creators of Erlang), it was designed to provide a Lisp that is 100% compatible with Erlang.

Relation to Erlang

LFE is not just “like” Erlang; it is Erlang in a Lisp syntax. Key points of its relationship include:

Installation

LFE is typically managed as a dependency in a rebar3 project.

Using rebar3

Add lfe as a dependency in your rebar.config:

{deps, [
    {lfe, "2.1.2"}
]}.

{plugins, [
    {rebar3_lfe, "0.4.8"}
]}.

Manual Installation (on Linux)

git clone https://github.com/lfe/lfe.git
cd lfe
make
sudo make install

Usage, tips and tricks

Interactive REPL

Start the LFE REPL with:

lfe

Example session:

> (+ 1 2 3)
6
> (lfe_io:format "Hello, ~s!~n" '("World"))
Hello, World!
ok

Defining a Module

(defmodule hello
  (export (world 0)))

(defun world ()
  (lfe_io:format "Hello from LFE!~n" '()))

Calling Erlang from LFE

You can call Erlang modules directly using the :module:function syntax:

(: lists map (lambda (x) (* x 2)) '(1 2 3))
;; Returns (2 4 6)

See also