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

def syntax - towards a more advanced macro utility #32

Open
jarcane opened this issue Jun 14, 2015 · 10 comments
Open

def syntax - towards a more advanced macro utility #32

jarcane opened this issue Jun 14, 2015 · 10 comments

Comments

@jarcane
Copy link
Owner

jarcane commented Jun 14, 2015

At the moment, Heresy defines only the simple def macro form, which is little more than a rename of Racket's define-syntax-rule. Tho has meant that a lot of macro work on new features has necessitated fallbacks to Racket.

I'm currently brainstorming an idea for another feature that will require a little more flexibility, and I would like to do it in as close to pure Heresy as I can.

I'm suggesting def syntax as a candidate name for importing define-syntax at least.

@jarcane
Copy link
Owner Author

jarcane commented Jun 15, 2015

I'm thinking def syntax will essentially just be a resugaring of define-syntax + syntax-rules, possibly with an optional clause for defining syntax literals. Perhaps it could expand with syntax-parameter definitions as well, to prevent export issues, much as we already do with the Racket-written ones.

@jarcane
Copy link
Owner Author

jarcane commented Jun 15, 2015

I think literal keyword reservation could possibly be handled with a seperate macro, def literal, that would just expand to the syntax-parameter form, with an optional (or even mandatory) custom error message.

@AlexKnauth
Copy link
Contributor

What about something that's similar to this:
https://github.com/jarcane/heresy/blob/master/lib/infix-math.rkt#L17
https://github.com/jarcane/heresy/blob/master/lib/infix-math.rkt#L24
Like this:

(def syntax-parser macro-name
  kw-option ...
  [pat
   body ...]
  ...)

With maybe an extra #:define-literals option that expands to def literal with an error message about the macro-name?

And also, by the way, is there a reason why you would want literals to be syntax parameters? Why not just normal macros that raise error messages (by default)?

@jarcane
Copy link
Owner Author

jarcane commented Jun 15, 2015

The reason we have the literals defined as syntax-parameters everywhere at the moment is that you need to be able to export them as part of the module, or else any form that uses them will fail syntax checking. That's why base.rkt is full of (define-syntax-parameter ...) for every last in, with, etc. If there's some other way to do it I dunno, that's what was suggested to me, and what I've stuck to.

So the question is whether we want to magic that behind the scenes, or force them to be similarly declared separately like they are in Racket.

@jarcane jarcane closed this as completed Jun 15, 2015
@AlexKnauth
Copy link
Contributor

Those could be regular macros instead of syntax parameters, and they would export as part of the module, and forms can use them. They don't have to be syntax-parameters, they could just use regular define-syntax instead.

@jarcane
Copy link
Owner Author

jarcane commented Jun 15, 2015

Cool. I guess only the ones actually redefined inside macros (like the carry/cry etc.) actually need to be parameters then?

@jarcane jarcane reopened this Jun 15, 2015
@AlexKnauth
Copy link
Contributor

Yes

@jarcane
Copy link
Owner Author

jarcane commented Jun 16, 2015

Huh. Well, something to look at refactoring then, perhaps.

@jarcane
Copy link
Owner Author

jarcane commented Nov 30, 2015

4125eca implements def macroset as a shortcut for define-syntax + syntax-rules. I've left out the ability to define new literal keywords, I think for now it's just safer that way.

In a future overhaul I may even ditch them altogether anyhow.

@jarcane
Copy link
Owner Author

jarcane commented Apr 27, 2017

It's undocumented yet, but def macroset now allows defining local literals. It was necessary for maybe-do and the new monadic do>.

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