 : <spider-result> ( url depth -- spider-result )
     spider-result new
         swap >>depth
-        swap >>url ;
+        swap >>url ; inline
 
 <PRIVATE
 
 : apply-filters ( links spider -- links' )
-    filters>> [ '[ [ _ 1&& ] filter ] call( seq -- seq' ) ] when* ;
+    filters>> [
+        '[ [ _ 1&& ] filter ] call( seq -- seq' )
+    ] when* ;
 
 : push-links ( links level unique-deque -- )
     '[ _ _ push-url ] each ;


: spider-sleep ( spider -- ) sleep>> [ sleep ] when* ;

: queue-initial-links ( spider -- )
    [
        [ currently-spidering>> ] [ initial-links>> ] bi normalize-hrefs 0
    ] keep add-todo ;

: spider-page? ( spider -- ? )
    {

    [ base>> host>> ] [ links>> members ] bi*
    [ host>> = ] with partition ;

:: add-spidered ( spider spider-result -- )
    spider [ 1 + ] change-count drop

    spider-result dup url>>
    spider spidered>> set-at

    spider spider-result filter-base-links :> ( matching nonmatching )
    spider-result depth>> 1 + :> depth

    nonmatching depth spider add-nonmatching

    matching spider apply-filters depth spider add-todo ;

: normalize-hrefs ( base links -- links' )
    [ derive-url ] with map ;
