-
Notifications
You must be signed in to change notification settings - Fork 126
RequireField
This is a design that attempts to solve similar problems as parser macros but with a more limited scope.
While metatables allow you to customize the behavior of tables at
runtime, there is currently no way for such tables to have literal
notation which would allow them to be serialized and round-tripped
back thru the parser. For instance, if you implement a data structure
like a set using a metatable on a regular table, currently
fennel.view
will turn it a regular table.
The metatable in question should emit the table in a notation like this:
(@require:my.lib/set [:a :b :c])
This parses to the following form:
((. (require :my.lib) :set) [:a :b :c])
It causes the module my.lib
to be required. The field set
is then
looked up inside that module, and the table [:a :b :c]
is passed to
it. The intent is that the set
field would take this table and
return a table with the metatable constructed in such a way as to make
it behave like a set.
This is built on a more general-purpose "at-macro" system which we could possibly use for other things in the future, but for now we're more focused on the require-field notation as an application of at-macros to explore their usefulness.