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:
result = cq.Workplane("XY").box(height, width, thickness)\
.faces(">Z").workplane().hole(diameter)\
.faces(">Z").workplane() \
.rect(height - padding,width - padding,forConstruction=True)\
.vertices()\
.cboreHole(2.4, 4.4, 2.1)
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
(defmacro on [&rest place]
`((~@place) (workplane)))
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?
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?