11 ms·
Fennel – Lisp in Lua
- rcarmo 6y agoIt should be noted that 0.6.0 came out 3 days ago, with a few improvements: https://fennel-lang.org/v0.6.0/ https://fennel-lang.org/v0.6.0/
- rudolfwinestock 6y agoA Hacker News regular, technomancy (the same guy behind the Atreus keyboard), has contributed a great deal to the Fennel language. https://builds.sr.ht/~technomancy/fennel-lang.org https://builds.sr.ht/~technomancy/fennel-lang.org I'd like to see him visit this thread. https://news.ycombinator.com/user?id=technomancy https://news.ycombinator.com/user?id=technomancy
- reitzensteinm 6y agoNot to mention lein for Clojure. He only posts here a few times a year which might be how he manages to be so prolific.
- O_H_E 6y agoAhh, that's whats probably holding me back. \s .... but not really. I need to figure out a way to tone down my mind wandering off.
- bokchoi 6y agoAnd if you haven't checked out his pico-8 game he used fennel to write, you ought to. It's great! https://technomancy.us/190 https://technomancy.us/190
- pragmatic 6y agoHe posts more frequently on lobsters. https://lobste.rs/u/technomancy https://lobste.rs/u/technomancy
- miguendes 6y agoInteresting project. I had never heard of a lisp flavour for lua before. Looks very elegant. It reminds me of hy, for python. [1] [1] https://github.com/hylang/hy https://github.com/hylang/hy
- mumblemumble 6y agoI haven't spent any time with Fennel, but it seems more promising to me. I couldn't get comfortable with Hy. It drops so many lispy things, such as let statements and persistent data structures, in order to stay close to the Python substrate. (You can get both from libraries, but at the cost of easy interop with Python packages, which kind of defeats the whole point of being on the Python platform in the first place.) It ultimately came out feeling less like I was working with a lisp, and more like I was working with an s-expression syntax for Python. OTOH, if you think that Python, while otherwise great, is really suffering for lack of defmacro, Hy absolutely succeeds in getting you Python with defmacro.
- rcarmo 6y agoI ended up dropping Hy very soon after they dropped let. Had an entire blog engine written in it: https://github.com/rcarmo/sushy https://github.com/rcarmo/sushy ...but I wanted Hy to be LISP, not a thin veneer over Python.
- dunham 6y agoThere is another small lisp that targets both Lua and Javascript called "lumen"[1]. Small enough that you can easily tinker with it. I added clojure style {} literals to the reader and paired it with hyperapp to write a toy web application. [1]: https://github.com/sctb/lumen https://github.com/sctb/lumen
- Rochus 6y agoPlenty of lisp frontends for lua, see https://github.com/hengestone/lua-languages#lisp https://github.com/hengestone/lua-languages#lisp
- rcarmo 6y ago
- j_m_b 6y agoWhat are some projects that people are using that use Lua? Why use it over something like python for scripting?
- stevedonovan 6y agoProbably because Lua is meant to be embedded in an application and provides a small, highly optimized VM. On my system Lua is smaller than PCRE.
- stevekemp 6y agoI wrote a console-based email-client, using Lua for all configuration and scripting needs. Using Lua is generally done because it is easy to embed inside a host-application. While it is possible to embed Python, Perl, or other languages, they're relatively heavyweight and not so commonly used in that case. In my own application I always felt annoyed that mutt didn't have "real" scripting. Just an ad-hoc configuration that made lots of things possible, but neglected some basics (such as loops and similar). Configuring a mail-client in Lua was a nice exercise, but eventually I moved on to pay for gsuite rather than self-hosting a mailserver of my own so it became a "done" project. Definitely a useful learning experience though, experimenting with user-interface, embedded scripting, and going through lots of learning relating to MIME-handling & etc.
- fit2rule 6y agoYour project sounds cool - is it possible to process email with Lua scripts, so that I could use a mailbox as a business process queue that is also user-friendly, while having a suite of Lua apps processing the mailboxes? If so, care to share details of your project if its open/available?
- stevekemp 6y agoIt wouldn't be impossible to iterate over a series of mails, and get the message-bodies, but it would be a bit fiddly and annoying as the program was more designed as an email-client. https://github.com/lumail/lumail/ https://github.com/lumail/lumail/ https://lumail.org/ https://lumail.org/ Honestly I'd probably write something in perl/go/similar to just walk over a remote IMAP mailbox: * Search for messages that are unread, or which don't have a given tag. * Process each one. * Mark as read, or add a tag. (I actually did something like that recently for processing DMARC reports.)
- mumblemumble 6y agoA nice summary of what Fennel's about here: http://jakob.space/blog/thoughts-on-lisps.html#org4d7f824 http://jakob.space/blog/thoughts-on-lisps.html#org4d7f824
- masklinn 6y agoIt's kinda weird that the only mention of Clojure is > Clojure's license makes it a complete non starter for me, sorry. Live free or die. when at first glance fennel looks a lot like clojure e.g. `fn`, square brackets, {} for maps / table literals.
- SahAssar 6y ago> when at first glance fennel looks a lot like clojure e.g. `fn`, square brackets, {} for maps / table literals. Aren't those mostly inherited from lua and present in a lot of different languages invented before and after clojure?
- masklinn 6y agoLua defines functions with the `function` keywords, and as most other C-style languages uses parenthesis to wrap the function parameters, not brackets. It does use `{}` for table literals but requires the `=` and `,` separators, where fennel (and clojure) uses no internal separator at all: a map literal is a pair of braces around a plist (https://www.gnu.org/software/emacs/manual/html_node/elisp/Property-Lists.html#Property-Lists)[0] https://www.gnu.org/software/emacs/manual/html_node/elisp/Pr.... Historically, lisp have used something around "define" to define functions (e.g. define, defun), parenthesis as essentially the only grouping, and would use macros or special-forms rather than complex literals. Clojure is the first lisp I know of (so I may well have missed a predecessor which inspired it) which largely diverged from that. [0] clojure allows commas but ignores them entirely, I don't know whether fennel allows them as well
- lispm 6y agoIf we think Clojure is a 'diverging Lisp', then there are other diverging Lisps with different syntax like MDL, Logo, Dylan, even JavaScript. Some Scheme code uses angular brackets. Historically core Lisp has left other grouping character or syntax to sublanguages or new data types. There are many examples for that. This is usually done via reader macros, which open up the s-expression reader to the programmer. This is a Joshua rule: (defrule grandfather-determiner (:backward) ;; there are 3 ways to find your grandfather IF [or [is-genetic-grandfather-of ?gramps ?kid] [is-grandfather-thru-step-parent ?gramps ?kid] [is-step-grandfather-of ?gramps ?kid]] THEN [is-grandfather-of ?gramps ?kid]) Many internal or external domain specific languages for Lisp use special syntax and defining forms, since their authors either believed that it's easier to use in general or that it was necessary for 'end users' of their systems. Early examples were maths systems like Macsyma, which were programmable, but addressed mathematicians as audience. Logo, which was Lisp for kids. One of the first theorem provers had the first ML as the programming language interface for its users. Historically Lisp 2 was supposed to get rid of simple s-expressions on the surface. There was a different syntax defined for it.
- minxomat 6y agoHere's an example web app hello-world in Fennel, parsing requests and responding with HTML rendered from the S expressions: https://gist.github.com/turbo/4388c9ad19028560053951a25b3b45d1 https://gist.github.com/turbo/4388c9ad19028560053951a25b3b45...
- yawn 6y agoThanks for posting this. I took a look at Fennel a few months ago and although they list 2 web frameworks on the front page, there's little documentation (that may have changed since then) about how to interface with other Lua projects. I kept running into things I couldn't figure out when working with the existing Lua ecosystem and projects.
- erikcw 6y agoI’ve been using it quite successfully in a large OpenResty project. While you’re right that there aren’t any docs on working with any of the 3rd party projects listed in the homepage - I found that it was pretty straight forward to use as a drop in Lua replacement by examining the compiled Lua from the online REPL. I was surprised how clean the Lua output is. There is really no magic here. I believe one of the project goals is to stay as close to Lua semantics as possible. Basically just lisp flavored Lua. In my project I just use the compiled .fnl files as I would any of other .lua file. Is something specific you’re getting stuck with? I’d be happy to try to point you in the right direction. It’s really nice! I encourage you to give it another try.
- fortran77 6y agoThe reason I used Lua was its "accessibility" -- so end users can script -- and not necessarily for the beauty and elegance of the language. It was also very easy to integrate into a C++ project.
- vsurabhi 6y agoThis and a recent feature addition to neovim (passing lua closures to vimscript functions [1]) should make a good substitute for elisp to configure neovim. [1] https://github.com/neovim/neovim/pull/12507 https://github.com/neovim/neovim/pull/12507
- adz5a 6y agoI don't see it mentioned but there is a neovim plugin called conjure [1] that is written in fennel. This is a general purpose REPL client that works for Clojure (I use it daily for Clojure and ClojureScript) but also for fennel itself. So you can have a really nice neovim plugin dev experience using this tool. Conjure works with fennel out of the box, but if you want to go deeper you may be interested in another plugin called aniseed [2] which provides interesting facilities for the fennel language and that is used internally by conjure. Disclaimer: I am not the author of those tools, just a random Clojure dev. [1] https://github.com/Olical/conjure https://github.com/Olical/conjure [2] https://github.com/Olical/aniseed https://github.com/Olical/aniseed
- merricksb 6y agoIf curious, see previous discussion from 2018 https://news.ycombinator.com/item?id=18016168 https://news.ycombinator.com/item?id=18016168
- sillysaurusx 6y agoLumen – Lisp in Lua and JavaScript: https://github.com/sctb/lumen https://github.com/sctb/lumen Scott Bell wrote a lot of that. I was fascinated by the self-hosting technique. The whole repo is so small that you can almost dismiss it as some kind of academic toy, if you don't realize it's a full-featured production-grade lisp. (Not to take anything away from Fennel! The more lisp, the better.)
- tgbugs 6y agoI knew about Fennel, but did not know about Lumen. Thanks for the pointer! edit: Looking at the git history is very educational for how to bootstrap a self hosting system like this. Fascinating.
- pmoriarty 6y agoWould someone be so kind as to compare Lumen to Fennel?
- deleted 6y ago[deleted]
- manexploitsman 6y agoWhy do you need all of those brackets?
- remix2000 6y agoIn the realm of Lua Lisps, there is also Urn: https://urn-lang.com/ https://urn-lang.com/
- galfarragem 6y agoAFAIK, for his author, Fennel is legacy. Nowadays he seems to contribute only to Janet (https://janet-lang.org https://janet-lang.org).
- molloy 6y agoIt's still under very active development by technomancy and others, with a friendly community and lively IRC channel.
- molloy 6y agoA lot of the questions in this thread are answered here: https://fennel-lang.org/rationale https://fennel-lang.org/rationale
- aasasd 6y agoI really wish Lua were popular for small-scale utility scripting instead of Python and JS. Because Lua is way snappier: even with language translation, plenty of Fennel scripts will run under Python's startup time. Likewise, Lua seems like a great fit for small mobile apps and automation (dunno about threading though, but I seem to have read that Lua can do threads with a library). My primary woe with Lua is the absence of ‘null’. You can't preserve structure of deserialized tables if there are nil values in them, so you can't really build API middleware and such, without extra effort for that (so you'd also not be able to use functional libraries like Penlight in your middleware).
- samatman 6y agocould you expand on that a bit? null and nil are effectively synonyms, and I'm having difficulty understanding what about Lua's use of nil has caused problems for you.
- mumblemumble 6y agoLua doesn't distinguish between, "the key is not in the table," and, "there is a value for that key, and the value is nil." Setting the value for the key to nil simply erases it from the table.
- nikki93 6y agoYou can just create a sentinel value and use that. eg. `local mySentinel = {}`. Then insert that value when that's the behavior you want. `nil` on its own rarely makes for a good semantic understanding of what value is actually in the table anyways. Also, in Lua 5.4, the behavior is different -- you need to do `t[key] = undef` (which is the only context you can use `undef` in). And `nil` can actually be a value in a table. Not saying what's better or worse, but that the behavior in 5.4 is different.
- pansa2 6y agoDid `undef` actually make it into 5.4? I thought it was removed during the beta period.
- slumos 6y agoI wrote my simple Hammerspoon config in Fennel and am really happy with it. https://github.com/slumos/dot.hammerspoon https://github.com/slumos/dot.hammerspoon