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

Pattern matching for expressions #2

Open
albop opened this issue Mar 22, 2016 · 1 comment
Open

Pattern matching for expressions #2

albop opened this issue Mar 22, 2016 · 1 comment

Comments

@albop
Copy link
Member

albop commented Mar 22, 2016

For the preliminary implementation, a pattern is an expression, with some wildcards.
Wildcards are valid identifiers starting by one underscore.

For instance, _a + _b*_a is supposed to match p + b*p but not p + b*c.

We can use that to define the elements of syntax that we want, for instance to define _x[_inds](_t) as the generic form of a timed and index variable (like v_{i,t+1})

There is a crude python implementation in https://github.com/EconForge/dolang/blob/master/dolang/pattern.py.

Some questions:

  • are there available libraries which do it efficiently ?
  • we probably want to "type" the wildcard so that, in the above example, _t could stand for a signed integer and _inds would be expected to be a list of indices
  • would we be better of by defining the expression parser ourselve instead of operating on the syntax tree ?
@sglyon
Copy link
Member

sglyon commented Mar 22, 2016

Cool idea. I like it.

On the Julia side we have the @match macro in MacroTools.jl

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