Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install peak-rules

How to install PEAK-Rules

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install peak-rules
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.5a1.dev-r2707
0.5a1.dev-r2713Never BuiltWhy not?
0.5a1.dev-r2707 Available View build log
0.5a1.dev-r2700 Available View build log
0.5a1.dev-r2686 Available View build log
0.5a1.dev-r2683 Available View build log
Windows (64-bit)
0.5a1.dev-r2707
0.5a1.dev-r2713Never BuiltWhy not?
0.5a1.dev-r2707 Available View build log
0.5a1.dev-r2700 Available View build log
0.5a1.dev-r2686 Available View build log
0.5a1.dev-r2683 Available View build log
Mac OS X (10.5+)
0.5a1.dev-r2707
0.5a1.dev-r2713Never BuiltWhy not?
0.5a1.dev-r2707 Available View build log
0.5a1.dev-r2700 Available View build log
0.5a1.dev-r2686 Available View build log
0.5a1.dev-r2683 Available View build log
Linux (32-bit)
0.5a1.dev-r2707
0.5a1.dev-r2713Never BuiltWhy not?
0.5a1.dev-r2707 Available View build log
0.5a1.dev-r2700 Available View build log
0.5a1.dev-r2686 Available View build log
0.5a1.dev-r2683 Available View build log
Linux (64-bit)
0.5a1.dev-r2713 Available View build log
0.5a1.dev-r2707 Available View build log
0.5a1.dev-r2700 Available View build log
0.5a1.dev-r2686 Available View build log
0.5a1.dev-r2683 Available View build log
 
License
ZPL 2.1
Imports
Lastest release
version 0.5a1.dev-r2713 on Jan 9th, 2014

PEAK-Rules is a highly-extensible framework for creating and using generic functions, from the very simple to the very complex. Out of the box, it supports multiple-dispatch on positional arguments using tuples of types, full predicate dispatch using strings containing Python expressions, and CLOS-like method combining. (But the framework allows you to mix and match dispatch engines and custom method combinations, if you need or want to.)

Basic usage:

>>> from peak.rules import abstract, when, around, before, after
>>> @abstract()
... def pprint(ob):
...     """A pretty-printing generic function"""
>>> @when(pprint, (list,))
... def pprint_list(ob):
...     print "pretty-printing a list"
>>> @when(pprint, "isinstance(ob,list) and len(ob)>50")
... def pprint_long_list(ob):
...     print "pretty-printing a long list"
>>> pprint([1,2,3])
pretty-printing a list
>>> pprint([42]*1000)
pretty-printing a long list
>>> pprint(42)
Traceback (most recent call last):
...
NoApplicableMethods: ...

PEAK-Rules works with Python 2.3 and up -- just omit the @ signs if your code needs to run under 2.3. Also, note that with PEAK-Rules, any function can be generic: you don't have to predeclare a function as generic. (The abstract decorator is used to declare a function with no default method; i.e., one that will raise NoApplicableMethods instead of executing a default implementation, if no rules match the arguments it's invoked with.)

PEAK-Rules is still under development; it lacks much in the way of error checking, so if you mess up your rules, it may not be obvious where or how you did. User documentation is also lacking, although there are extensive doctests describing and testing most of its internals, including:

(Please note that these documents are still in a state of flux and some may still be incomplete or disorganized, prior to the first official release.)

Source distribution snapshots are generated daily, but you can also update directly from the development version in SVN.

Subscribe to package updates

Last updated Jan 9th, 2014

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.