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

macro capture #37

Closed
Roger-luo opened this issue Feb 6, 2019 · 4 comments
Closed

macro capture #37

Roger-luo opened this issue Feb 6, 2019 · 4 comments

Comments

@Roger-luo
Copy link
Collaborator

To make use of the fast speed of this package, a capture macro like MacroTools would be preferred. And instead of underscore, we could use current match's expr template style.

@thautwarm
Copy link
Owner

like this?

@capture ex begin
    f($x, y) => x  # AST pattern
   $(Expr(:meta, a)) => a # Expr pattern
end

Does it really make sense for we already have the following?

@match ex begin
  :(f($x, y)) => x
   Expr(:meta, a) => a
end

It seems that @capture just simplify AST pattern a little.

@Roger-luo
Copy link
Collaborator Author

Umm, it is just an eye candy of @match in MLStyle, and has similar interface of regex, e.g

@capture <template> <expr>

@capture :(1 + $x + $y) 1 + a + b

this will return a tuple: (:a, :b)

@thautwarm
Copy link
Owner

The problem is $ inside a Quote would be evaluated eagerly if it's not an argument of macrocall, so if you want to use such a @capture macro, you cannot share a common template with multiple callsites.

template = :(1 + $a + $b) # wrong! a, b would inserted here

So you cannt do these:

@capture $template ex1
@capture $template ex2

If we quote an Expr twice :(:($a)), the $ would then be preserved.

@thautwarm
Copy link
Owner

@Roger-luo Would this be sufficient?

https://thautwarm.github.io/MLStyle.jl/latest/tutorials/capture/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants