Suggestion for a Python Extension

Felix Thibault felixt at dicksonstreet.com
Sat Mar 25 14:49:53 EST 2000


Hi Luis-
   I have been working on a pattern matcher lately too, and
__cmp__ and __rcmp__ have come in really handy:

class Any:
    def __cmp__(self, other):
        return 0
    def __rcmp__(self, other):
        return 0

>>> any = Any()
>>> range(3) == [any, any, any]
1
>>> 

(cmp(x,y) -> -1, 0, 1 for x < y, x == y, x > y)

But I haven't gotten much more than that worked out-

Felix

At 02:55 3/23/00 GMT, Luis Cortes wrote:
<Eudora stipped out the newlines, I tried to put them back>
>  Hello,
>In Prolog you might have something like this:
>     fact( 1, 3 ). 
>     fact( 2, 3 ). 
>     fact( 3, 4 ).
>you can query the relation with a simple statement like so: 
>     ?fact( _X, 3 )
>which returns:
>    fact( 1, 3 ). 
>    fact( 2, 3 ).
>For example: fact = [ (1,3), (2,3), (3,4)] 
>ans = fact( SomeAnonymousVariable, 3 ) 
>so that ans has:
> ans = [ (1,3), (2,3) ] 
>
>I have create a couple of classes in Python
>to allow me to simulate what I want, but it
>would be nice if it where built-in instead,
>using my classes the last example would be: 
>
>fact = plist( [ (1,3), (2,3), (3,4)] ) 
>
>ans = fact.query( Anonymous(), 3 ) 
>
>so that ans has: 
>
>ans = [ (1,3), (2,3) ] 
>
>other examples might be: 
>
>ans = fact.query( 1, 3 ) 
>
>so that ans has: 
>
>ans = [ (1,3) ] 
>
>OR: 
>
>ans = fact.query( 1, Anonymous() ) 
>
>so that ans has: 
>
>ans = [ (1,3), (2,3) ] 
>
>OR 
>
>ans = fact.query( Anonymous(), Anonymous() ) 
>
>so that ans has: 
>
>ans = [ (1,3), (2,3), (3,4) ] 
>  
>  
>
>What do you'all think? 
>  
>
>best regards, 
>Luis. 
>  
>
>P.S.  Please also reply to sender with your comments, suggests, and
corrections. # -------------------------------------------------------
>
<snip rest>





More information about the Python-list mailing list