Git Product home page Git Product logo

fennel's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.