Eliminate some more usages of tuck

db4
Slava Pestov 2009-01-25 17:55:27 -06:00
parent 577fde6e91
commit fe7c2fecbe
11 changed files with 35 additions and 33 deletions

View File

@ -1,7 +1,7 @@
! Copyright (C) 2005, 2008 Slava Pestov. ! Copyright (C) 2005, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: io kernel math namespaces math.vectors ui.gadgets USING: io kernel math namespaces math.vectors ui.gadgets
ui.gadgets.packs accessors math.geometry.rect ; ui.gadgets.packs accessors math.geometry.rect combinators ;
IN: ui.gadgets.incremental IN: ui.gadgets.incremental
TUPLE: incremental < pack cursor ; TUPLE: incremental < pack cursor ;
@ -29,7 +29,7 @@ M: incremental pref-dim*
[ cursor>> ] [ orientation>> ] bi v* [ cursor>> ] [ orientation>> ] bi v*
>>loc drop ; >>loc drop ;
: prefer-incremental ( gadget -- ) USE: slots.private : prefer-incremental ( gadget -- )
dup forget-pref-dim dup pref-dim >>dim drop ; dup forget-pref-dim dup pref-dim >>dim drop ;
M: incremental dim-changed drop ; M: incremental dim-changed drop ;
@ -38,17 +38,19 @@ M: incremental dim-changed drop ;
not-in-layout not-in-layout
2dup swap (add-gadget) drop 2dup swap (add-gadget) drop
t in-layout? [ t in-layout? [
over prefer-incremental {
over layout-later [ drop prefer-incremental ]
2dup incremental-loc [ drop layout-later ]
tuck update-cursor [ incremental-loc ]
dup prefer-incremental [ update-cursor ]
parent>> [ invalidate* ] when* [ nip prefer-incremental ]
[ nip parent>> [ invalidate* ] when* ]
} 2cleave
] with-variable ; ] with-variable ;
: clear-incremental ( incremental -- ) : clear-incremental ( incremental -- )
not-in-layout not-in-layout
dup (clear-gadget) [ (clear-gadget) ]
dup forget-pref-dim [ forget-pref-dim ]
{ 0 0 } >>cursor [ { 0 0 } >>cursor parent>> [ relayout ] when* ]
parent>> [ relayout ] when* ; tri ;

View File

