• Stars
    star
    2,443
  • Rank 18,821 (Top 0.4 %)
  • Language Fennel
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lua Lisp Language

Fennel

Fennel is a lisp that compiles to Lua. It aims to be easy to use, expressive, and has almost zero overhead compared to writing Lua directly.

  • Full Lua compatibility - You can use any function or library from Lua.
  • Zero overhead - Compiled code should be just as efficient as hand-written Lua.
  • Compile-time macros - Ship compiled code with no runtime dependency on Fennel.
  • Embeddable - Fennel is a one-file library as well as an executable. Embed it in other programs to support runtime extensibility and interactive development.

At https://fennel-lang.org there's a live in-browser repl you can use without installing anything. At https://fennel-lang.org/see you can see what Lua output a given piece of Fennel compiles to, or what the equivalent Fennel for a given piece of Lua would be.

Documentation

  • The setup guide is a great place to start
  • The tutorial teaches the basics of the language
  • The rationale explains the reasoning of why Fennel was created
  • The reference describes all Fennel special forms
  • The macro guide explains how to write macros
  • The API listing shows how to integrate Fennel into your codebase
  • The style guide gives tips on how to write clear and concise code
  • The Lua primer gives a very brief intro to Lua with pointers to further details

For more examples, see the cookbook on the wiki.

The changelog has a list of user-visible changes for each release.

Example

Hello World

(print "hello, world!")

Fibonacci sequence

(fn fib [n]
  (if (< n 2)
      n
      (+ (fib (- n 1)) (fib (- n 2)))))

(print (fib 10))

Building Fennel from source

Building Fennel from source allows you to use versions of Fennel that haven't been released, and it makes contributing to Fennel easier.

To build Fennel from source

This requires GNU Make and Lua (5.1-5.4 or LuaJIT).

  1. cd to a directory in which you want to download Fennel, such as ~/src
  2. Run git clone https://git.sr.ht/~technomancy/fennel
  3. Run cd fennel
  4. Run make fennel to create a standalone script called fennel
  5. Run sudo make install to install system-wide (or make install PREFIX=$HOME if ~/bin is on your $PATH)

Differences from Lua

  • Syntax is much more regular and predictable (no statements; no operator precedence)
  • It's impossible to set or read a global by accident
  • Pervasive destructuring anywhere locals are introduced
  • Clearer syntactic distinction between sequential tables and key/value tables
  • Separate looping constructs for numeric loops vs iterators instead of overloading for
  • Opt-in mutability for local variables
  • Opt-in nil checks for function arguments
  • Pattern matching
  • Ability to extend the syntax with your own macros

Differences from other lisp languages

  • Its VM can be embedded in other programs with only 180 kB
  • Access to excellent FFI
  • LuaJIT consistently ranks at the top of performance shootouts
  • Inherits aggressively simple semantics from Lua; easy to learn
  • Lua VM is already embedded in databases, window managers, games, etc
  • Low memory usage
  • Readable compiler output resembles input

Why not Fennel?

Fennel inherits the limitations of the Lua runtime, which does not offer pre-emptive multitasking or OS-level threads. Libraries for Lua work great with Fennel, but the selection of libraries is not as extensive as it is with more popular languages. While LuaJIT has excellent overall performance, purely-functional algorithms will not be as efficient as they would be on a VM with generational garbage collection.

Even for cases where the Lua runtime is a good fit, Fennel might not be a good fit when end-users are expected to write their own code to extend the program, because the available documentation for learning Lua is much more readily-available than it is for Fennel.

Resources

License

Unless otherwise listed, all files are copyright © 2016-2023 Calvin Rose and contributors.

The file test/faith.fnl is copyright © 2009-2023 Scott Vokes, Phil Hagelberg, and contributors

All files released under the MIT license.

More Repositories

1

tiny-ecs

ECS for Lua
Lua
661
star
2

binser

Customizable Lua Serializer
Lua
197
star
3

moonmint

A Web Framework for Lua
Lua
75
star
4

Splash.lua

2D Spatial Hashing in Lua
Lua
71
star
5

mendoza

A Static Site Generator
Janet
54
star
6

fennel.vim

Syntax highlighting for Fennel
Vim Script
51
star
7

Editgrid

gamera and HUMP compatible scaling grid for LÖVE
Lua
44
star
8

CommandoKibbles

Cannon Cat Game for Ludum Dare 32
Lua
39
star
9

luamd

Markdown to HTML in pure Lua.
Lua
33
star
10

corope

Lua threading utility using coroutines.
Lua
29
star
11

littleserver

A simple test HTTP server for Janet, circlet, and jpm.
13
star
12

ats-lua

An ATS to Lua compiler
ATS
9
star
13

janet-miniz

Janet bindings to the miniz library.
C
7
star
14

ldmath.h

Home rolled header only c game math lib.
C
7
star
15

ats2.vim

A vim package for working with the ATS2 language.
Vim Script
5
star
16

x43bot

Just an IRC bot.
4
star
17

weregoat

Game for Ludum Dare 33
Lua
4
star
18

libatscc2lua

Runtime library for code compiled from ATS to Lua
Lua
4
star
19

mcu-serve

HTTP Server for NodeMCU + ESP32
HTML
4
star
20

WTBUiOS

Boston University WTBU app
Swift
3
star
21

bkdoc

Markup format and compiler that can output to different document formats.
C
3
star
22

dotfiles

My Dotfiles
Shell
2
star
23

EGF

A Java entity-component game framework that uses slick.
Java
2
star
24

go

Go in ClojureScript - Play at
JavaScript
1
star
25

ldoomc

C GL code
C
1
star
26

msp432-morse

Example project for the msp432p401r microcontroller
C
1
star
27

truss-analysis

MATLAB
1
star
28

ezglib

An Easy Game Library in ClojureScript
Clojure
1
star
29

TankLand

A tank simulation written in Clojure
Clojure
1
star
30

heroku-buildpack-moonmint

A Heroku buildpack for LuaJIT and the moonmint server
CMake
1
star