Mercerenies / gdlisp

Lisp on the Godot platform
GNU General Public License v3.0
141 stars 1 forks source link

symbol-macrolet #22

Closed Mercerenies closed 3 years ago

Mercerenies commented 3 years ago

symbol-macrolet works like macrolet (#19) but operates on symbols in the value namespace, rather than transforming function-like forms as a global macro would.

Mercerenies commented 3 years ago

As we discovered (the hard way) with macrolet, implementing this functionality will require some care, as the IR layer is not currently equipped to keep track of local variables in the value namespace, and it would be responsible for doing so in this case.

Remember that symbol-macrolet is not a simple walk down the tree. Like ordinary macros, symbol macros should only expand when the symbol is used in an expression-like or declaration-like context. Incidentally, unlike normal macros, I don't think symbol macros can ever reasonably be bound in a scope where a symbol could expand in a declaration context, so we may only have to worry about expression context.

Mercerenies commented 3 years ago

As of 7dd8e80, define-symbol-macro is implemented.

This issue is still open, as symbol-macrolet is not implemented yet.

Additionally, symbol macros forbid anything in the function namespace from sharing a name with them. This is arguably acceptable behavior, provided we document it, but I'll open an issue for it nonetheless (#51)

Mercerenies commented 3 years ago

Note that symbol macros cannot be used in declaration context as of now. They can only be used in situations where an expression is expected and they can only produce expression results, so a symbol macro that produces, for instance, a defn form, would be useless. It is probably not too difficult to fix this, but I frankly fail to see the use case.