-
Notifications
You must be signed in to change notification settings - Fork 10
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
Provide a macro that works like .
but expands macros in its arguments first
#43
Comments
Generally, Hy macros are expanded outside-in, not inside-out. This allows a macro to do whatever it likes with symbols, whether they happen to be macro names in the surrounding scope or not. Thus you can still do things like define a macro named |
Ah, I see. Even so, I wonder if it would be useful then to either have a standard library version of Sure I can define a |
My intuition is that it would be very difficult to make this work correctly in nontrivial cases.
I wouldn't recommend trying to implement your own macro system, but instead having
expands to
then Hy can expand a macro (or call a function) named
Perhaps you'd like |
Thanks for the suggestion. Is there a way in Hy to access all defined macros in the current scope as a set? My current approach allowing first-order expansions in
but it would be nice if I could also make a version where
What's the reasoning here? I think this kind of thing is a pretty typical idiom in Common Lisp, at least. It would basically be extending this snippet so that DSLs can each have their own |
No, macro introspection in its full generality is not implemented.
Because it's a lot more work than just using the existing macro system. |
Right...
So this is just the thread first macro after all, and for example we could have
but this requires defining all the inner macros in terms of the
Is this as in not implemented yet, or is it against the language design philosophy? |
Right, probably better to define
As in "it would be nice to have, but nobody's working on it at the moment or has plans to work on it". |
Anyway, let's narrow this issue to a single feature request so we can decide what to do with it. You've brought up a few things. What would you like to request? Is it what you said in the first post, for |
Yeah, either that or have an alternate version of |
I think the second is more likely to happen, and Hyrule's the place for that, so I'll move this issue over. |
.
but expands macros in its arguments first
Here's my partial proposed implementation, which makes use of the existing
Not sure if what I'm calling The problem is, this implementation doesn't support macro expansions that start with an a symbol, which is allowable in
but couldn't figure out how to make Maybe there's another way to distinguish between when the macro expansion starts with a symbol because |
Oh wait I'm silly. I thought it was some spooky Python error but there's just an extra |
I'm currently using Hy with CadQuery, which is a Python library for parametric CAD that basically implements a DSL via chained method calls. An example from their Quickstart docs:
Currently, it seems like the hy "." special form overrides all cons forms inside of it to represent method calls, but in cases like this I think it would be really helpful to support macro expansion inside of the "." form. For example, I wrote the macro
hoping that
(on faces ">Z")
would expand to(faces ">Z") (workplace)
inside of a dot form (i.e.(. cq ...
), but instead Hy assumes that "on" is the name of a method.I'm sure there are other Python libraries implemented as chained method call DSLs, where allowing macros inside the dot form would be helpful. Namespace conflicts between macros and chained methods could be addressed by making explicitly quoted cons forms only refer to method calls.
Is there already a way in Hy to achieve what I'm trying to do, or are there any other issues with this proposal?
The text was updated successfully, but these errors were encountered: