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

example api for matching expression sequences #1

Closed
kovasb opened this issue Jan 7, 2013 · 3 comments
Closed

example api for matching expression sequences #1

kovasb opened this issue Jan 7, 2013 · 3 comments

Comments

@kovasb
Copy link

kovasb commented Jan 7, 2013

You might already be aware of this, but there is a pretty good example of a solution to this, at

http://reference.wolfram.com/mathematica/guide/Patterns.html

(this is within the context of a broader expression pattern matching language that can deal with trees, but also deals with various form of the sequence case)

@jclaggett
Copy link
Owner

Fascinating!

I was not aware of this at all. Thank you for pointing it out.
On Jan 6, 2013 9:28 PM, "kovasb" notifications@github.com wrote:

You might already be aware of this, but there is a pretty good example of
a solution to this, at

http://reference.wolfram.com/mathematica/guide/Patterns.html

(this is within the context of a broader expression pattern matching
language that can deal with trees, but also deals with various form of the
sequence case)


Reply to this email directly or view it on GitHubhttps://github.com//issues/1.

@jclaggett
Copy link
Owner

I've just pushed an updated API that you might be interested in.

@kovasb
Copy link
Author

kovasb commented Jan 23, 2013

The idea of making the patterns into functions is interesting.

If it was me, I'd prefer to separate what is being matched from the repetition specification. http://reference.wolfram.com/mathematica/ref/Repeated.html handles this very well.

You can still have syntactic sugar to express common cases, but still have it boil down to a consistent representation.

I think its possible to simply what you have by leveraging clojure's built in datatypes.

I'm also a fan of using #{} to represent orderless sets. Maybe its possible to do away with the distinction between c and s entirely. Though you'd have to distinguish between matching a literal set versus a set of alternatives. (The literal case is less common, so wrapping it as (literal #{}) within the sequence pattern would do the trick nicely)

From my own experience, verbose symbolic names for the pattern components are much easier to remember and read than regex terse descriptions. Working with http://reference.wolfram.com/mathematica/tutorial/WorkingWithStringPatterns.html#316252289

which is an extension of the general pattern matching to the string case, was way more fun than regex because it was just a lot more evident what was going on.

One big reason regex is so terse is that it is embedded in the string itself, but in this situation you are liberated from that.

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