@ -10,7 +10,7 @@ IN: ui.gadgets.menus
[ dim>> ] [ pref-dim ] bi* [v-] hand-loc get-global vmin ; [ dim>> ] [ pref-dim ] bi* [v-] hand-loc get-global vmin ;
: show-menu ( owner menu -- ) : show-menu ( owner menu -- )
[ find-world dup ] dip tuck menu-loc show-glass ; [ find-world ] dip 2dup menu-loc show-glass ;
:: <menu-item> ( target hook command -- button ) :: <menu-item> ( target hook command -- button )
command command-name [ command command-name [

View File

@ -124,7 +124,7 @@ M: style-stream write-gadget
stream>> write-gadget ; stream>> write-gadget ;
: print-gadget ( gadget stream -- ) : print-gadget ( gadget stream -- )
tuck write-gadget stream-nl ; [ write-gadget ] [ nip stream-nl ] 2bi ;
: gadget. ( gadget -- ) : gadget. ( gadget -- )
output-stream get print-gadget ; output-stream get print-gadget ;

View File

@ -51,7 +51,7 @@ CONSTANT: table-gap 6
: (compute-column-widths) ( font rows -- total widths ) : (compute-column-widths) ( font rows -- total widths )
[ drop 0 { } ] [ [ drop 0 { } ] [
tuck [ first length 0 <repetition> ] 2dip [ nip first length 0 <repetition> ] 2keep
[ [ text-width ] with map vmax ] with each [ [ text-width ] with map vmax ] with each
[ [ sum ] [ length 1 [-] table-gap * ] bi + ] keep [ [ sum ] [ length 1 [-] table-gap * ] bi + ] keep
] if-empty ; ] if-empty ;
@ -217,7 +217,7 @@ PRIVATE>
if ; if ;
M: table model-changed M: table model-changed
tuck initial-selected-index { [ nip ] [ initial-selected-index ] 2bi {
[ >>selected-index drop ] [ >>selected-index drop ]
[ show-row-summary ] [ show-row-summary ]
[ drop update-selected-value ] [ drop update-selected-value ]

View File

@ -9,9 +9,9 @@ IN: ui.gestures
GENERIC: handle-gesture ( gesture gadget -- ? ) GENERIC: handle-gesture ( gesture gadget -- ? )
M: object handle-gesture M: object handle-gesture
tuck class superclasses [ nip ]
[ "gestures" word-prop ] map [ class superclasses [ "gestures" word-prop ] map assoc-stack ] 2bi
assoc-stack dup [ call f ] [ 2drop t ] if ; dup [ call f ] [ 2drop t ] if ;
: set-gestures ( class hash -- ) "gestures" set-word-prop ; : set-gestures ( class hash -- ) "gestures" set-word-prop ;

View File

@ -145,11 +145,10 @@ TUPLE: gradient < caching-pen colors last-vertices last-colors ;
>float-array ; >float-array ;
M: gradient recompute-pen ( gadget gradient -- ) M: gradient recompute-pen ( gadget gradient -- )
tuck [ nip ] [ [ [ orientation>> ] [ dim>> ] bi ] [ colors>> ] bi* ] 2bi
[ [ orientation>> ] [ dim>> ] bi ] [ colors>> ] bi*
[ gradient-vertices >>last-vertices ] [ gradient-vertices >>last-vertices ]
[ gradient-colors >>last-colors ] bi [ gradient-colors >>last-colors ]
drop ; bi drop ;
: draw-gradient ( colors -- ) : draw-gradient ( colors -- )
GL_COLOR_ARRAY [ GL_COLOR_ARRAY [

View File

@ -58,8 +58,8 @@ M: browser-gadget ungraft*
} 2|| ; } 2|| ;
M: browser-gadget definitions-changed ( assoc browser -- ) M: browser-gadget definitions-changed ( assoc browser -- )
model>> tuck value>> swap showing-definition? model>> [ value>> swap showing-definition? ] keep
[ notify-connections ] [ drop ] if ; '[ _ notify-connections ] when ;
M: browser-gadget focusable-child* search-field>> ; M: browser-gadget focusable-child* search-field>> ;

View File

@ -304,7 +304,7 @@ M: object accept-completion-hook 2drop ;
] recover ; ] recover ;
: handle-interactive ( lines interactor -- quot/f ? ) : handle-interactive ( lines interactor -- quot/f ? )
tuck try-parse { [ nip ] [ try-parse ] 2bi {
{ [ dup quotation? ] [ nip t ] } { [ dup quotation? ] [ nip t ] }
{ [ dup not ] [ drop "\n" swap user-input* drop f f ] } { [ dup not ] [ drop "\n" swap user-input* drop f f ] }
[ handle-parse-error f f ] [ handle-parse-error f f ]

View File

@ -19,8 +19,9 @@ TUPLE: node value children ;
nip , nip ,
] [ ] [
[ [
2dup children>> swap first head-slice % [ children>> swap first head-slice % ]
tuck traverse-step traverse-to-path [ tuck traverse-step traverse-to-path ]
2bi
] make-node ] make-node
] if ] if
] if ; ] if ;
@ -33,8 +34,8 @@ TUPLE: node value children ;
nip , nip ,
] [ ] [
[ [
2dup traverse-step traverse-from-path [ traverse-step traverse-from-path ]
tuck children>> swap first 1+ tail-slice % [ tuck children>> swap first 1+ tail-slice % ] 2bi
] make-node ] make-node
] if ] if
] if ; ] if ;

View File

@ -231,7 +231,7 @@ M: x11-ui-backend set-title ( string world -- )
M: x11-ui-backend set-fullscreen* ( ? world -- ) M: x11-ui-backend set-fullscreen* ( ? world -- )
handle>> window>> "XClientMessageEvent" <c-object> handle>> window>> "XClientMessageEvent" <c-object>
tuck set-XClientMessageEvent-window [ set-XClientMessageEvent-window ] keep
swap _NET_WM_STATE_ADD _NET_WM_STATE_REMOVE ? swap _NET_WM_STATE_ADD _NET_WM_STATE_REMOVE ?
over set-XClientMessageEvent-data0 over set-XClientMessageEvent-data0
ClientMessage over set-XClientMessageEvent-type ClientMessage over set-XClientMessageEvent-type