     length 1 - 0 number-from-to nip ;
 
 MACRO: unsafe-amb ( seq -- quot )
-    dup length 1 =
-    [ first 1quotation ]
-    [ [ first ] [ rest ] bi
-      '[ _ [ drop _ unsafe-amb ] checkpoint ] ] if ;
+    dup length 1 = [
+        first 1quotation
+    ] [
+        unclip swap '[ _ [ drop _ unsafe-amb ] checkpoint ]
+    ] if ;
 
 PRIVATE> 
 

! Copyright (C) 2008 William Schlieper
! See http://factorcode.org/license.txt for BSD license.

USING: kernel continuations combinators sequences quotations arrays namespaces
       fry summary assocs math math.order macros ;

IN: backtrack


M: amb-failure summary drop "Backtracking failure" ;

: fail ( -- )
    failure get [ continue ] [ amb-failure ] if* ;

: require ( ? -- )
    [ fail ] unless ;

MACRO: checkpoint ( quot -- quot' )
    '[
        failure get _ '[
            '[ failure set _ continue ] callcc0
            _ failure set @
        ] callcc0
    ] ;

: number-from ( from -- from+n )
    [ 1 + number-from ] checkpoint ;
