]> gitweb.factorcode.org Git - factor.git/blobdiff - core/kernel/kernel.factor
kernel: move recusrive-hashcode to math and add test
[factor.git] / core / kernel / kernel.factor
index e102818c4b183fcf605666062d1fd8bc3811e6e9..e5389f401f2117e1cd302362ac99cdea1923d769 100644 (file)
@@ -1,6 +1,5 @@
 ! Copyright (C) 2004, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-IN: math DEFER: <= DEFER: - ! for bootstrap
 USE: slots.private
 USE: kernel.private
 USE: math.private
@@ -236,6 +235,9 @@ DEFER: if
 : 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
 
@@ -277,6 +279,8 @@ UNION: boolean POSTPONE: t POSTPONE: f ;
 
 : most ( x y quot -- z ) 2keep ? ; inline
 
+: negate ( quot -- quot' ) [ not ] compose ; inline
+
 ! Loops
 : loop ( ... pred: ( ... -- ... ? ) -- ... )
     [ call ] keep [ loop ] curry when ; inline recursive
@@ -291,7 +295,7 @@ UNION: boolean POSTPONE: t POSTPONE: f ;
     [ [ 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 ) flushable
@@ -302,9 +306,6 @@ M: f hashcode* 2drop 31337 ; inline
 
 : hashcode ( obj -- code ) 3 swap hashcode* ; inline
 
-: recursive-hashcode ( n obj quot -- code )
-    pick 0 <= [ 3drop 0 ] [ [ 1 - ] 2dip call ] if ; inline
-
 GENERIC: equal? ( obj1 obj2 -- ? )
 
 M: object equal? 2drop f ; inline