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

Reader macros aren't #1230

Closed
Kodiologist opened this issue Feb 23, 2017 · 4 comments
Closed

Reader macros aren't #1230

Kodiologist opened this issue Feb 23, 2017 · 4 comments

Comments

@Kodiologist
Copy link
Member

For a long time, Hy has had a feature we call "reader macros", but they're not actually reader macros, just regular macros with an unusual syntax for calling them. A reader macro is a macro that is called at read-time, and hence can change how raw characters of the source are parsed. It's provided with raw text as arguments. An ordinary macro, on the other hand, is called after the text has already been parsed into s-expressions. It's provided with s-expressions as arguments.

Real reader macros would be nice to have, but they would be hard to implement (see #722, which is over 3 years old and probably won't get closed soon). In the meantime, I think we're long overdue for not misleading users about our so-called reader macros. I see two options:

  • Remove the feature entirely, so we can use some of the same syntax for real reader macros once we have them, and so-called reader macros won't suddenly be reinterpreted as real reader macros after one upgrades Hy.
  • Call them something else, like "sharp macros", since they're called with a character after a sharp sign (#). defreader would then be defsharp or something.
@gilch
Copy link
Member

gilch commented Feb 23, 2017

Something like Clojure's tagged literals #1046 might be easier to implement. Those aren't true reader macros in the Common Lisp sense either. But Hy is more like Clojure than Common Lisp.

@Kodiologist
Copy link
Member Author

Definitely, I think tags of that sort wouldn't be hard, since the macro gets run at the same time as ordinary macros.

@gilch
Copy link
Member

gilch commented Feb 23, 2017

See also #1042. I don't know that Perl-style heredocs would work well in a Lisp, but maybe something like Lua's long brackets could work. If we had the better string syntax, then we could apply a tag to invoke an arbitrary reader/interpreter/compiler on a string containing any language we like. I think this would get us most of the power of reader macros, but perhaps there's more I haven't thought of.

@Kodiologist
Copy link
Member Author

Kodiologist commented Apr 15, 2017

I think I'm going to make a PR to just rename them to "sharp macros" (and make the documentation less misleading). The extension to symbols longer than 1 character can be done later if desired.

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

3 participants