Jonathan Eunice  committed 6e926e1

tweaked docs

  • Participants
  • Parent commits c99aad3

Comments (0)

Files changed (4)

     if name in Re(r'\b(s\w*)\b', Re.I):
         print 'Good name, {}'.format(Re._[1])
-Note that this enables a form of *en passant* assignment
+Note that this enables a form of (or alternative to) *en passant* assignment
 that shortens regular expression conditionals by at least one line
-compared to the standard ``re`` module.
+compared to the standard ``re`` module. A spiffed-up version of the
+``re.MatchObject`` is available at ``Re._``. This object can be
+indexed to get regexp match groups. For named groups (e.g. ``(?P<firstname>\w+)``),
+the matched value can be retrieved by attribute: ``Re._.firstname``. All of the
+other ``re.MatchObject`` methods and properties can also be accessed this way,
+such as ``Re._.start(1)`` and ``Re._.span(1)``.
 For simple matching, the ``Glob`` class (which plays by the rules
 of Unix glob expressions) may be simpler:

File intensional/

     Some set operations like union can be performed without requiring returning
     a different subclass of IntensionalSet. Provides more opporunity also for
     in-place mutations.
     def __init__(self, include, exclude=[]):
         self.include = boxed(include)

File more docs.txt

-  * A nicer way to use regular expressions
-  * A ``switch`` statement (actually, function) for Python
-Instead of::
-    import re
-    match =, some_string)
-    if match:
-        print
-You can do an *en passant* test::
-    from intensional import Re
-    if some_string in Re(pattern):
-        print _[1]
-There are two things to note here: First,
-this turns the sense of the matching around, asking "is a given string *in*
-the set of items this pattern describes?" The ``Re`` pattern is an intensionally
-defined set (namely "all strings matching the pattern"). This order often makes
-excellent sense whey you have a clear intent for the test. For example, "is the
-given string within the set of *all legitimate commands*?"
-Second, the ``in`` test had the side effect of setting the underscore
-name ``_`` to the result. Python doesn't support *en passant* assignment, so
-you can't both test and collect results in the same motion, even though that's
-sometimes exactly appropriate. ``Re`` use introspection to get around this
-difficulty and provide neat results.
-If you prefer the more traditional ``re`` calls, you can still use them with the
-convenient *en passant* style.::
-    if Re(pattern).search(some_string):
-        print _[1]
-``Re`` works even better with named pattern components, such as::
-    person = 'John Smith 48'
-    if person in Re(r'(?P<name>[\w\s]*)\s+(?P<age>\d+)'):
-        print, "is", _.age, "years old"
-    else:
-        print "don't understand '{}'".format(person)
-It's possible also to loop over the results, as in::
-    for found in Re(r'(pattern\w*)').findall('pattern is as pattern does'):
-        print found
-``Re`` objects are `memoized <>`_ for efficiency, so they
-are only compiled once, regardless of how many times they're mentioned in the program.
-It's entirely possible to implement an intensional set like idea with
-other Python mechanisms, such as ``lambda`` expressions, test functions,
-and list comprehensions. Many (most?) Python programs already *de facto*
-use this implicit intensional set approach. Making intensional sets
-explicit, however, has the benefit of making what's being done more
-clear. It provides a mechanism for cleaning up several sort of ucky
-parts of Python:
- *  Messy, guts-exposed regular expression tests
- *  Overly verbose lambda expressions
- *  Long, non-DRY ``if``/``elif``/``else`` constructions (with ``switch``)
- *  A mess of mechanisms for collection filtering
-    version=verno("0.150"),
+    version=verno("0.151"),
     author='Jonathan Eunice',
     description='Intensional sets in Python',