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

How to assign part of a matched pattern to a variable? #62

Open
Qiyamah opened this issue May 13, 2018 · 1 comment
Open

How to assign part of a matched pattern to a variable? #62

Qiyamah opened this issue May 13, 2018 · 1 comment

Comments

@Qiyamah
Copy link

Qiyamah commented May 13, 2018

Hi,
Here is an example, but it would be nice to have a syntax to (ex = :{P,pattern}) to have the matched part of the expression.

@metafunction collectwheres(member1 where *{params1}) begin
  	member2, params2 = collectwheres(member1)
  	(member2, (params1..., params2...))
end
@metafunction collectwheres(other) begin
  	(other,())
end
@metafunction parse_fn(function(*{args},) where w; *{stmts} end) begin
end

for me to use collectwheres method, i need to assign the matched part of the expression by "function(*{args},) where w;" pattern. So is there a way to assign the matched part to a variable so that i can pass it to collectwheres?

Thanks

@fcard
Copy link
Owner

fcard commented May 15, 2018

I think I understand, but unfortunately julia's syntax rules makes implementing the new syntax difficult. If they were more permissive, we could just do this:

@metafunction parse_fn(function expr; *{stms} end) begin
  fn, wheres = collectwheres(expr)
  #...
end

We can do this somewhat clumsily with :R.

@metafunction parse_fn(:R{:function, expr, begin *{stms} end}) begin
  fn, wheres = collectwheres(expr)
  #...
end

"Named matches" seem worth implementing anyway, even if it's not useful for this particular case.

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