View Poll Results: What do you understand by pattern matching?
- Voters
- 2. You may not vote on this poll
-
regular expressions
2 100.00% -
form recognition in computer vision
0 0% -
matching like in functional languages
0 0% -
I had no clou about that before reading this post
0 0%
Multiple Choice Poll.
Results 1 to 1 of 1
- 06-29-2010, 08:16 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 1
- Rep Power
- 0
myPatterns: pattern matching in custom notations for Java & JavaScript
Hi,
I am looking for (feedback from) potential users of an open source
library for Java and JavaScript, called myPatterns, implementing a
new concept: pattern matching in "custom notations".
What are custom notations?
Everyone knows pattern matching of strings using regular expressions.
myPatterns implements a more general notion of pattern matching:
- working not only on strings, but on any program data: numbers,
objects, collections, etc.
- using patterns written either in a pre-defined notation, subsuming
regular expressions and JSON, on in user-defined notations.
When designing a class API, programmers using this library can also
design very easily a custom syntax for matching objects of that class,
i.e. for selecting objects of a certain shape, and decomposing them
into smaller pieces.
For more details, see custom notations
-------------------------------------------------------------------------------
Example
A balance method for red-black trees can be written very concisely
using a custom notation in which a red-rooted tree is written
"(left label right)" and a black-rooted tree is written
"[left label right]":
-------------------------------------------------------------------------------Java Code:static final String pats[] = {"[((%a %x %b) %y %c) %z %d]", "[(%a %x (%b %y %c)) %z %d]", "[%a %x ((%b %y %c) %z %d)]", "[%a %x (%b %y (%c %z %d))]"}; rbTree balance() { Subst s = Matchbox.matchAny(this, pats); if(s != null) return new rbTree(red, new rbTree(black, (rbTree)s.get('a'), (Integer)s.get('x'), (rbTree)s.get('b')), (Integer)s.get('y'), new rbTree(black, (rbTree)s.get('c'), (Integer)s.get('z'), (rbTree)s.get('d'))); return this; }
Similar Threads
-
String matching a pattern
By vividcooper in forum New To JavaReplies: 7Last Post: 01-07-2010, 10:30 PM -
Will someone pliz help me with this code on pattern matching
By nmvictor in forum New To JavaReplies: 1Last Post: 10-27-2009, 07:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks