 : dlist-any? ( ... dlist quot: ( ... value -- ... ? ) -- ... ? )
     dlist-find nip ; inline
 
-M: dlist deque-member? ( value dlist -- ? )
+M: dlist deque-member?
     [ = ] with dlist-any? ;
 
-M: dlist delete-node ( dlist-node dlist -- )
+M: dlist delete-node
     [
         {
             { [ 2dup front>> eq? ] [ nip pop-front* ] }

<PRIVATE

: (push-before-node) ( obj dlist-node -- new-dlist-node )
    [ [ prev>> ] keep <dlist-node> ] keep {
        [ prev>> [ next<< ] [ drop ] if* ]
        [ prev<< ]
        [ drop ]
    } 2cleave ; inline

: push-before-node ( obj dlist-node dlist -- new-dlist-node )
    2dup front>> eq? [

    [ set-prev-when ]
    [ swap set-next-when ] 2bi ; inline

M: dlist push-front*
    [
        f swap <dlist-node> dup dup set-next-prev
    ] change-front set-back-to-front ;

: push-node-front ( dlist-node dlist -- )
    dupd [ >>next ] change-front
    [ set-next-prev ] [ set-back-to-front ] bi* ;

: push-node-back ( dlist-node dlist -- )
    dupd [ >>prev ] change-back
    [ set-prev-next ] [ set-front-to-back ] bi* ;

M: dlist push-back*
    [
        [ f <dlist-node> dup dup ]
        [ set-next-when ] bi
    ] change-back set-front-to-back ;

M: dlist peek-front*
    front>> [ obj>> t ] [ f f ] if* ;

M: dlist peek-back*
    back>> [ obj>> t ] [ f f ] if* ;

M: dlist pop-front*
    [
        [ empty-deque ] unless*
        next>>
        f over set-prev-when
    ] change-front normalize-back ;

M: dlist pop-back*
    [
        [ empty-deque ] unless*
        prev>>
        f over set-next-when
    ] change-back normalize-front ;

: dlist-find ( ... dlist quot: ( ... value -- ... ? ) -- ... obj/f ? )
    '[ obj>> @ ] dlist-find-node [ obj>> t ] [ f f ] if* ; inline
