: canonicalize-specializer-1 ( specializer -- specializer' )
[
[ class? ] filter
- [ length <reversed> [ 1+ neg ] map ] keep zip
+ [ length <reversed> [ 1 + neg ] map ] keep zip
[ length args [ max ] change ] keep
]
[
{ 0 [ [ dup ] ] }
{ 1 [ [ over ] ] }
{ 2 [ [ pick ] ] }
- [ 1- picker [ dip swap ] curry ]
+ [ 1 - picker [ dip swap ] curry ]
} case ;
: (multi-predicate) ( class picker -- quot )
USING: multi-methods tools.test math sequences namespaces system
kernel strings definitions prettyprint debugger arrays
hashtables continuations classes assocs accessors see ;
+RENAME: GENERIC: multi-methods => multi-methods:GENERIC:
-GENERIC: first-test ( -- )
+multi-methods:GENERIC: first-test ( -- )
[ t ] [ \ first-test generic? ] unit-test
SINGLETON: scissors INSTANCE: scissors thing
SINGLETON: rock INSTANCE: rock thing
-GENERIC: beats? ( obj1 obj2 -- ? )
+multi-methods:GENERIC: beats? ( obj1 obj2 -- ? )
-METHOD: beats? { paper scissors } t ;
-METHOD: beats? { scissors rock } t ;
-METHOD: beats? { rock paper } t ;
-METHOD: beats? { thing thing } f ;
+METHOD: beats? { paper scissors } 2drop t ;
+METHOD: beats? { scissors rock } 2drop t ;
+METHOD: beats? { rock paper } 2drop t ;
+METHOD: beats? { thing thing } 2drop f ;
-: play ( obj1 obj2 -- ? ) beats? 2nip ;
+: play ( obj1 obj2 -- ? ) beats? ;
[ { } 3 play ] must-fail
[ t ] [ error get no-method? ] unit-test
SYMBOL: some-var
-GENERIC: hook-test ( -- obj )
+multi-methods:GENERIC: hook-test ( obj -- obj )
METHOD: hook-test { array { some-var array } } reverse ;
METHOD: hook-test { { some-var array } } class ;
TUPLE: busted-2 ; INSTANCE: busted-2 busted
TUPLE: busted-3 ;
-GENERIC: busted-sort ( obj1 obj2 -- obj1 obj2 )
+multi-methods:GENERIC: busted-sort ( obj1 obj2 -- obj1 obj2 )
METHOD: busted-sort { busted-1 busted-2 } ;
METHOD: busted-sort { busted-2 busted-3 } ;