Fennel icon indicating copy to clipboard operation
Fennel copied to clipboard

Luau syntax support

Open shaunsingh opened this issue 10 months ago • 4 comments

Hi, I was interested in transpiling fennel to luau: https://luau-lang.org, which has a few notable extensions to lua/luajit, mainly type annotations. Fennel already compiles fine down to standard 5.1 syntax, but would a PR adding support for type annotation syntax be accepted? Of course I'd be happy to discuss the syntax and implementation beforehand.

I understand bending or implementing syntax to support forks (e.g. pluto) isn't recommended, but luau is gaining popularity quite heavily in the scripting space (most notably roblox) and so it should be taken under further consideration

shaunsingh avatar Oct 01 '23 11:10 shaunsingh

Yeah, as you mention this is similar to the situation with #459 as it's about a Lua fork.

At this time I don't think it's a good idea to include support for specialized fork syntax in Fennel itself; there are at least four different forks that all offer their own take on type hints. Since this is fairly unexplored territory, any such development would necessitate a quicker release cycle than Fennel's, as well as the flexibility to make backwards-incompatible changes, making mainline inclusion detrimental.

It should be possible to extend the plugin interface to still allow this to be implemented outside the compiler. I expect that the current state of the plugin system is not extensive enough to support this, but I am certainly open to proposals to extend it in order to enable what you're asking for.

technomancy avatar Oct 01 '23 17:10 technomancy

I wonder if the lua special could be used to just splice in some arbitrary code at an arbitrary place. E.g.:

(fn inc (lua ": number") [x (lua ": number")]
  (+ x 1))

It is ugly, but can be made less ugly with a simple macro:

(macro fn+ [name hint args ...] 
  ;; `args` need handling in a similar way
  `(fn ,name (lua ,(.. ": " hint)) ,args ,...))

(fn+ inc :number [x :number]
  (+ x 1))

andreyorst avatar Oct 01 '23 18:10 andreyorst

I like the idea of @andreyorst, in combination with a library for a luau specific macros.

For example I have been working on a library to add dynamic type checking to Fennel itself, but if adding arbitrary code to the output from a macro becomes possible, i would consider adding type annotations to the output as well.

dokutan avatar Oct 01 '23 18:10 dokutan

Not wanting to add support for a fork is fair enough, the macro approach is just as clean. Will certainly look into it. Thanks!

shaunsingh avatar Oct 01 '23 20:10 shaunsingh