1
0
Fork
You've already forked fennel
0
No description
  • Fennel 71.2%
  • Lua 27.5%
  • Makefile 1.3%
2025年01月05日 12:52:12 -08:00
.circleci circleci: fix choco install for windows setup 2024年02月22日 17:40:29 -05:00
bootstrap Merge branch 'main' into precompile-macros 2024年10月09日 09:14:14 -07:00
build build/manfilter: assert on man section detection 2024年03月09日 12:35:40 -05:00
lua @ff102c0a68 Use git submodules for binary builds instead of tarballs. 2024年03月30日 17:54:31 -07:00
luajit @725ec37f2a Use git submodules for binary builds instead of tarballs. 2024年03月30日 17:54:31 -07:00
man Tidy up compile-time detection in quote. 2024年09月08日 09:50:58 -07:00
src Don't assume traceback data is a string in dosafely. 2025年01月05日 12:52:12 -08:00
test Fix runtime quoting of sequences. 2025年01月03日 10:20:03 -08:00
.build.yml Switch CI config over to JSON instead of YAML. 2023年12月01日 16:40:41 -08:00
.editorconfig editorconfig: Comment markdown trailing whitespace 2024年07月20日 18:29:46 -04:00
.gitignore Make certain build flags overrideable. 2023年08月01日 08:38:03 -07:00
.gitmodules Use git submodules for binary builds instead of tarballs. 2024年03月30日 17:54:31 -07:00
.luacov added 'coverage' target to Makefile using luacov 2020年06月28日 21:00:17 -04:00
api.md Clarify docs for fennel.parser. 2025年01月01日 13:55:39 -08:00
changelog.md Fix runtime quoting of sequences. 2025年01月03日 10:20:03 -08:00
CODE-OF-CONDUCT.md Remove mentions in code of conduct which imply we have multiple channels. 2024年05月31日 21:46:34 -07:00
CONTRIBUTING.md Clarify a few things in readme and contributing guide. 2024年05月31日 21:47:02 -07:00
from-clojure.md Various minor documentation fixes. 2023年12月22日 18:48:38 -08:00
LICENSE Clarify licensing. 2023年07月29日 13:57:21 -07:00
lua-primer.md Minor improvements to a lot of documentation. 2022年10月11日 17:03:37 -07:00
macros.md Explain the behavior of multi-values like unpack in quoted forms. 2025年01月01日 13:55:24 -08:00
Makefile Address a few linting suggestions. 2024年11月20日 17:48:38 -08:00
rationale.md A few documentation updates. 2021年11月06日 10:30:32 -07:00
README.md Fix makefile targets to initialize submodules when necessary. 2024年09月20日 21:10:10 -07:00
reference.md Document .inf and .nan in the reference. 2024年08月24日 17:37:36 -07:00
security.md Explain how to verify signatures. 2024年08月10日 18:07:05 -07:00
setup.md Release 1.5.1 2024年08月24日 18:34:54 -07:00
style.md Style guide updates. 2023年12月02日 11:30:26 -08:00
tutorial.md Clarify a few documentation issues. 2024年01月06日 18:50:30 -08:00
values.md Some wording in the compiler guide, mostly about bootstrapping. 2023年05月12日 23:12:14 -07:00

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 (< n2)n(+ (fib(- n1))(fib(- n2)))))(print (fib10))

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
  • Comprehensions result in much more succinct table transformations
  • 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 ~200kb
  • 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
  • Easy to build small (~250kb) standalone binaries
  • Compilation output has no runtime dependency on Fennel

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

Building 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)

If you don't have Lua already installed on your system, you can run make fennel-bin LUA=lua/src/lua instead to build a standalone binary that has its own internal version of Lua. This requires having a C compiler installed; normally gcc.

See the contributing guide for details about how to work on the source.

License

Unless otherwise listed, all files are copyright © 2016-2024 Calvin Rose and contributors, released under the MIT license.

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

The file style.txt is copyright © 2007-2011 Taylor R. Campbell, 2021-2023 Phil Hagelberg and contributors, released under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License: https://creativecommons.org/licenses/by-nc-sa/3.0/