]> gitweb.factorcode.org Git - factor.git/commitdiff
Reimplement leach so that stack is clean when executing the quotation
authorSamuel Tardieu <sam@rfc1149.net>
Fri, 21 Dec 2007 04:42:25 +0000 (05:42 +0100)
committerSamuel Tardieu <sam@rfc1149.net>
Fri, 21 Dec 2007 12:33:56 +0000 (13:33 +0100)
The previous implementation let garbage on the stack (such as the lazy list
cdr) before executing the quotation. This prevents easy implementation of
reduce-like words using leach.

extra/lazy-lists/lazy-lists.factor

index 2e3dc9154a25ab03fc1158adda9b0f38336fd1a4..c6294087045f64cc3ad9f748118fea88518ca00f 100644 (file)
@@ -100,11 +100,7 @@ M: lazy-cons list? ( object -- bool )
     dup car swap cdr ;
 
 : leach ( list quot -- )
-  swap dup nil? [
-    2drop
-  ] [
-    uncons swap pick call swap leach
-  ] if ;
+  swap dup nil? [ 2drop ] [ uncons swapd over 2slip leach ] if ; inline
 
 TUPLE: memoized-cons original car cdr nil? ;