! Copyright (C) 2004, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel.private slots.private math.private ;
+USE: slots.private
+USE: kernel.private
+USE: math.private
IN: kernel
BUILTIN: callstack ;
: 4keep ( ..a w x y z quot: ( ..a w x y z -- ..b ) -- ..b w x y z )
[ 4dup ] dip 4dip ; inline
-: keepd ( ..a x y quot: ( ..a x y -- ..b x ) -- ..b x )
+: keepd ( ..a x y quot: ( ..a x y -- ..b ) -- ..b x )
2keep drop ; inline
-: keepdd ( ..a x y z quot: ( ..a x y z -- ..b x ) -- ..b x )
+: keepdd ( ..a x y z quot: ( ..a x y z -- ..b ) -- ..b x )
3keep 2drop ; inline
-: 2keepd ( ..a x y z quot: ( ..a x y z -- ..b x y ) -- ..b x y )
+: 2keepd ( ..a x y z quot: ( ..a x y z -- ..b ) -- ..b x y )
3keep drop ; inline
! Cleavers
: 2with ( param1 param2 obj quot -- obj curried )
with with ; inline
+: withd ( param obj quot -- obj curried )
+ swapd [ -rotd call ] 2curry ; inline
+
: prepose ( quot1 quot2 -- composed )
swap compose ; inline
: most ( x y quot -- z ) 2keep ? ; inline
+: negate ( quot -- quot' ) [ not ] compose ; inline
+
! Loops
: loop ( ... pred: ( ... -- ... ? ) -- ... )
[ call ] keep [ loop ] curry when ; inline recursive
: while ( ..a pred: ( ..a -- ..b ? ) body: ( ..b -- ..a ) -- ..b )
swap do compose [ loop ] curry when ; inline
+: while* ( ..a pred: ( ..a -- ..b ? ) body: ( ..b ? -- ..a ) -- ..b )
+ [ [ dup ] compose ] dip while drop ; inline
+
: until ( ..a pred: ( ..a -- ..b ? ) body: ( ..b -- ..a ) -- ..b )
- [ [ not ] compose ] dip while ; inline
+ [ negate ] dip while ; inline
! Object protocol
-GENERIC: hashcode* ( depth obj -- code )
+GENERIC: hashcode* ( depth obj -- code ) flushable
M: object hashcode* 2drop 0 ; inline
: hashcode ( obj -- code ) 3 swap hashcode* ; inline
+GENERIC: equal? ( obj1 obj2 -- ? )
+
+M: object equal? 2drop f ; inline
+
+TUPLE: identity-tuple ;
+
+M: identity-tuple equal? 2drop f ; inline
+
: identity-hashcode ( obj -- code )
dup tag 0 eq? [
dup tag 1 eq? [ drop 0 ] [
] if
] unless ; inline
-GENERIC: equal? ( obj1 obj2 -- ? )
-
-M: object equal? 2drop f ; inline
-
-TUPLE: identity-tuple ;
-
-M: identity-tuple equal? 2drop f ; inline
-
M: identity-tuple hashcode* nip identity-hashcode ; inline
: = ( obj1 obj2 -- ? )