Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: F.lua, a functional Lua extension library (github.com/shakna-israel)
5 points by shakna on Nov 14, 2017 | hide | past | favorite | 1 comment



Obligatory code:

    f = require "f"
    
    local fibonacci = function(n, acc)
      if isnil(acc) then
        acc = 1
      end
      f.elif(x <= 1,
        acc,
        f.recur()(x - 1, x * acc)
    end
The first question I can imagine coming to mind when seeing my work on this project is probably "Why?".

Building a functional library in Lua seems to be something many newcomers attempt [0].

There are a few differences, and they'll probably get spelled out in the README when I become satisfied with the overall coverage of the project.

Firstly: Completeness.

Some libraries give you cons and friends, others give you operators. The feature-list for f.lua is certainly longer than most.

Functions like let and cond simply haven't been in the other libraries I've seen, and tend to be out of scope for them.

Secondly: Lua is incredibly flexible.

It's near-Lisp levels of flexibility, even without going to something like Metalua. Seeing how far I can push it whilst still remaining fairly close to the spirit of Lua is an awesome challenge.

Unfortunately, I'm beginning to hit those barriers. No immutable values unless your assigning to globals, so far as I can tell. [1][2] (Though they might make it into f.let, because of the strange way that function works.) A good prettyprint function actually takes a decent amount of code to implement, especially because of self-referencing, and the ability to override __index.

---

Anyways, I'm happy enough with it, that I thought it was ready for others to play with.

[0] http://lua-users.org/wiki/FunctionalLibrary

[1] http://lua-users.org/wiki/ImmutableObjects

[2] https://github.com/shakna-israel/f.lua/issues/10




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: