LFE – Quick start


This blog post will get you up and running with LFE in ~30 seconds. This will only prepare your computer for some serious fun. So don’t expect too much.

Short about LFE.
LFE is Erlang with Lisp syntax. It will twist your brain. Specially when you get a bit tired. So keep an eye on your focus. Just remember. It is more Erlang than Lisp. But with some nice features.

The one I’m going to mention is macros. Macros are very powerful. If it was only for macros, we would install LFE just for that. (A macro is a function that first create the code, then run it in the last step. No arguments are evaluated. Compared to normal functions.) Ok. enough about that. Later we will get a better understanding. First we need to install it.

Install Erlang
At the moment, Ubuntu’s Erlang version is 5.5.5. And is not working with current LFE. (Use “erl +V”, this will display version text.) To build latest and greatest version of Erlang, copy-paste this into your terminal.

sudo apt-get install build-essential libncurses5-dev libssl-dev m4 git-core
wget http://www.erlang.org/download/otp_src_R13B.tar.gz
tar xvf otp_src_R13B.tar.gz
cd otp_src_R13B
./configure
make
sudo make install

If all looks ok. Then it’s time for LFE.

Install LFE
Again, copy and paste.

git clone git://github.com/rvirding/lfe.git ~/lfe

lfe-mode in emacs
To make emacs recognize lfe files. We need to make emacs aware of LFE. Paste this into .emacs.

;; lfe-mode
(when (load "~/lfe/src/lfe-mode.el" t)
  (setq auto-mode-alist
        (cons '("\\.lfe\\'" . lfe-mode) auto-mode-alist)))

Hello world
Next step is to create your first program in LFE. Save this to a file called myhello.lfe.

(defmodule myhello
  (export (start 0)))

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

If you are used to Erlang you will see some familiar things.

  1. Module definition with export. That tells what functions are callable from the outside. The zero stands for zero arguments.
  2. Erlang string syntax for line feed (~n).

What’s interesting here is the colon. With colon you can call all Erlang BIFs (built-in functions). Else we can’t print out “Hello World”.

To make it easy I prepared this in a github project. You can just clone my hello-lfe and type make and make test.

cd
git clone git://github.com/cadar/hello-lfe.git
cd hello-lfe
make
make start

If all steps before this was success full. This will print “Hello world!”

I hope you see how easy it is. And how near you are total world domination. *my fingers are shivering*

Published in:  on August 25, 2008 at 9:16 am Comments (1)
Tags: , , ,