Convert Figma logo to code with AI

lfe logolfe

Lisp Flavoured Erlang (LFE)

2,339
141
2,339
35

Top Related Projects

11,496

Erlang/OTP

24,771

Elixir is a dynamic, functional language for building scalable and maintainable applications

18,601

⭐️ A friendly language for building type-safe, scalable systems!

1,442

Functional programming inspired by ML for the Erlang VM

Quick Overview

LFE (Lisp Flavored Erlang) is a Lisp-2 dialect of the Erlang programming language, designed to leverage the power and robustness of the Erlang/OTP ecosystem. It provides a Lisp-based syntax and a set of libraries that integrate seamlessly with Erlang.

Pros

  • Powerful Lisp Syntax: LFE offers a Lisp-inspired syntax, which can be more expressive and concise than the traditional Erlang syntax.
  • Erlang Ecosystem Integration: LFE allows developers to leverage the vast Erlang/OTP ecosystem, including libraries, tools, and the Erlang Virtual Machine (BEAM).
  • Concurrency and Fault Tolerance: LFE inherits Erlang's strengths in building concurrent, fault-tolerant, and scalable systems.
  • Functional Programming Paradigm: LFE embraces the functional programming paradigm, which can lead to more maintainable and testable code.

Cons

  • Smaller Community: Compared to Erlang, the LFE community is relatively smaller, which may result in fewer available libraries and resources.
  • Learning Curve: Developers who are not familiar with Lisp or functional programming may face a steeper learning curve when transitioning to LFE.
  • Niche Usage: LFE is a niche language, and its adoption may be limited compared to more mainstream programming languages.
  • Potential Compatibility Issues: As a Lisp dialect, LFE may have some compatibility issues with existing Erlang libraries or tools.

Code Examples

Here are a few code examples demonstrating LFE's syntax and features:

Defining a Simple Function

(defun hello-world ()
  (io:format "Hello, world!~n"))

This code defines a simple function hello-world that prints the message "Hello, world!" to the console.

Handling Concurrency with Processes

(defun worker (name)
  (receive
    (msg
     (io:format "~p received message: ~p~n" (list name msg))
     (worker name))))

