bakpakin / Fennel翻译 / 编辑

最近提交:6天前
创建时间:2016.08.08

语言构成

Lua99.0%
Shell0.7%
Makefile0.2%

README

Fennel

Fennel (formerly fnl) is a lisp that compiles to Lua. It aims to be easy to use, expressive, and has almost zero overhead compared to handwritten Lua. It's currently a single file Lua library that can be dragged into any Lua project.

Current features include:

  • Full Lua compatibility - You can use any function from Lua.
  • Zero overhead - Compiled code should be fast, standalone, and just as or more efficient than hand-written Lua.
  • Compile time only macros - Macros exist only at compile time and are not output in the final Lua compilation. In fact, macros are just a special case of special forms.
  • Ability to write custom special forms - Special forms are s-expressions that, when evaulated, directly output Lua code.
  • Fennel is a library as well as a compiler. Embed it in other projects.

Documentation

  • The tutorial is a great place to start
  • The reference describes all Fennel special forms
  • The API listing shows how to integrate Fennel into your codebaes
  • The Lua primer gives a very brief intro to Lua with pointers to further details
  • The test suite has basic usage examples for most features.

For a small complete example that uses the LÖVE game engine, see pong.fnl.

Example

Hello World

(print "hello, world!")

Fibonacci sequence

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

(print (fib 10))

Try it

At https://fennel-lang.org there's a live in-browser repl you can use without installing anything.

Otherwise clone this repository, and run ./fennel --repl to quickly start a repl.

The repl will load the file ~/.fennelrc on startup if it exists.

Install with Luarocks

You can install the dev package from luarocks via

luarocks install --server=http://luarocks.org/dev fennel

This will install both the fennel module, which can be required into via local fennel = require 'fennel', as well as the fennel executable which can be used to run a repl or compile Fennel to Lua.

To start a repl:

fennel --repl

To compile a file:

fennel --compile myscript.fnl > myscript.lua

When given a file without a flag, it will simply load and run the file.

Resources

License

Copyright © 2016-2018 Calvin Rose and contributors

Released under the MIT license

讨论区

说说你的看法