]> gitweb.factorcode.org Git - factor.git/commitdiff
nip most uses of tuck from extra
authorJoe Groff <arcata@gmail.com>
Fri, 6 Nov 2009 04:22:21 +0000 (22:22 -0600)
committerJoe Groff <arcata@gmail.com>
Fri, 6 Nov 2009 04:22:21 +0000 (22:22 -0600)
38 files changed:
extra/benchmark/knucleotide/knucleotide.factor
extra/curses/curses.factor
extra/decimals/decimals.factor
extra/ecdsa/ecdsa.factor
extra/io/serial/windows/windows.factor
extra/jamshred/gl/gl.factor
extra/jamshred/oint/oint.factor
extra/jamshred/player/player.factor
extra/jamshred/tunnel/tunnel.factor
extra/joystick-demo/joystick-demo.factor
extra/key-handlers/key-handlers.factor
extra/koszul/koszul.factor
extra/math/affine-transforms/affine-transforms.factor
extra/math/binpack/binpack.factor
extra/math/finance/finance.factor
extra/math/quadratic/quadratic.factor
extra/models/combinators/combinators.factor
extra/mongodb/msg/msg.factor
extra/mongodb/tuple/state/state.factor
extra/parser-combinators/parser-combinators.factor
extra/project-euler/002/002.factor
extra/project-euler/100/100.factor
extra/project-euler/117/117.factor
extra/project-euler/ave-time/ave-time.factor
extra/quadtrees/quadtrees.factor
extra/random/blum-blum-shub/blum-blum-shub-tests.factor
extra/rot13/rot13.factor
extra/sequences/abbrev/abbrev.factor
extra/sequences/modified/modified.factor
extra/space-invaders/space-invaders.factor
extra/spider/spider.factor
extra/tetris/piece/piece.factor
extra/trees/avl/avl.factor
extra/trees/splay/splay.factor
extra/trees/trees.factor
extra/ui/gadgets/lists/lists.factor
extra/units/units-tests.factor
extra/usa-cities/usa-cities.factor

index fb4f17cca5c768615975aa03451108ebf4bea86a..a28a676b904b72957dae0aed314e03c24d747317 100644 (file)
@@ -1,4 +1,4 @@
-USING: kernel io io.files splitting strings io.encodings.ascii
+USING: kernel locals io io.files splitting strings io.encodings.ascii
        hashtables sequences assocs math namespaces prettyprint
        math.parser combinators arrays sorting unicode.case ;
 
@@ -21,10 +21,7 @@ IN: benchmark.knucleotide
     CHAR: \n swap remove >upper ;
 
 : tally ( x exemplar -- b )
-    clone tuck
-    [
-      [ [ 1 + ] [ 1 ] if* ] change-at
-    ] curry each ;
+    clone [ [ inc-at ] curry each ] keep ;
 
 : small-groups ( x n -- b )
     swap
@@ -42,10 +39,10 @@ IN: benchmark.knucleotide
     ] each
     drop ;
 
-: handle-n ( inputs x -- )
-    tuck length
-    small-groups H{ } tally
-    at [ 0 ] unless*
+:: handle-n ( inputs x -- )
+    inputs x length small-groups :> groups
+    groups H{ } tally :> b
+    x b at [ 0 ] unless*
     number>string 8 CHAR: \s pad-tail write ;
 
 : process-input ( input -- )
index 4d6c77fd23c03388961911fd8ed27ecd5c0af8d0..23adf31700097386e3791260da53ad2092df328c 100644 (file)
@@ -123,8 +123,10 @@ PRIVATE>
 : curses-writef ( window string -- )
     [ window-ptr dup ] dip (curses-wprint) (curses-window-refresh) ;
 
-: (curses-read) ( window-ptr n encoding -- string )
-    [ [ <byte-array> tuck ] keep wgetnstr curses-error ] dip alien>string ;
+:: (curses-read) ( window-ptr n encoding -- string )
+    n <byte-array> :> buf
+    window-ptr buf n wgetnstr curses-error
+    buf encoding alien>string ;
 
 : curses-read ( window n -- string )
     utf8 [ window-ptr ] 2dip (curses-read) ;
index cc12b4fed1822ec35349bd18b52de74a9c554d35..d5c62fee5e3d0d4fa4f87ff2f78b2aa18a1d11af 100644 (file)
@@ -37,7 +37,7 @@ SYNTAX: D: parse-decimal suffix! ;
     ] 2bi ;
 
 : scale-decimals ( D1 D2 -- D1' D2' )
