Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metadata macros #271

Open
jaawerth opened this issue May 10, 2020 · 0 comments
Open

metadata macros #271

jaawerth opened this issue May 10, 2020 · 0 comments
Assignees

Comments

@jaawerth
Copy link
Collaborator

jaawerth commented May 10, 2020

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)
    • 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.

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.

@jaawerth jaawerth added this to the 0.4.0 milestone May 10, 2020
@jaawerth jaawerth self-assigned this May 10, 2020
@technomancy technomancy modified the milestones: 0.4.0, 0.5.0 May 12, 2020
@technomancy technomancy removed this from the 0.4.2 milestone Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants