thautwarm / MLStyle.jl

Julia functional programming infrastructures and metaprogramming facilities
https://thautwarm.github.io/MLStyle.jl/latest/
MIT License
403 stars 38 forks source link

Referential transparency #53

Open cscherrer opened 5 years ago

cscherrer commented 5 years ago

This is not specific to MLStyle, but if you have time I hope you might be able to help. There's a sort of "design pattern" I see you using that I'd like to better understand.

Macros interpret their arguments as expressions, so @foo x will try to do manipulations on the x as a symbol, ignoring any value x is bound to.

For things like match, you somehow pass an expression, and any non-expression gets looked up in the current local context. This seems to me a much better use of macros (or at least better suited to my use case).

I'd love to see a minimal example of this approach. I've looked at the source code for match, but I'm not sure which parts are essential to making things work this way.

thautwarm commented 5 years ago

Hello! My style of ast manipulation comes from such a point of view: macros are just functions, each of which map an AST to another AST.

For things like match, you somehow pass an expression, and any non-expression gets looked up in the current local context. This seems to me a much better use of macros (or at least better suited to my use case).

I think you might be talking about the @format, format, render defined in MLStyle.Render?.It provides a handy way to substitute ASTs in runtime. In Julia, a runtime could be other (itself, as well) modules's parsing time, so you can use return the substituted ASTs from a macro invocation and get them compiled and executable.

thautwarm commented 5 years ago

I'll give you some examples later. These days my schedule just gets burned(I mean quite busy and urgent), and sorry for my late reply.

cscherrer commented 5 years ago

No worries, I know how open source is and just appreciate any help you have time for