
Fennel – Lisp in Lua - tosh
https://fennel-lang.org/
======
zokier
While I can't say much on the language (well, it's a Lisp), I must
congratulate the author for creating exemplary front page for it. The four key
bullet points as elevator pitch, code sample above the fold to grab attention,
embedded interpreter to play around, and the simple instructions how to run
locally now that I'm sold, it has it all without being too heavy or noisy or
anything. Clean, neat, beautiful.

------
le-mark
Looks like fennel compiles to lua; does that mean this is a blazing fast lisp
when using luajit? And you can call any lua library? A blazing fast lisp with
a large library ecosystem (luarocks)? That's very interesting indeed!

Edit; not bytecode, thanks

~~~
taeric
Just to go ahead and "be that person." Pretty sure CommonLisp already fits the
"blazing fast with a large library ecosystem."

The ecosystem can be somewhat confusing, because much of what would look like
abandoned packages in most ecosystems are more like completed packages, but
speed hasn't been a real failing of Common Lisp for a long time now. Talked
about a ton, of course.

~~~
nine_k
CL is a system in itself; it can be seen as an environment / OS, and has even
been used in this role.

Fennel piggy-backs on a known and _widely deployed_ language / VM.

This gives them different capabilities, and very different possible adoption
curves.

~~~
register
I agree: CL is a wonderful language but you have to embrace the whole
environment/philosophy if you want to adopt it. And the language is not so
easy to embed which prevents many "enterprise"/application development use
cases.

As a matter of fact the only game in town for embedding CL code is ECL which:
1) relies on the Bohem garbage collector 2) is LGPL licensed

Both points have cons which might discourage embedding of Common Lisp code in
other applications. Matters would be different if there was something like a
CL to C transplier adopting a generational GC distributed with a MIT/BSD like
license.

~~~
jarcane
SBCL on some benchmarks outperforms C, and what portions of the code are not
completely public domain are MIT/BSD licensed.

~~~
register
My point was not about peformances but rather about embedding. CL performances
are good and toghether with interactive development these are the main selling
points. It's a compiled programming language that feels like a scripting
language "done right". However try to develop something like an embeddable
library in SBCL and then use it in native Android, Ios , Mac and Windows
applications. This is something that can be done in Javascript, Go, Dart,
C,C++, Lua and so on. As far as I know the only CL that can achieve something
similar is ECL. In my opinion this limits considerably CL adoption because it
forces to adopt the entire ecosystem as a whole.

------
annywhey
Lua is emerging as a "everything compiles to it" source target - you can have
Lisp style syntax, you can have static types and JS style syntax with Haxe -
it's designed to piggyback off C codebases well - and on its own, it makes a
decent Lisp too. So there are a lot of potential benefits to building a stack
centered around Lua.