(defun start-workers ()
  (spawn (lambda () (worker 'worker1)))
  (spawn (lambda () (worker 'worker2)))
  (spawn (lambda () (worker 'worker3))))

This example demonstrates how to create and manage concurrent processes in LFE, a key feature inherited from Erlang.

Pattern Matching and List Manipulation

(defun sum-list (list)
  (cond
    ((null list) 0)
    ((cons? list) (+ (car list) (sum-list (cdr list))))))

(sum-list '(1 2 3 4 5)) ; => 15

This function demonstrates LFE's pattern matching capabilities and how to recursively process a list.

Getting Started

To get started with LFE, you can follow these steps:

  1. Install Erlang and Rebar3 (the build tool for Erlang/LFE projects) on your system.

  2. Install LFE using the Rebar3 package manager:

    rebar3 update
    rebar3 install lfe
    
  3. Create a new LFE project using Rebar3:

    rebar3 new lfe-lib my-lfe-project
    cd my-lfe-project
    
  4. Write your LFE code in the src/ directory, and then compile and run your project:

    rebar3 compile
    rebar3 shell
    

    This will start an LFE REPL (Read-Eval-Print Loop) where you can interactively test your code.

  5. Explore the LFE documentation and community resources to learn more about the language and its features.

Competitor Comparisons

11,496

Erlang/OTP

Pros of OTP

  • Mature and battle-tested ecosystem with extensive libraries and tools
  • Excellent support for distributed systems and fault-tolerance
  • Robust standard library with comprehensive documentation

Cons of OTP

  • Steeper learning curve due to unique syntax and concepts
  • Less familiar to developers coming from mainstream programming languages
  • Limited support for certain programming paradigms (e.g., object-oriented programming)

Code Comparison

LFE (Lisp Flavoured Erlang):

(defun factorial (n)
  (if (=< n 1)
      1
      (* n (factorial (- n 1)))))

Erlang (OTP):

factorial(N) when N =< 1 -> 1;
factorial(N) -> N * factorial(N - 1).

Summary

OTP is a mature and powerful platform for building scalable, fault-tolerant systems, while LFE offers a Lisp-like syntax on top of the Erlang VM. OTP provides a more extensive ecosystem and better documentation, but LFE may be more appealing to developers familiar with Lisp-like languages. Both share the same underlying runtime, allowing interoperability between Erlang and LFE code. The choice between them often depends on personal preference and specific project requirements.

24,771

Elixir is a dynamic, functional language for building scalable and maintainable applications

Pros of Elixir

  • More modern syntax and features, making it easier for developers coming from other languages
  • Larger and more active community, resulting in better documentation and more libraries
  • Built-in support for concurrent and distributed programming with the actor model

Cons of Elixir

  • Steeper learning curve for developers unfamiliar with functional programming concepts
  • Less direct access to Erlang's features and libraries compared to LFE
  • Slightly slower compilation times due to additional language features

Code Comparison

LFE (Lisp Flavored Erlang):

(defun factorial (n)
  (if (=< n 1)
      1
      (* n (factorial (- n 1)))))

Elixir:

def factorial(n) do
  if n <= 1, do: 1, else: n * factorial(n - 1)
end

Both LFE and Elixir are functional programming languages that run on the Erlang VM (BEAM). LFE provides a Lisp-like syntax and direct access to Erlang features, while Elixir offers a more Ruby-inspired syntax with additional language features. Elixir has gained more popularity and has a larger ecosystem, but LFE remains an excellent choice for Lisp enthusiasts who want to leverage the power of the Erlang ecosystem.

18,601

⭐️ A friendly language for building type-safe, scalable systems!

Pros of Gleam

  • Modern type system with type inference, providing better safety and developer experience
  • Compiles to Erlang bytecode, allowing seamless integration with existing BEAM ecosystem
  • Designed with a focus on developer ergonomics and productivity

Cons of Gleam

  • Younger project with a smaller community and ecosystem compared to LFE
  • Less direct compatibility with Erlang/OTP idioms and patterns
  • Steeper learning curve for developers already familiar with Lisp-like syntax

Code Comparison

Gleam:

pub fn factorial(n: Int) -> Int {
  case n {
    0 | 1 -> 1
    _ -> n * factorial(n - 1)
  }
}

LFE:

(defun factorial
  ((0) 1)
  ((1) 1)
  ((n) (* n (factorial (- n 1)))))

Summary

Gleam offers a more modern, type-safe approach to BEAM languages, while LFE provides a Lisp-like syntax familiar to some developers. Gleam focuses on developer ergonomics and safety, whereas LFE offers closer alignment with Erlang/OTP patterns. Both compile to Erlang bytecode, enabling interoperability with the BEAM ecosystem. The choice between them often depends on personal preference, team expertise, and specific project requirements.

1,442

Functional programming inspired by ML for the Erlang VM

Pros of Alpaca

  • Designed for modern functional programming with a focus on type safety
  • Offers a more Haskell-like syntax, which may be familiar to some developers
  • Includes built-in support for algebraic data types and pattern matching

Cons of Alpaca

  • Smaller community and ecosystem compared to LFE
  • Less mature and potentially less stable than LFE
  • Limited documentation and learning resources available

Code Comparison

Alpaca:

module Hello
let main = 
  io.println "Hello, World!"

LFE:

(defmodule hello
  (export (start 0)))

(defun start ()
  (io:format "Hello, World!~n"))

Summary

Alpaca is a newer language that focuses on modern functional programming concepts and type safety, while LFE (Lisp Flavored Erlang) is more established and closely tied to the Erlang ecosystem. Alpaca may appeal to developers familiar with Haskell-like syntax, while LFE offers a Lisp-based approach to Erlang programming. The choice between the two depends on specific project requirements, team expertise, and desired language features.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

LFE

Build Status Hex.pm version Hex.pm downloads Hex.pm weekly downloads Hex.pm daily downloads

LFE, Lisp Flavoured Erlang, is a lisp syntax front-end to the Erlang compiler. Code produced with it is compatible with "normal" Erlang code. An LFE evaluator and shell is also included.

Building

To compile LFE, simple clone it and compile:

$ git clone https://github.com/lfe/lfe.git
$ cd lfe
$ make compile

LFE requires Erlang be installed on the system and that the erl binary is in $PATH.

Running the Tests

To run the full suite of tests for LFE, simply use the following:

make tests

Installation

Should you wish to have LFE available system-wide, you can run the following make target:

$ make install

By default this will create the programs lfe, lfec, lfedoc and lfescript in /usr/local/bin. This can be changed by defining the make variable PREFIX to point to the desired parent directory.

Note that the install target will also install the LFE man pages in the appropriate $(PREFIX)/share/man/man* directories. This can be changed by defining the make variable MANINSTDIR to point to the desired top man directory.

So:

$ make install PREFIX=/Users/rv/ MANINSTDIR=/Users/rv/man

will put the programs in /Users/rv/bin and the man pages in the /Users/rv/man/man* directories.

REPL

If you're running LFE from a git clone working dir, you can start the REPL like so after compiling:

$ ./bin/lfe
Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]

   ..-~.~_~---..
  (      \\     )    |   A Lisp-2+ on the Erlang VM
  |`-.._/_\\_.-':    |   Type (help) for usage info.
  |         g |_ \   |
  |        n    | |  |   Docs: http://docs.lfe.io/
  |       a    / /   |   Source: http://github.com/lfe/lfe
   \     l    |_/    |
    \   r     /      |   LFE v2.1.5 (abort with ^G)
     `-E___.-'

lfe>

If you have installed LFE, then you may start the REPL from any location:

$ lfe

Likewise, you may run an LFE shell script in the same style as shell scripts with:

$ ./bin/lfe script-name script-arg-1 ...

or

$ lfe script-name script-arg-1 ...

Usage

The docs site has several places to explore that will show you how to start using LFE. However, here's a quick taste:

  • start up an LFE REPL as demonstrated above
  • then, do something like this:
lfe> (* 2 (+ 1 2 3 4 5 6))
42
lfe> (* 2 (lists:foldl #'+/2 0 (lists:seq 1 6)))
42

Docker Support

LFE now supports Docker. To get started, simply do the following, once you have Docker set up on your machine:

$ docker pull lfex/lfe

Alternatively, you could build the image yourself:

$ cd lfe
$ docker build .

To bring up the LFE REPL:

$ docker run -it lfex/lfe

Documentation

Files with more technical details:

If you would like to make changes to the LFE documentation and then regenerate the docs, you'll want to read the instructions here:

Join the Community

LFE on Slack, join by requesting an invite here

LFE Forum - Erlang Forums

Maintainers

Cutting Releases

Steps:

  1. Update the version in src/lfe.app.src
  2. Create the release tags
  3. Create a release on Github
  4. Publish to hex.pm

Once the app.src has been updated with the version for the release, you can create and push the tags (to Github) with the following:

make tags

That will create the number-only version as well as the "v"-prefixed version.

For now, the process of creating a release on Github is manual:

  1. Go to https://github.com/lfe/lfe/releases
  2. Click "Draft new release"
  3. Select the correct tag from the drop-down "Choose a tag"
  4. Click "Generate release notes"
  5. Click "Publish release"

Lastly, to publish LFE to hex.pm, you need to have rebar3 installed on our system and an entry for the hex plugin in your system rebar.config file. With that in place, publish a new release to hex.pm requires only the following:

make hex-publish