-    scale-mantissas tuck [ <decimal> ] 2dip <decimal> ;
+    scale-mantissas [ <decimal> ] curry bi@ ;
 
 ERROR: decimal-types-expected d1 d2 ;
 
index c4d889991edf25be4e0b5184ee42dd9f9412a4d0..8e285a0904a35625acb1a1e31237aaae582895a3 100644 (file)
@@ -50,7 +50,7 @@ PRIVATE>
 
 : get-private-key ( -- bin/f )
     ec-key-handle EC_KEY_get0_private_key
-    dup [ dup BN_num_bits bits>bytes <byte-array> tuck BN_bn2bin drop ] when ;
+    dup [ dup BN_num_bits bits>bytes <byte-array> [ BN_bn2bin drop ] keep ] when ;
 
 :: get-public-key ( -- bin/f )
     ec-key-handle :> KEY
index 551fd16b33e27ea0c5952d5d9c623580fc623fa0..645e4939de0d3416425507932c9ce00da3837dde 100755 (executable)
@@ -11,8 +11,7 @@ IN: io.serial.windows
 
 : get-comm-state ( duplex -- dcb )
     in>> handle>>
-    DCB <struct> tuck
-    GetCommState win32-error=0/f ;
+    DCB <struct> [ GetCommState win32-error=0/f ] keep ;
 
 : set-comm-state ( duplex dcb -- )
     [ in>> handle>> ] dip
index 60e9e39d9f5abf8d3611841355eedb5e683b3a24..48bf2b693a8c463c74cdc247e5689dc2488fd1b6 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors alien.c-types jamshred.game jamshred.oint
 jamshred.player jamshred.tunnel kernel math math.constants
 math.functions math.vectors opengl opengl.gl opengl.glu
-opengl.demo-support sequences specialized-arrays ;
+opengl.demo-support sequences specialized-arrays locals ;
 FROM: alien.c-types => float ;
 SPECIALIZED-ARRAY: float
 IN: jamshred.gl
@@ -50,8 +50,9 @@ CONSTANT: wall-drawing-offset 0.15
     over color>> gl-color segment-vertex-and-normal
     gl-normal gl-vertex ;
 
