Erlang Central

Lisp Flavoured Erlang

From ErlangCentral Wiki

Contents

Introduction

LFE, or Lisp Flavoured Erlang, is a Lisp syntax front-end to the Erlang compiler. LFE is a Lisp-2, like Common Lisp, and comes with a REPL (shell) for use with interactive coding. LFE allows one to write Erlang/OTP apps in a Lisp language, with full access to the BEAM ecosystem.

LFE-based projects coexist seamlessly with Core Erlang/OTP. As such, code written in LFE can freely be used together with modules written in other BEAM languages such as Erlang and Elixir. The reverse applies too: LFE libraries and services may be used by other Erlang/OTP projects.

Features

A few of LFE's features include:

  • . Homoiconicity
  • . Lisp macros
  • . Actor model
  • . Async
  • . High concurrency
  • . Pattern matching
  • . Functional programming language
  • . 100% interop with Erlang/OTP
  • . Interop with Java via JInterface and Erjang

More features are presented here.

Quick Start

LFE has a Quick Start guide. In 4 short pages, you will:

  • . Download and install lfetool.
  • . Create new LFE projects with a single command.
  • . Run LFE unit tests, see errors, and correct them.
  • . Learn to use the LFE REPL (shell).
  • . See what Erlang/OTP functions look like in LFE.
  • . Learn where to go next to dive in deeper.

Example Code

The front page of the docs site has some example code. As does page 3 of the Quick Start Guide.

The project source on Github has a directory dedicated to example code.

There are also a growing number of examples on Rosetta Code's LFE section.

Here is a quick bit of code, an LFE translation of Joe Armstrong's favourite Erlang program:

(defmodule joes-fav
  (export all))
 
(defun universal-server ()
  (receive
    ((tuple 'become server-function)
     (funcall server-function))))
 
(defun factorial
  ((0) 1)
  ((number) (* number (factorial (- number 1)))))
 
(defun factorial-server ()
  (receive
    ((tuple sender number)
     (! sender (factorial number))
     (factorial-server))))
 
(defun run-it ()
  (let ((pid (spawn #'universal-server/0)))
    (! pid (tuple 'become #'factorial-server/0))
    (! pid (tuple (self) 50)))
  (receive
    (data data)))

LFE Resources

Here are some additional resources for the interested reader: