You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This has been planned for already, but I wanted to get it into an issue so we didn't forget about it before release, and so we could discuss API options.
In order to abstract away direct usage of the fennel.metadata API, we'll want to add some macros for getting and setting metadata. I actually have a userland implementation of these that could be pretty easily incorporated into fennel, we just need to hammer out the macro API for it.
When metadata is disabled, either a compiler error or expands to nil (could use feedback on which). Ideally used in a with-metadata block as defined below to prevent this.
When metadata is enabled, expands to the code that gets/sets the metadata obect so it can be worked with in runtime.
If the optional key is provided (e.g. :fnl/docstring), instead does gets/sets specific key (could use feedback: could this lead to too many bugs?)
(with-metadata [func-meta func] ...)
Accepts a function and a binding for that function's metadata (like let, but always returns the function, so named with- to disambiguate)
When metadata is enabled, expands to a let block that executes the body and returns the function. When metadata is disabled, the whole expands to the function itself.
(when-metadata ...)
Simply executes the body when metadata is enabled. Other than the lack of a condition, behaves like when. A possible simpler alternative to with-metadata. We could have both, but that might add cognitive debt.
Other than changing up the API signatures to something better suited for built-ins, the only real difference is replacing the hack I used to detect whether metadata is enabled with a way for it to directly query options.useMetadata in the macro env, since a (get-compiler-opts) function would be useful elsewhere.
The text was updated successfully, but these errors were encountered:
This has been planned for already, but I wanted to get it into an issue so we didn't forget about it before release, and so we could discuss API options.
In order to abstract away direct usage of the
fennel.metadata
API, we'll want to add some macros for getting and setting metadata. I actually have a userland implementation of these that could be pretty easily incorporated into fennel, we just need to hammer out the macro API for it.API
I'm thinking something like:
(get-metadata func ?metadata-key)
/(set-metadata func ?metadata-key value)
with-metadata
block as defined below to prevent this.:fnl/docstring
), instead does gets/sets specific key (could use feedback: could this lead to too many bugs?)(with-metadata [func-meta func] ...)
let
, but always returns the function, so namedwith-
to disambiguate)let
block that executes the body and returns the function. When metadata is disabled, the whole expands to the function itself.(when-metadata ...)
when
. A possible simpler alternative towith-metadata
. We could have both, but that might add cognitive debt.Implementation
Implementation-wise, I already have most of what I need in these userland macros in meta-macros.fnl.
Other than changing up the API signatures to something better suited for built-ins, the only real difference is replacing the hack I used to detect whether metadata is enabled with a way for it to directly query
options.useMetadata
in the macro env, since a(get-compiler-opts)
function would be useful elsewhere.The text was updated successfully, but these errors were encountered: