bakpakin / Fennel

Lua Lisp Language
https://fennel-lang.org
MIT License
2.42k stars 124 forks source link

Add option for additional Lua keywords #476

Closed dokutan closed 5 months ago

dokutan commented 5 months ago

This PR adds the --keyword option to improve support for Lua forks which have additional keywords, as suggested in #459.

This option only affects the generated code, i.e. fennel generates correct code if this option is used. Therefore this option will not allow Fennel to run on a Lua fork, if any added reserved names are used by Fennel itself (for example the Pluto keyword new is used by Fennel). However it should be possible to compile Fennel with this option to prevent this issue.

I have tested this with Ravi and Pluto:

If this functionality gets added, it leads to a few questions that i can not answer:

technomancy commented 5 months ago

Thanks for submitting this! I think it's a good idea.

However, in order to be consistent with other compiler options, it should be controlled by the options table rather than modifying the list of keywords in utils.fnl. For instance, it should be possible to run the compiler from the API to target Pluto, and then run another compilation that does not target Pluto afterwards; this is not possible with the current implementation above, but would be possible if lua-keywords were part of the options table accepted by fennel.compile and other functions.

Also if you could add a mention of this in api.md and man/man1/fennel.1 that would be super! Putting a page on the wiki would be good too, but let's focus on the compiler change first.

Should this option be added to the bootstrap compiler?

Without that, it would make it so fennel.lua itself couldn't be loaded into Ravi/Pluto, right? If so, then yeah, it's probably worth adding to the bootstrap compiler. Doesn't need to happen in this PR.

Should Fennel detect these forks [...]?

Maybe we can add this in the future once we get feedback from users of this feature in practice. I'd rather keep it focused for now.

Thanks again.

dokutan commented 5 months ago

However, in order to be consistent with other compiler options, it should be controlled by the options table rather than modifying the list of keywords in utils.fnl.

I have opened #477 which implements the same functionality using the options table and documented the changes in api.md and man/man1/fennel.1.

Without that, it would make it so fennel.lua itself couldn't be loaded into Ravi/Pluto, right?

Ravi works without this by chance, because no added keywords are used in the fennel codebase, however for Pluto this would be necessary.