-: draw-vertex-pair ( theta next-segment segment -- )
-    rot tuck draw-segment-vertex draw-segment-vertex ;
+:: draw-vertex-pair ( theta next-segment segment -- )
+    segment theta draw-segment-vertex
+    next-segment theta draw-segment-vertex ;
 
 : draw-segment ( next-segment segment -- )
     GL_QUAD_STRIP [
index ae72bd847cadfe687b14df90116817641ba89321..b1644ef443a5f308963e79c2510070935350d2c2 100644 (file)
@@ -53,13 +53,13 @@ C: <oint> oint
 
 : scalar-projection ( v1 v2 -- n )
     #! the scalar projection of v1 onto v2
-    tuck v. swap norm / ;
+    [ v. ] [ norm ] bi / ;
 
 : proj-perp ( u v -- w )
     dupd proj v- ;
 
 : perpendicular-distance ( oint oint -- distance )
-    tuck distance-vector swap 2dup left>> scalar-projection abs
+    [ distance-vector ] keep 2dup left>> scalar-projection abs
     -rot up>> scalar-projection abs + ;
 
 :: reflect ( v n -- v' )
index baeacd750bccbd38014b11c26a82ecb171eed501..ecce29180c2bd6611ea218452e250d1d14dac8da 100644 (file)
@@ -31,8 +31,9 @@ CONSTANT: max-speed 30.0
     forward-pivot ;
 
 : to-tunnel-start ( player -- )
-    [ tunnel>> first dup location>> ]
-    [ tuck (>>location) (>>nearest-segment) ] bi ;
+    dup tunnel>> first
+    [ >>nearest-segment ]
+    [ location>> >>location ] bi drop ;
 
 : play-in-tunnel ( player segments -- )
     >>tunnel to-tunnel-start ;
index e7285dcbbc56eef78ea9c8d5cfd2ef64d9084b0f..7f8646b778d9e8ec4dc8f4e610f0c4ac4ff42a52 100644 (file)
@@ -63,9 +63,10 @@ CONSTANT: default-segment-radius 1
     #! valid values
     [ '[ _ clamp-length ] bi@ ] keep <slice> ;
 
-: nearer-segment ( segment segment oint -- segment )
-    #! return whichever of the two segments is nearer to the oint
-    [ 2dup ] dip tuck distance [ distance ] dip < -rot ? ;
+:: nearer-segment ( seg-a seg-b oint -- segment )
+    seg-a oint distance
+    seg-b oint distance <
+    seg-a seg-b ? ;
 
 : (find-nearest-segment) ( nearest next oint -- nearest ? )
     #! find the nearest of 'next' and 'nearest' to 'oint', and return
index 90e28594e7c0d4deeb3465e262a765392487f871..6ea1dc5633b18bbba53ee3a68186434d824db77b 100755 (executable)
@@ -50,10 +50,10 @@ CONSTANT: pov-polygons
     [ [ 0.0 ] unless* ] tri@
     [ (xy>loc) ] dip (z>loc) ;
 
-: move-axis ( gadget x y z -- )
-    (xyz>loc) rot tuck
-    [ indicator>>   (>>loc) ]
-    [ z-indicator>> (>>loc) ] 2bi* ;
+:: move-axis ( gadget x y z -- )
+    x y z (xyz>loc) :> ( xy z )
+    xy gadget   indicator>> (>>loc)
+    z  gadget z-indicator>> (>>loc) ;
 
 : move-pov ( gadget pov -- )
     swap pov>> [ interior>> -rot = COLOR: gray COLOR: white ? >>color drop ]
@@ -82,10 +82,10 @@ TUPLE: joystick-demo-gadget < pack axis raxis controller buttons alarm ;
     [ >>controller ] [ product-string <label> add-gadget ] bi ;
 
 : add-axis-gadget ( gadget shelf -- gadget shelf )
-    <axis-gadget> tuck [ >>axis ] [ add-gadget-with-border ] 2bi* ;
+    <axis-gadget> [ >>axis ] [ add-gadget-with-border ] bi-curry bi* ;
 
 : add-raxis-gadget ( gadget shelf -- gadget shelf )
-    <axis-gadget> tuck [ >>raxis ] [ add-gadget-with-border ] 2bi* ;
+    <axis-gadget> [ >>raxis ] [ add-gadget-with-border ] bi-curry bi* ;
 
 :: (add-button-gadgets) ( gadget shelf -- )
     gadget controller>> read-controller buttons>> length [
index b5171bece01aac07060274a3e334365050b852d7..fafd68ca68db138d274012732a812e1a9e247ffa 100644 (file)
@@ -7,4 +7,4 @@ TUPLE: key-handler < border handlers ;
 : <keys> ( gadget -- key-handler ) key-handler new-border { 0 0 } >>size ;
 
 M: key-handler handle-gesture
-    tuck handlers>> at [ call( gadget -- ) f ] [ drop t ] if* ;
\ No newline at end of file
+    [ handlers>> at ] keep swap [ call( gadget -- ) f ] [ drop t ] if* ;
index 3e3d67195e2f5857616c0e7513439f68368fd3a8..f5b30f49da7a61dfa2659cec521e483d30195ed8 100755 (executable)
@@ -229,14 +229,12 @@ DEFER: (d)
 : laplacian-betti ( basis1 basis2 basis3 -- n )
     laplacian-matrix null/rank drop ;
 
-: laplacian-kernel ( basis1 basis2 basis3 -- basis )
-    [ tuck ] dip
-    laplacian-matrix dup empty-matrix? [
-        2drop f
-    ] [
-        nullspace [
-            [ [ wedge (alt+) ] 2each ] with-terms
-        ] with map
+:: laplacian-kernel ( basis1 basis2 basis3 -- basis )
+    basis1 basis2 basis3 laplacian-matrix :> lap
+    lap empty-matrix? [ f ] [
+        lap nullspace [| x |
+            basis2 x [ [ wedge (alt+) ] 2each ] with-terms
+        ] map
     ] if ;
 
 : graded-triple ( seq n -- triple )
index 7d63bbfac8cacf88074a6f0e57fa268ccf4cb536..e8315cdf202062cfb8ef72929fc1c00c4f31bde9 100644 (file)
@@ -41,7 +41,7 @@ CONSTANT: identity-transform T{ affine-transform f { 1.0 0.0 } { 0.0 1.0 } { 0.0
     [ [ y>> second     ] [ x>> second neg ] bi 2array ]
     [ [ y>> first  neg ] [ x>> first      ] bi 2array ]
     [ |a| ] tri
-    tuck [ v/n ] 2bi@ ;
+    [ v/n ] curry bi@ ;
 
 : inverse-axes ( a -- a^-1 )
     (inverted-axes) { 0.0 0.0 } <affine-transform> ;
index 4bd1bc1b81fcc3c0022386327db20f3ead24dee7..5f1ec0c0177306b061f49ced552474fb0961fd6d 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: sequences kernel arrays vectors accessors assocs sorting math math.functions ;
+USING: sequences kernel arrays vectors accessors assocs shuffle sorting locals math math.functions ;
 
 IN: math.binpack 
 
@@ -9,10 +9,12 @@ IN: math.binpack
     [ [ values sum ] map ] keep
     zip sort-keys values first push ;
 
-: binpack ( assoc n -- bins )
-    [ sort-values <reversed> dup length ] dip
-    tuck / ceiling <array> [ <vector> ] map
-    tuck [ (binpack) ] curry each ;
+:: binpack ( assoc n -- bins )
+    assoc sort-values <reversed> :> values
+    values length :> #values
+    n #values n / ceiling <array> [ <vector> ] map :> bins
+    values [ bins (binpack) ] each
+    bins ;
 
 : binpack* ( items n -- bins )
     [ dup zip ] dip binpack [ keys ] map ;
index 5954b08c9b3649331aafe2c0d666dc73c6defd7b..f1c608bad912017f37f4afce36f527952f61544c 100644 (file)
@@ -7,7 +7,7 @@ IN: math.finance
 <PRIVATE
 
 : weighted ( x y a -- z )
-    tuck [ * ] [ 1 - neg * ] 2bi* + ;
+    [ * ] [ 1 - neg * ] bi-curry bi* + ;
 
 : a ( n -- a )
     1 + 2 swap / ;
index e4642a863b4e4d4e6606b674ecd467b2d7201518..892b846e9ee331bbee49fd4ebf0fb0053b0ab622 100644 (file)
@@ -3,9 +3,9 @@
 USING: kernel locals math math.functions ;
 IN: math.quadratic
 
-: monic ( c b a -- c' b' ) tuck [ / ] 2bi@ ;
+: monic ( c b a -- c' b' ) [ / ] curry bi@ ;
 
-: discriminant ( c b -- b d ) tuck sq 4 / swap - sqrt ;
+: discriminant ( c b -- b d ) [ nip ] [ sq 4 / swap - sqrt ] 2bi ;
 
 : critical ( b d -- -b/2 d ) [ -2 / ] dip ;
 
index c7b864d4042d59dfa93b7873f6a9c3d456593c77..489691061893ed7ecca523348a5e37ac41320021 100644 (file)
@@ -1,5 +1,5 @@
 USING: accessors arrays kernel models models.product monads
-sequences sequences.extras ;
+sequences sequences.extras shuffle ;
 FROM: syntax => >> ;
 IN: models.combinators
 
@@ -102,4 +102,4 @@ M: (when-model) (model-changed) [ quot>> ] 2keep
 : with-self ( quot: ( model -- model ) -- model ) [ f <basic> dup ] dip call swap [ add-dependency ] keep ; inline
 
 USE: models.combinators.templates
-<< { "$>" "<$" "fmap" } [ fmaps ] each >>
\ No newline at end of file
+<< { "$>" "<$" "fmap" } [ fmaps ] each >>
index dd8bae84386952acef313ca87245204e3bb105c0..c48634679507caa304149e9a35507b0905b70b21 100644 (file)
@@ -94,7 +94,7 @@ M: sequence <mdb-insert-msg> ( collection sequence -- mdb-insert-msg )
 M: assoc <mdb-insert-msg> ( collection assoc -- mdb-insert-msg )
     [ mdb-insert-msg new ] 2dip
     [ >>collection ] dip
-    V{ } clone tuck push
+    [ V{ } clone ] dip suffix!
     >>objects OP_Insert >>opcode ;
 
 
index ec1b8865ab2c8be470f95872f5ae885cb34f3445..bbae2b039959c09487b95ee29de0026b7ec3b1d6 100644 (file)
@@ -10,7 +10,7 @@ CONSTANT: MDB_TUPLE_INFO       "_mfd_t_info"
 PRIVATE>
 
 : <tuple-info> ( tuple -- tuple-info )
-    class V{ } clone tuck  
+    class [ V{ } clone ] dip over
     [ [ name>> ] dip push ]
     [ [ vocabulary>> ] dip push ] 2bi ; inline
 
index 7a73561e56fbbdfaf2c1f436ef95ce570d0c2110..c2e3e347275f80252ed74ea8702156e5d917d778 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2004 Chris Double.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: lists lists.lazy promises kernel sequences strings math
-arrays splitting quotations combinators namespaces
+arrays splitting quotations combinators namespaces locals
 unicode.case unicode.categories sequences.deep accessors ;
 IN: parser-combinators
 
@@ -58,9 +58,11 @@ C: <token-parser> token-parser
 
 : case-insensitive-token ( string -- parser ) t <token-parser> ;
 
-M: token-parser parse ( input parser -- list )
-    [ string>> ] [ ignore-case?>> ] bi
-    [ tuck ] dip ?string-head
+M:: token-parser parse ( input parser -- list )
+    parser string>> :> str
+    parser ignore-case?>> :> case?
+
+    str input str case? ?string-head
     [ <parse-results> ] [ 2drop nil ] if ;
 
 : 1token ( n -- parser ) 1string token ;
@@ -319,7 +321,7 @@ LAZY: <(+)> ( parser -- parser )
     <& &> ;
 
 : nonempty-list-of ( items separator -- parser )
-    [ over &> <*> <&:> ] keep <?> tuck pack ;
+    [ over &> <*> <&:> ] keep <?> [ nip ] 2keep pack ;
 
 : list-of ( items separator -- parser )
     #! Given a parser for the separator and for the
index 9995e434e7cec04337409aa2c633f36f757e71b3..63d6eac8b438bf59879faacbc440492f8e61183c 100644 (file)
@@ -31,7 +31,7 @@ PRIVATE>
     V{ 0 } clone 1 rot (fib-upto) ;
 
 : euler002 ( -- answer )
-    4000000 fib-upto [ even? ] filter sum ;
+    4,000,000 fib-upto [ even? ] filter sum ;
 
 ! [ euler002 ] 100 ave-time
 ! 0 ms ave run time - 0.22 SD (100 trials)
@@ -41,11 +41,11 @@ PRIVATE>
 ! -------------------
 
 : fib-upto* ( n -- seq )
-    0 1 [ pick over >= ] [ tuck + dup ] produce [ 3drop ] dip
+    0 1 [ pick over >= ] [ [ nip ] 2keep + dup ] produce [ 3drop ] dip
     but-last-slice { 0 1 } prepend ;
 
 : euler002a ( -- answer )
-    4000000 fib-upto* [ even? ] filter sum ;
+    4,000,000 fib-upto* [ even? ] filter sum ;
 
 ! [ euler002a ] 100 ave-time
 ! 0 ms ave run time - 0.2 SD (100 trials)
@@ -54,7 +54,7 @@ PRIVATE>
 <PRIVATE
 
 : next-fibs ( x y -- y x+y )
-    tuck + ;
+    [ nip ] [ + ] 2bi ;
 
 : ?retotal ( total fib- fib+ -- retotal fib- fib+ )
     dup even? [ [ nip + ] 2keep ] when ;
index 72584d833ec842bc4eca1d5e7ea344ba224e2981..55a108aa68f29b8521d8b9120b9939b58e7ad727 100644 (file)
@@ -5,19 +5,18 @@ IN: project-euler.100
 
 ! http://projecteuler.net/index.php?section=problems&id=100
 
-! DESCRIPTION
-! -----------
+! DESCRIPTION ! -----------
 
 ! If a box contains twenty-one coloured discs, composed of fifteen blue discs
-! and six red discs, and two discs were taken at random, it can be seen that
-! the probability of taking two blue discs, P(BB) = (15/21)*(14/20) = 1/2.
+!  and six red discs, and two discs were taken at random, it can be seen that
+!  the probability of taking two blue discs, P(BB) = (15/21)*(14/20) = 1/2.
 
 ! The next such arrangement, for which there is exactly 50% chance of taking
-! two blue discs at random, is a box containing eighty-five blue discs and
-! thirty-five red discs.
+!  two blue discs at random, is a box containing eighty-five blue discs and
+!  thirty-five red discs.
 
 ! By finding the first arrangement to contain over 10^12 = 1,000,000,000,000
-! discs in total, determine the number of blue discs that the box would contain.
+!  discs in total, determine the number of blue discs that the box would contain.
 
 
 ! SOLUTION
@@ -26,7 +25,7 @@ IN: project-euler.100
 : euler100 ( -- answer )
     1 1
     [ dup dup 1 - * 2 * 10 24 ^ <= ]
-    [ tuck 6 * swap - 2 - ] while nip ;
+    [ [ 6 * swap - 2 - ] keep swap ] while nip ;
 
 ! TODO: solution needs generalization
 
index 0d4ec782269f4b1d4777da7e7dd8045c06ccc1ff..60daa7224e8634827c6df8ffa983656a2a60b7bb 100644 (file)
@@ -31,7 +31,7 @@ IN: project-euler.117
     [ 4 short tail* sum ] keep push ;
 
 : (euler117) ( n -- m )
-    V{ 1 } clone tuck [ next ] curry times last ;
+    [ V{ 1 } clone ] dip over [ next ] curry times last ;
 
 PRIVATE>
 
index dc521d4d70f0bd2520877b2f3c684439ace125f0..cc326c1afe9bd40c14e5c4e914d07cdd81116e0a 100644 (file)
@@ -11,8 +11,8 @@ IN: project-euler.ave-time
     [
         [ datastack ]
         [
-            '[ _ gc benchmark 1000 / , ] tuck
-            '[ _ _ with-datastack drop ]
+            '[ _ gc benchmark 1000 / , ]
+            [ '[ _ _ with-datastack drop ] ] keep swap
         ]
         [ 1 - ] tri* swap times call
     ] { } make ; inline
index 6fe361b556c565ae6a39052a925fde8243909f57..7c2bdd0d28007546253a9b696c72f5651ae1da9e 100644 (file)
@@ -1,5 +1,5 @@
 ! (c) 2009 Joe Groff, see BSD license
-USING: assocs kernel math.rectangles combinators accessors
+USING: assocs kernel math.rectangles combinators accessors locals
 math.vectors vectors sequences math combinators.short-circuit arrays fry ;
 IN: quadtrees
 
@@ -89,8 +89,9 @@ DEFER: in-rect*
 : insert ( value point tree -- )
     dup leaf?>> [ leaf-insert ] [ node-insert ] if ;
 
-: leaf-at-point ( point leaf -- value/f ? )
-    tuck point>> = [ value>> t ] [ drop f f ] if ;
+:: leaf-at-point ( point leaf -- value/f ? )
+    point leaf point>> =
+    [ leaf value>> t ] [ f f ] if ;
 
 : node-at-point ( point node -- value/f ? )
     descend at-point ;
@@ -103,15 +104,15 @@ DEFER: in-rect*
 : node-in-rect* ( values rect node -- values )
     [ (node-in-rect*) ] with each-quadrant ;
 
-: leaf-in-rect* ( values rect leaf -- values ) 
-    tuck { [ nip point>> ] [ point>> swap contains-point? ] } 2&&
-    [ value>> over push ] [ drop ] if ;
+:: leaf-in-rect* ( values rect leaf -- values ) 
+    { [ leaf point>> ] [ leaf point>> rect contains-point? ] } 0&&
+    [ values leaf value>> suffix! ] [ values ] if ;
 
 : in-rect* ( values rect tree -- values )
     dup leaf?>> [ leaf-in-rect* ] [ node-in-rect* ] if ;
 
-: leaf-erase ( point leaf -- )
-    tuck point>> = [ f >>point f >>value ] when drop ;
+:: leaf-erase ( point leaf -- )
+    point leaf point>> = [ leaf f >>point f >>value drop ] when ;
 
 : node-erase ( point node -- )
     descend erase ;
index 4b0dee642e7e9d7c4314c3a5a6b0da460a41af0b..0a397ddc6ddec7e18350400f5fcbc55bb35da97e 100644 (file)
@@ -22,7 +22,7 @@ IN: blum-blum-shub.tests
 
 [ 3716213681 ]
 [
-    100 T{ blum-blum-shub f 200352954495 846054538649 } clone tuck [
+    T{ blum-blum-shub f 200352954495 846054538649 } clone 100 over [
         random-32* drop
     ] curry times
     random-32*
index 6663381522aeb2fbcde56cd4f2b526184c1cd0f7..c8f08bcf30a1cfbcba5804c21a1f2895ac640e24 100644 (file)
@@ -3,7 +3,7 @@
 USING: kernel math sequences strings io combinators ascii ;
 IN: rot13
 
-: rotate ( ch base -- ch ) tuck - 13 + 26 mod + ;
+: rotate ( ch base -- ch ) [ - 13 + 26 mod ] [ + ] bi ;
 
 : rot-letter ( ch -- ch )
     {
index 6770a48a3a835c98e98157a306f1f4d89ec9d995..2dc22477838594feadc25add3c85cfe4ad39741a 100644 (file)
@@ -12,7 +12,7 @@ IN: sequences.abbrev
     [ prefixes ] keep 1array '[ _ ] H{ } map>assoc ;
 
 : assoc-merge ( assoc1 assoc2 -- assoc3 )
-    tuck '[ over _ at dup [ append ] [ drop ] if ] assoc-map assoc-union ;
+    [ '[ over _ at dup [ append ] [ drop ] if ] assoc-map ] keep swap assoc-union ;
 
 PRIVATE>
 
index d552f2dc77a9ede9af6930d911df60a5a9146eb4..3fb87feaf8da17a5663009c9634232fe43ce8eb1 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Alex Chapman
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays kernel math math.order
+USING: accessors arrays kernel locals math math.order
 sequences sequences.private shuffle ;
 IN: sequences.modified
 
@@ -32,9 +32,9 @@ C: <scaled> scaled
 M: scaled modified-nth ( n seq -- elt )
     [ seq>> nth ] [ c>> * ] bi ;
 
-M: scaled modified-set-nth ( elt n seq -- elt )
+M:: scaled modified-set-nth ( elt n seq -- elt )
     ! don't set c to 0!
-    tuck [ c>> / ] 2dip seq>> set-nth ;
+    elt seq c>> / n seq seq>> set-nth ;
 
 TUPLE: offset < 1modified n ;
 C: <offset> offset
@@ -45,8 +45,8 @@ C: <offset> offset
 M: offset modified-nth ( n seq -- elt )
     [ seq>> nth ] [ n>> + ] bi ;
 
-M: offset modified-set-nth ( elt n seq -- )
-    tuck [ n>> - ] 2dip seq>> set-nth ;
+M:: offset modified-set-nth ( elt n seq -- )
+    elt seq n>> - n seq seq>> set-nth ;
 
 TUPLE: summed < modified seqs ;
 C: <summed> summed
index db6ed7ed04492ab23e35ec6711605d1e7d34b499..3d0369128740fb471c3a19a5dcdfaafcc6171c84 100755 (executable)
@@ -14,7 +14,9 @@ USING:
     io.files
     io.pathnames
     kernel 
+    locals
     math
+    math.order
     openal
     opengl.gl
     sequences
@@ -41,9 +43,7 @@ CONSTANT: game-height 256
   first2 game-width 3 * * swap 3 * + ;
 
 :: set-bitmap-pixel ( bitmap point color -- )
-    color point bitmap
-
-    point color :> index
+    point bitmap-index :> index
     color first  index     bitmap set-nth
     color second index 1 + bitmap set-nth
     color third  index 2 + bitmap set-nth ;
@@ -140,8 +140,8 @@ M: space-invaders read-port ( port cpu -- byte )
   #! Setting this value affects the value read from port 3
   (>>port2o) ;
 
-: bit-newly-set? ( old-value new-value bit -- bool )
-  tuck bit? [ bit? not ] dip and ;
+:: bit-newly-set? ( old-value new-value bit -- bool )
+  new-value bit bit? [ old-value bit bit? not ] dip and ;
 
 : port3-newly-set? ( new-value cpu bit -- bool )
   [ port3o>> swap ] dip bit-newly-set? ;
@@ -320,17 +320,13 @@ CONSTANT: red   { 255 0 0 }
   #! point is a {x y}. color is a {r g b}.
   set-bitmap-pixel ;
 
-: within ( n a b -- bool )
-  #! n >= a and n <= b
-  rot tuck swap <= [ swap >= ] dip and ;
-
 : get-point-color ( point -- color )
   #! Return the color to use for the given x/y position.
   first2
   {
-    { [ dup 184 238 within pick 0 223 within and ] [ 2drop green ] }
-    { [ dup 240 247 within pick 16 133 within and ] [ 2drop green ] }
-    { [ dup 247 215 - 247 184 - within pick 0 223 within and ] [ 2drop red ] }
+    { [ dup 184 238 between? pick 0 223 between? and ] [ 2drop green ] }
+    { [ dup 240 247 between? pick 16 133 between? and ] [ 2drop green ] }
+    { [ dup 247 215 - 247 184 - between? pick 0 223 between? and ] [ 2drop red ] }
     [ 2drop white ]
   } cond ;
 
index 4ce998294b283c26b12adb972281c5b379231346..c8ea4734d28a79294a182ecd33c04d9bcc57f2e7 100644 (file)
@@ -57,7 +57,7 @@ fetched-in parsed-html links processed-in fetched-at ;
     [ filter-base-links ] 2keep
     depth>> 1 + swap
     [ add-nonmatching ]
-    [ tuck [ apply-filters ] 2dip add-todo ] 2bi ;
+    [ dup '[ _ apply-filters ] curry 2dip add-todo ] 2bi ;
 
 : normalize-hrefs ( base links -- links' )
     [ derive-url ] with map ;
index 2ebbfc07d68480b1a1e95cc3cf1e4474fdd3a097..0a24b2033c30163ef122242d49d044c10edd4f83 100644 (file)
@@ -37,7 +37,7 @@ TUPLE: piece
 
 : modulo ( n m -- n )
   #! -2 7 mod => -2, -2 7 modulo =>  5
-  tuck mod over + swap mod ;
+  [ mod ] [ + ] [ mod ] tri ;
 
 : (rotate-piece) ( rotation inc n-states -- rotation' )
     [ + ] dip modulo ;
index 04c7022077c0c4bb0914c5ded36c66e595b7e935..4903307af1698a5a9bf3f6cdf28b7713c347c6cc 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007 Alex Chapman
 ! See http://factorcode.org/license.txt for BSD license.
 USING: combinators kernel generic math math.functions
-math.parser namespaces io sequences trees
+math.parser namespaces io sequences trees shuffle
 assocs parser accessors math.order prettyprint.custom ;
 IN: trees.avl
 
index 66ef154b63c726faf70f6e5bc586ecda2026e108..67b2f6b62456aeca32e71650a0bcd67f6ba783f2 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (c) 2005 Mackenzie Straight.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays kernel math namespaces sequences assocs parser
-trees generic math.order accessors prettyprint.custom ;
+trees generic math.order accessors prettyprint.custom shuffle ;
 IN: trees.splay
 
 TUPLE: splay < tree ;
index 62f4d8fce4ba9367bd7af9c1018e8e0a7be9ed37..77e5e5bdc066ab7cecbd99b6f3ea86ad57df0ba9 100755 (executable)
@@ -2,7 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel generic math sequences arrays io namespaces
 prettyprint.private kernel.private assocs random combinators
-parser math.order accessors deques make prettyprint.custom ;
+parser math.order accessors deques make prettyprint.custom 
+shuffle ;
 IN: trees
 
 TUPLE: tree root count ;
index 8730c0acc48330bd553edc4d7a93b3f2125c7dd1..06f1de6bc8c05d4c2ba0ae7ef21f95ad28f1501e 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2006, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors math.vectors classes.tuple math.rectangles colors
-kernel sequences models opengl math math.order namespaces
+kernel locals sequences models opengl math math.order namespaces
 ui.commands ui.gestures ui.render ui.gadgets ui.gadgets.labels
 ui.gadgets.scrollers ui.gadgets.presentations ui.gadgets.viewports
 ui.gadgets.packs ;
@@ -78,7 +78,7 @@ M: list focusable-child* drop t ;
     dup list-empty? [
         2drop
     ] [
-        tuck control-value length rem >>index
+        [ control-value length rem ] [ (>>index) ] [ ] tri
         [ relayout-1 ] [ scroll>selected ] bi
     ] if ;
 
@@ -95,9 +95,9 @@ M: list focusable-child* drop t ;
         [ index>> ] keep nth-gadget invoke-secondary
     ] if ;
 
-: select-gadget ( gadget list -- )
-    tuck children>> index
-    [ swap select-index ] [ drop ] if* ;
+:: select-gadget ( gadget list -- )
+    gadget list children>> index
+    [ list select-index ] when* ;
 
 : clamp-loc ( point max -- point )
     vmin { 0 0 } vmax ;
index 96497b8bbc5c0cc8c2a992f3bc7af8a5c78ff2f7..5d0fa1cf1e848380e5b791c31d5415e43071956b 100755 (executable)
@@ -10,7 +10,7 @@ IN: units.tests
 [ t ] [ 5 m 1 m d- 4 m = ] unit-test
 [ t ] [ 5 m 2 m d* 10 m^2 = ] unit-test
 [ t ] [ 5 m 2 m d/ 5/2 { } { } <dimensioned> = ] unit-test
-[ t ] [ 5 m 2 m tuck d/ drop 2 m = ] unit-test
+[ t ] [ 2 m 5 m 2 m d/ drop 2 m = ] unit-test
 
 [ t ] [ 1 m 2 m 3 m 3array d-product 6 m^3 = ] unit-test
 [ t ] [ 3 m d-recip 1/3 { } { m } <dimensioned> = ] unit-test
index 0ee2a114dd7b486702f1bb3d08a7f3bafc868a1f..29f710061c4b02ecfad9120d63f4a0fa83aa7baa 100644 (file)
@@ -48,7 +48,7 @@ MEMO: cities-named ( name -- cities )
 
 MEMO: cities-named-in ( name state -- cities )
     cities [
-        tuck [ name>> = ] [ state>> = ] 2bi* and
+        [ name>> = ] [ state>> = ] bi-curry bi* and
     ] with with filter ;
 
 : find-zip-code ( code -- city )