------
rileyphone
The winner of the last Lisp Game Jam ([https://technomancy.itch.io/exo-
encounter-667](https://technomancy.itch.io/exo-encounter-667)) was written
with it and love2d, seems pretty cool.

~~~
technomancy
This was my game, and I've contributed significantly to newer features in the
Fennel compiler; happy to oblige if you have any questions about either.

~~~
eggy
Wow, congrats! I just posted above about deciding on Fennel over Urn. Have you
checked out Lumen? What are your thoughts on it compared with Fennel? I want
to choose one to work on my own type of game dev, live coding toy experiments.

~~~
technomancy
I've looked briefly at Lumen. I don't do any JS work, so cross-compiling to JS
doesn't really appeal to me personally. I would expect that compiling to two
targets would make it more difficult to implement clean, readable compiler
output the way Fennel does, but I haven't checked.

The docs for Lumen are a bit sparse, but it looks like it doesn't make globals
opt-in or make you flag locals as mutable the way Fennel does. IME calling
these things out explicitly makes certain kinds of bugs easier to catch.
Fennel also allows for optional arity checks on functions.

I would expect that Lumen's keyword arguments would cause some complication
when interoperating with Lua, which doesn't have them. In addition, cross-
compiling to both JS and Lua means that it can't seamlessly support multiple
return values, which are used pervasively in 3rd-party Lua libraries.

As I mentioned elsewhere, Fennel can run in the browser with Fengari, but it's
a very different approach because Fengari includes a full Lua VM. This means
there's some overhead to load the VM (~220kb) but once it's loaded you get
access to coroutines, which are a _much_ nicer way to code non-blocking
functions than callbacks.

But these are just my initial uninformed impressions.

~~~
eggy
I don't do much JS either.

I am going to try Fennel, specifically look over your work on Fennel and the
game you did. I am sure it will speak tons to my questions. I can always try
and duplicate efforts in Lumen if I really want to know for myself if it is a
good fit for me and my needs. Thanks!

------
veli_joza
I'm currently looking for lisp-like language for Lua. I've looked into Urn,
Lumen and Fennel, still haven't decided on one.

Maybe someone can answer - why does fennel description insist on macros as
compile time feature? I'm interested in live coding and self-modifying code;
is there a speed penalty or some other reason why Fennel would be a bad
option?

~~~
dman
What problem domain are you working in?

~~~
veli_joza
I'm building the 2D interactive graphics engine for mobile platforms. The
focus is on authoring all of content on phone/tablet.

Instead of using bitmaps/meshes, the user starts with single primitive (y < 0
half-plane) and applies series of transformations (wrap, intersect, linear
transform...) to sculpture it into desired shape. This scene description looks
and behaves both like JSON tree and S-expressions.

For interactivity, I would like to have a lisp-like language that's visualized
as tree. The user would execute 'macros' to modify existing code, for example
to wrap a function into a loop or to make a mirror reflection of existing
graphics. The host should make sure that code is always syntactically correct
and should provide default primitives when constructing new code, that will be
replaced or modified by user.

Here's some WiP screenshots: [0]
[https://raw.githubusercontent.com/jmiskovic/arbo/master/medi...](https://raw.githubusercontent.com/jmiskovic/arbo/master/media/2018-08-29%20rotating%20rays.gif)
[1]
[https://raw.githubusercontent.com/jmiskovic/arbo/master/medi...](https://raw.githubusercontent.com/jmiskovic/arbo/master/media/2018-08-27%20clock.gif)
[2] [https://i.imgur.com/qzb6cC0.gif](https://i.imgur.com/qzb6cC0.gif)

------
lispm
Lisp in Lua? It does not have Lisp syntax and semantics.

Why would one call it 'Lisp' (which stands for 'Lisp Processor), when for
example it does not do list processing as in Lisp?

    
    
      > (list 1 2 3 4)
      [string "return list(1, 2, 3, 4)"]:1: attempt to call a nil value (global 'list')
      > (append '(1 2 3) '(3 4 5))
      Compile error in '3' unknown:3: cannot call literal value

------
whitten
So, since many mediawiki systems use lua, does this mean that you can code in
Lisp (or Fennel), transpile to Lua, and then run the code as a module in a
media wiki system?

What about Common Lisp libraries? would they be transpiled too?

Is there even a site with Common Lisp libraries written in common lisp to be
the source to be transpiled into Lua ?

~~~
technomancy
> So, since many mediawiki systems use lua, does this mean that you can code
> in Lisp (or Fennel), transpile to Lua, and then run the code as a module in
> a media wiki system?

Yes, easily.

With a little bit more work you could load the Fennel compiler up server-side
so it could do the compilation for you and support Fennel "natively". I have
done a similar process with TIC-80 despite knowing very little C:
[https://github.com/nesbox/TIC-80/pull/597](https://github.com/nesbox/TIC-80/pull/597)

> What about Common Lisp libraries? would they be transpiled too?

No, Common Lisp is a completely different language with little in common with
Fennel.

------
pq0ak2nnd
How much longer until every project is written in its own language? This
doesn't actually bother me: there is so little difference between the
proliferation of new languages that "mastery" is kind of a meaningless term.
Previous languages are tweaked for a particular task from a base language, and
the project / application is made a bit easier.

In other words: writing a custom language for each application in the name of
efficiency or more elegant patterns seems to make perfect sense.

------
ionforce
I admire projects like this.

I wonder if there's a master list of "this language X transpiles to language Y
and imitates language Z".

~~~
sitkack
There was a site, but it went offline years ago.
[https://github.com/tcr/langlangmatrix](https://github.com/tcr/langlangmatrix)

~~~
yunyu
Here's a link to the page that renders as HTML:
[https://rawgit.com/tcr/langlangmatrix/gh-
pages/index.html](https://rawgit.com/tcr/langlangmatrix/gh-pages/index.html)

(there will be a warning about loading unsafe scripts as the original file
loads jquery under http)

------
fithisux
Wish there was one for Tcl/Tk.

~~~
forgotpwd16
Why? Lua is embedded in numerous programs, as such targeting Lua is useful the
same way targeting JS for web is.

------
rufugee
Would this be a good first lisp to use for learning?

~~~
technomancy
There are a few factors at play that make a language good to learn:
simplicity, learning materials, and suitability for learning projects.

On the first point, Fennel is simpler than any other lisp I know, beyond "my
first interpreter" type Schemes. But you'll find much better learning
materials for some other lisps; in particular Racket is exemplary in this
regard.

So I would say it comes down to the learning projects you might want to build;
this is always the trickiest part of learning any language. If you want to
learn by creating a game, Fennel is a great choice. Likewise if you want to
extend an existing program that already has Lua support, such as AwesomeWM or
Redis. But for most "industrial" type projects that access external APIs or
write to existing file formats, you'll have a better time in Racket due to the
better library ecosystem.

~~~
lispm
I don't find it particular simple or a good Lisp. I don't think it is a Lisp
at all. It does not even know about QUOTE or basic list processing. If Fennel
is supposed to be a Lisp, than the concept of 'being a Lisp' is meaningless.

Actually the best Lisps are those who are actually Lisp (actually implementing
the particular syntax and semantics of Lisp) and not a transpiler to another
language. This other language leaks on all places.

Fennel is neither a Lisp nor a good learning environment for Lisp. Fennel is
actually some kind of Lisp/parentheses-inspired layer on top of Lua. That's
nice but not Lisp.

There are a lot of small Lisps which make learning Lisp much more easier.
Start with any small Scheme implementation and that's much nearer to Lisp than
Fennel will ever be: s-expressions, list processing, evaluator, code as data,
macros, data representation, tail/recursion, procedural abstraction, first
class functions, lambda calculus, etc etc. There is a lot of excellent
material in the Lisp world to teach that. There is even material how to do
useful things with that. None of that applies to Fennel. It does not do list
processing, its code as data is weak and Lua leaks everywhere.

------
sdinsn
I dig it

