Jump to content
Search

The new Ubuntu Wiki is live. Legacy content may be unavailable and page links may have changed. Read the announcement on Discourse.

Fennel

From Ubuntu Wiki

Fennel[1] is a Lisp-like programming language that compiles to Lua.

Some developers, for example, write games in Fennel that target the Lua-based Love2d framework[2].

Install

Run the following command:

sudo apt install fennel

Compiling to Lua

For comparison, take the following example code from the Lua guide:

local function greet(name)
  local msg = "Hello, " .. name .. "!"
  return msg
end

print(greet("world"))

Create the following hello.fnl file:

(fn greet [name]
  (let [msg (.. "Hello, " name "!")]
    msg))

(print (greet "world"))

Then compile to Lua with fennel --compile hello.fnl, which should print:

local function greet(name)
  local msg = ("Hello, " .. name .. "!")
  return msg
end
return print(greet("world"))

As you can see, the original Lua code and the generated code are essentially equivalent.

Running the program

To run the code directly, use:

fennel hello.fnl