]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJoe Groff <arcata@gmail.com>
Fri, 6 Nov 2009 04:23:21 +0000 (22:23 -0600)
committerJoe Groff <arcata@gmail.com>
Fri, 6 Nov 2009 04:23:21 +0000 (22:23 -0600)
90 files changed:
basis/core-text/core-text-tests.factor
basis/csv/csv-tests.factor
basis/db/sqlite/sqlite.factor
basis/fry/fry-docs.factor
basis/game/input/input.factor
basis/generalizations/generalizations-docs.factor
basis/generalizations/generalizations-tests.factor
basis/generalizations/generalizations.factor
basis/hints/hints-docs.factor
basis/images/jpeg/jpeg.factor
basis/io/backend/windows/nt/nt.factor
basis/io/buffers/buffers-tests.factor
basis/io/files/info/windows/windows.factor
basis/io/launcher/windows/windows.factor
basis/lists/lazy/lazy.factor
basis/math/blas/vectors/vectors.factor
basis/math/combinatorics/combinatorics.factor
basis/math/intervals/intervals-tests.factor
basis/math/matrices/elimination/elimination.factor
basis/persistent/hashtables/hashtables-tests.factor
basis/persistent/hashtables/hashtables.factor
basis/persistent/vectors/vectors.factor
basis/regexp/dfa/dfa.factor
basis/regexp/disambiguate/disambiguate.factor
basis/regexp/minimize/minimize.factor
basis/shuffle/shuffle-docs.factor
basis/shuffle/shuffle.factor
basis/suffix-arrays/suffix-arrays.factor
basis/tools/scaffold/scaffold.factor
basis/ui/traverse/traverse.factor
basis/unix/groups/groups.factor
basis/validators/validators.factor
basis/windows/com/com-tests.factor
basis/windows/com/wrapper/wrapper-docs.factor
basis/xmode/catalog/catalog.factor
basis/xmode/marker/marker.factor
core/generic/single/single.factor
core/kernel/kernel-docs.factor
core/kernel/kernel.factor
extra/bank/bank.factor
extra/benchmark/knucleotide/knucleotide.factor
extra/c/preprocessor/preprocessor.factor
extra/couchdb/couchdb.factor
extra/curses/curses.factor
extra/decimals/decimals.factor
extra/digraphs/digraphs.factor
extra/ecdsa/ecdsa.factor
extra/fries/fries.factor
extra/gpu/framebuffers/framebuffers.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/reports/noise/noise.factor
extra/rot13/rot13.factor
extra/sequences/abbrev/abbrev.factor
extra/sequences/modified/modified.factor
extra/set-n/set-n.factor
extra/space-invaders/space-invaders.factor
extra/spider/spider.factor
extra/sudokus/sudokus.factor
extra/tetris/game/game.factor
extra/tetris/piece/piece.factor
extra/tokyo/assoc-functor/assoc-functor.factor
extra/trees/avl/avl.factor
extra/trees/splay/splay.factor
extra/trees/trees.factor
extra/ui/gadgets/layout/layout.factor
extra/ui/gadgets/lists/lists.factor
extra/units/units-tests.factor
extra/units/units.factor
extra/usa-cities/usa-cities.factor

index a5cf69fdee3e23b7fa5db1aec4b59ddd8db3fffa..b6b54df7c3b567865a3926ce0c6d2a7a0967adfa 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: tools.test core-text core-text.fonts core-foundation
 core-foundation.dictionaries destructors arrays kernel generalizations
-math accessors core-foundation.utilities combinators hashtables colors
+locals math accessors core-foundation.utilities combinators hashtables colors
 colors.constants ;
 IN: core-text.tests
 
@@ -18,10 +18,11 @@ IN: core-text.tests
     ] with-destructors
 ] unit-test
 
-: test-typographic-bounds ( string font -- ? )
+:: test-typographic-bounds ( string font -- ? )
     [
-        test-font &CFRelease tuck COLOR: white <CTLine> &CFRelease
-        compute-line-metrics {
+        font test-font &CFRelease :> ctfont
+        string ctfont COLOR: white <CTLine> &CFRelease :> ctline
+        ctfont ctline compute-line-metrics {
             [ width>> float? ]
             [ ascent>> float? ]
             [ descent>> float? ]
@@ -33,4 +34,4 @@ IN: core-text.tests
 
 [ t ] [ "Hello world" "Chicago" test-typographic-bounds ] unit-test
 
-[ t ] [ "日本語" "Helvetica" test-typographic-bounds ] unit-test
\ No newline at end of file
+[ t ] [ "日本語" "Helvetica" test-typographic-bounds ] unit-test
index 6ba8e2d5b8a965b67767fc7400ce751aed0c3892..829637b4aa18b2e916ac4e6f9aed77d954ffdf4c 100644 (file)
@@ -70,11 +70,12 @@ IN: csv.tests
 
 "can write csv too!"
 [ "foo1,bar1\nfoo2,bar2\n" ]
-[ { { "foo1" "bar1" } { "foo2" "bar2" } } <string-writer> tuck write-csv >string ] named-unit-test
+[ { { "foo1" "bar1" } { "foo2" "bar2" } } <string-writer> [ write-csv ] keep >string ] named-unit-test
+
 
 "escapes quotes commas and newlines when writing"
 [ "\"fo\"\"o1\",bar1\n\"fo\no2\",\"b,ar2\"\n" ]
-[ { { "fo\"o1" "bar1" } { "fo\no2" "b,ar2" } } <string-writer> tuck write-csv >string ] named-unit-test ! "
+[ { { "fo\"o1" "bar1" } { "fo\no2" "b,ar2" } } <string-writer> [ write-csv ] keep >string ] named-unit-test ! "
 
 [ { { "writing" "some" "csv" "tests" } } ]
 [
index ffcbec70d08340f8b0456c71034c2aa61a207660..8d26d3b098c185a2fdcb5bf016c865dcd6a81bf4 100755 (executable)
@@ -4,7 +4,7 @@ USING: alien arrays assocs classes compiler db hashtables
 io.files kernel math math.parser namespaces prettyprint fry
 sequences strings classes.tuple alien.c-types continuations
 db.sqlite.lib db.sqlite.ffi db.tuples words db.types combinators
-math.intervals io nmake accessors vectors math.ranges random
+math.intervals io locals nmake accessors vectors math.ranges random
 math.bitwise db.queries destructors db.tuples.private interpolate
 io.streams.string make db.private sequences.deep
 db.errors.sqlite ;
@@ -85,12 +85,11 @@ M: literal-bind sqlite-bind-conversion ( tuple literal-bind -- array )
     nip [ key>> ] [ value>> ] [ type>> ] tri
     <sqlite-low-level-binding> ;
 
-M: generator-bind sqlite-bind-conversion ( tuple generate-bind -- array )
-    tuck
-    [ generator-singleton>> eval-generator tuck ] [ slot-name>> ] bi
-    rot set-slot-named
-    [ [ key>> ] [ type>> ] bi ] dip
-    swap <sqlite-low-level-binding> ;
+M:: generator-bind sqlite-bind-conversion ( tuple generate-bind -- array )
+    generate-bind generator-singleton>> eval-generator :> obj
+    generate-bind slot-name>> :> name
+    obj name tuple set-slot-named
+    generate-bind key>> obj generate-bind type>> <sqlite-low-level-binding> ;
 
 M: sqlite-statement bind-tuple ( tuple statement -- )
     [
index 9602933785d60492af2ff4ac419145f4a178c01f..3401208858ad242d542936b79ee7127e21e5d398 100644 (file)
@@ -59,7 +59,6 @@ $nl
     { { $link literalize } { $snippet ": literalize '[ _ ] ;" } }\r
     { { $link curry } { $snippet ": curry '[ _ @ ] ;" } }\r
     { { $link compose } { $snippet ": compose '[ @ @ ] ;" } }\r
-    { { $link bi@ } { $snippet ": bi@ tuck '[ _ @ _ @ ] call ;" } }\r
 } ;\r
 \r
 ARTICLE: "fry.philosophy" "Fried quotation philosophy"\r
index 377a89a884b78557e64e9f606a142a51c9f2781d..954602cf0671e95894b41087d782877dd75eade1 100755 (executable)
@@ -75,9 +75,8 @@ SYMBOLS:
     get-controllers [ product-id = ] with filter ;
 : find-controller-instance ( product-id instance-id -- controller/f )
     get-controllers [
-        tuck
         [ product-id  = ]
-        [ instance-id = ] 2bi* and
+        [ instance-id = ] bi-curry bi* and
     ] with with find nip ;
 
 TUPLE: keyboard-state keys ;
index e9a709030e067e86963644f5d2947c26dce2598e..ef6c3767035f7dc24a83b05bac3864b0cf24a7fe 100644 (file)
@@ -332,18 +332,6 @@ HELP: nappend-as
 \r
 { nappend nappend-as } related-words\r
 \r
-HELP: ntuck\r
-{ $values\r
-     { "n" integer }\r
-}\r
-{ $description "A generalization of " { $link tuck } " that can work for any stack depth. The top item will be copied and placed " { $snippet "n" } " items down on the stack." } ;\r
-\r
-HELP: nspin\r
-{ $values\r
-    { "n" integer }\r
-}\r
-{ $description "A generalization of " { $link spin } " that can work for any stack depth. The top " { $snippet "n" } " items will be reversed in order." } ;\r
-\r
 ARTICLE: "sequence-generalizations" "Generalized sequence operations"\r
 { $subsections\r
     narray\r
@@ -363,8 +351,6 @@ ARTICLE: "shuffle-generalizations" "Generalized shuffle words"
     -nrot\r
     nnip\r
     ndrop\r
-    ntuck\r
-    nspin\r
     mnswap\r
     nweave\r
 } ;\r
index c54e35002f3803d56342baf8229b65bf777ef805..546413447e6a28fc1b385ec1f43af84c12fccc11 100644 (file)
@@ -26,8 +26,6 @@ IN: generalizations.tests
 { 0 } [ 0 1 2 3 4 4 ndrop ] unit-test\r
 [ [ 1 ] 5 ndip ] must-infer\r
 [ 1 2 3 4 ] [ 2 3 4 [ 1 ] 3 ndip ] unit-test\r
-[ 5 nspin ] must-infer\r
-[ 1 5 4 3 2 ] [ 1 2 3 4 5 4 nspin ] unit-test\r
 \r
 [ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] must-infer\r
 [ 1 2 3 4 5 2 '[ drop drop drop drop drop _ ] 5 nkeep ] must-infer\r
index 8d6d6f2ac0e77fd347a9b68a9216f2420d9fd602..6c8a0b5fdecf9558538ead28593a5d2904c3bba0 100644 (file)
@@ -71,9 +71,6 @@ MACRO: ndrop ( n -- )
 MACRO: nnip ( n -- )
     '[ [ _ ndrop ] dip ] ;
 
-MACRO: ntuck ( n -- )
-    2 + '[ dup _ -nrot ] ;
-
 MACRO: ndip ( n -- )
     [ [ dip ] curry ] n*quot [ call ] compose ;
 
@@ -112,8 +109,8 @@ MACRO: cleave* ( n -- )
     [ 1 - [ [ [ keep ] curry ] dip compose ] n*quot [ call ] compose ] 
     if-zero ;
 
-MACRO: napply ( n -- )
-    [ [ drop ] ] dip [ '[ tuck _ 2dip call ] ] times ;
+: napply ( quot n -- )
+    [ dupn ] [ spread* ] bi ; inline
 
 : apply-curry ( ...a quot n -- )
     [ [curry] ] dip napply ; inline
@@ -139,6 +136,3 @@ MACRO: nbi-curry ( n -- )
 
 : nappend ( n -- seq ) narray concat ; inline
 
-MACRO: nspin ( n -- )
-    [ [ ] ] swap [ swap [ ] curry compose ] n*quot [ call ] 3append ;
-
index 56a2cb9142a1bdc2c1a90ab7c804ef929269a089..46bdc698b73a59874c1884ba25626bfec96aa5fa 100644 (file)
@@ -20,7 +20,7 @@ HELP: specialized-def
 { $description "Outputs the definition of a word after it has been split into specialized branches. This is the definition which will actually be compiled by the compiler." } ;
 
 HELP: HINTS:
-{ $values { "defspec" "a definition specifier" } { "hints..." "a list of sequences of classes or literals" } }
+{ $values { "defspec" "a word or method" } { "hints..." "a list of sequences of classes or literals" } }
 { $description "Defines specialization hints for a word or a method."
 $nl
 "Each sequence in the list will cause a specialized version of the word to be compiled. Classes are tested for using their predicate, and literals are tested using " { $link eq? } "." }
@@ -35,8 +35,8 @@ $nl
     "M: assoc count-occurrences"
     "    swap [ = nip ] curry assoc-filter assoc-size ;"
     ""
-    "HINTS: { sequence count-occurrences } { object array } ;"
-    "HINTS: { assoc count-occurrences } { object hashtable } ;"
+    "HINTS: M\ sequence count-occurrences { object array } ;"
+    "HINTS: M\ assoc count-occurrences { object hashtable } ;"
 }
 } ;
 
index 4f10808b040887e5f103abafa8d83a5fdbdf7ca6..e305c8477a18f63f2f3a80a0202d4a09018a48f7 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Marc Fauconneau.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays byte-arrays combinators
-grouping compression.huffman images
+grouping compression.huffman images fry
 images.processing io io.binary io.encodings.binary io.files
 io.streams.byte-array kernel locals math math.bitwise
 math.constants math.functions math.matrices math.order
@@ -232,7 +232,7 @@ MEMO: dct-matrix-blas ( -- m ) dct-matrix >float-blas-matrix ;
     block dup length>> sqrt >fixnum group flip
     dup matrix-dim coord-matrix flip
     [
-        [ first2 spin nth nth ]
+        [ '[ _ [ second ] [ first ] bi ] dip nth nth ]
         [ x,y v+ color-id jpeg-image draw-color ] bi
     ] with each^2 ;
 
@@ -295,7 +295,7 @@ MEMO: dct-matrix-blas ( -- m ) dct-matrix >float-blas-matrix ;
     binary [
         [
             { HEX: FF } read-until
-            read1 tuck HEX: 00 = and
+            read1 [ HEX: 00 = and ] keep swap
         ]
         [ drop ] produce
         swap >marker {  EOI } assert=
index 452dc4a409d91908aa301b2052d658c42624d2ba..1301d699134b23147b09814d2eea4648f9d05b7b 100755 (executable)
@@ -50,16 +50,17 @@ M: winnt add-completion ( win32-handle -- )
         } cond
     ] with-timeout ;
 
-:: wait-for-overlapped ( us -- bytes-transferred overlapped error? )
+:: wait-for-overlapped ( usec -- bytes-transferred overlapped error? )
     master-completion-port get-global
-    0 <int> [ ! bytes
-        f <void*> ! key
-        f <void*> [ ! overlapped
-            us [ 1000 /i ] [ INFINITE ] if* ! timeout
-            GetQueuedCompletionStatus zero?
-        ] keep
-        *void* dup [ OVERLAPPED memory>struct ] when
-    ] keep *int spin ;
+    0 <int> :> bytes
+    f <void*> :> key
+    f <void*> :> overlapped
+    usec [ 1000 /i ] [ INFINITE ] if* :> timeout
+    bytes key overlapped timeout GetQueuedCompletionStatus zero? :> error?
+
+    bytes *int
+    overlapped *void* dup [ OVERLAPPED memory>struct ] when
+    error? ;
 
 : resume-callback ( result overlapped -- )
     >c-ptr pending-overlapped get-global delete-at* drop resume-with ;
index d366df7c54ff33aa97b696ff0796eec9ce3740dd..93d2f5b2fc60ce3a1107c4b97918f9296a7660b4 100644 (file)
@@ -8,7 +8,7 @@ strings accessors destructors ;
     [ length ] dip buffer-reset ;
 
 : string>buffer ( string -- buffer )
-    dup length <buffer> tuck buffer-set ;
+    dup length <buffer> [ buffer-set ] keep ;
 
 : buffer-read-all ( buffer -- byte-array )
     [ [ pos>> ] [ ptr>> ] bi <displaced-alien> ]
index 5ae21fcfee111898ae48b66d7ddfefb177dcf998..6bd3f77ffa68df512713bb51b07a0513a2186b91 100755 (executable)
@@ -151,12 +151,16 @@ PRIVATE>
 M: winnt file-system-info ( path -- file-system-info )
     normalize-path root-directory (file-system-info) ;
 
-: volume>paths ( string -- array )
-    16384 <ushort-array> tuck dup length
-    0 <uint> dup [ GetVolumePathNamesForVolumeName 0 = ] dip swap [
-        win32-error-string throw
+:: volume>paths ( string -- array )
+    16384 :> names-buf-length
+    names-buf-length <ushort-array> :> names
+    0 <uint> :> names-length
+
+    string names names-buf-length names-length GetVolumePathNamesForVolumeName :> ret
+    ret 0 = [
+        ret win32-error-string throw
     ] [
-        *uint "ushort" heap-size * head
+        names names-length *uint "ushort" heap-size * head
         utf16n alien>string CHAR: \0 split
     ] if ;
 
@@ -166,13 +170,16 @@ M: winnt file-system-info ( path -- file-system-info )
     FindFirstVolume dup win32-error=0/f
     [ utf16n alien>string ] dip ;
 
-: find-next-volume ( handle -- string/f )
-    MAX_PATH 1 + [ <ushort-array> tuck ] keep
-    FindNextVolume 0 = [
+:: find-next-volume ( handle -- string/f )
+    MAX_PATH 1 + :> buf-length
+    buf-length <ushort-array> :> buf
+
+    handle buf buf-length FindNextVolume :> ret
+    ret 0 = [
         GetLastError ERROR_NO_MORE_FILES =
         [ drop f ] [ win32-error-string throw ] if
     ] [
-        utf16n alien>string
+        buf utf16n alien>string
     ] if ;
 
 : find-volumes ( -- array )
index 6cae50bd9e107272d7369eb45480f1ceaa2bcf0d..8a800115f6421e607744c40514d3ca99f52c036a 100755 (executable)
@@ -132,7 +132,7 @@ M: windows run-process* ( process -- handle )
         current-directory get absolute-path cd
 
         dup make-CreateProcess-args
-        tuck fill-redirection
+        [ fill-redirection ] keep
         dup call-CreateProcess
         lpProcessInformation>>
     ] with-destructors ;
index 7b386e9c819ea1acfc93988b97227fcfb8666355..57cacaa4945c6d83bf56bf317c65ab236ec51ab7 100644 (file)
@@ -114,7 +114,7 @@ M: lazy-until car ( lazy-until -- car )
      cons>> car ;
 
 M: lazy-until cdr ( lazy-until -- cdr )
-     [ cons>> unswons ] keep quot>> tuck call( elt -- ? )
+     [ quot>> ] [ cons>> unswons ] bi over call( elt -- ? )
      [ 2drop nil ] [ luntil ] if ;
 
 M: lazy-until nil? ( lazy-until -- ? )
index 8d057de720d8673852c7104ef50f4fe77a4e066f..8fa41c502613e33e03557de03fa421517da6a88b 100755 (executable)
@@ -78,10 +78,10 @@ PRIVATE>
 : n*V+V ( alpha x y -- alpha*x+y ) clone n*V+V! ; inline
 : n*V ( alpha x -- alpha*x ) clone n*V! ; inline
 
-: V+ ( x y -- x+y )
-    1.0 -rot n*V+V ; inline
-: V- ( x y -- x-y )
-    -1.0 spin n*V+V ; inline
+:: V+ ( x y -- x+y )
+    1.0 x y n*V+V ; inline
+:: V- ( x y -- x-y )
+    -1.0 y x n*V+V ; inline
 
 : Vneg ( x -- -x )
     -1.0 swap n*V ; inline
index bc09f9fe0fa9b609147c751e7eb01a8e05fba3bc..5c03e4187079a3712a9e821cd50048905dba94c8 100644 (file)
@@ -96,9 +96,9 @@ C: <combo> combo
     initial-values [ over 0 > ] [ next-values ] produce
     [ 3drop ] dip ;
 
-: combination-indices ( m combo -- seq )
-    [ tuck dual-index combinadic ] keep
-    seq>> length 1 - swap [ - ] with map ;
+:: combination-indices ( m combo -- seq )
+    combo m combo dual-index combinadic
+    combo seq>> length 1 - swap [ - ] with map ;
 
 : apply-combination ( m combo -- seq )
     [ combination-indices ] keep seq>> nths ;
index 1ee4e1e100f6c7285edb9a7f2ace547bdd95c0af..a569b4af7bb39b852c752d83c85d5c83f48466b0 100644 (file)
@@ -79,7 +79,7 @@ IN: math.intervals.tests
 
 [ t ] [ 1 2 [a,b] dup empty-interval interval-union = ] unit-test
 
-[ t ] [ empty-interval 1 2 [a,b] tuck interval-union = ] unit-test
+[ t ] [ 1 2 [a,b] empty-interval over interval-union = ] unit-test
 
 [ t ] [
     0 1 (a,b) 0 1 [a,b] interval-union 0 1 [a,b] =
@@ -250,7 +250,7 @@ IN: math.intervals.tests
     dup full-interval eq? [
         drop 32 random-bits 31 2^ -
     ] [
-        dup to>> first over from>> first tuck - random +
+        [ ] [ from>> first ] [ to>> first ] tri over - random +
         2dup swap interval-contains? [
             nip
         ] [
index 8411447aac3a183e1ba7b99558b3770c32146a03..5c154a6820a2f68dce5049b3ed3d9ce2b69dd74d 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.vectors math.matrices namespaces
-sequences ;
+USING: kernel locals math math.vectors math.matrices
+namespaces sequences ;
 IN: math.matrices.elimination
 
 SYMBOL: matrix
@@ -85,12 +85,11 @@ SYMBOL: matrix
         ] each
     ] with-matrix ;
 
-: basis-vector ( row col# -- )
-    [ clone ] dip
-    [ swap nth neg recip ] 2keep
-    [ 0 spin set-nth ] 2keep
-    [ n*v ] dip
-    matrix get set-nth ;
+:: basis-vector ( row col# -- )
+    row clone :> row'
+    col# row' nth neg recip :> a
+    0 col# row' set-nth
+    a row n*v col# matrix get set-nth ;
 
 : nullspace ( matrix -- seq )
     echelon reduced dup empty? [
index eea31dd34e700c5475d231658dea0468da04ae29..d66fdd0c089eaacd055ef5926006c17123d4267a 100644 (file)
@@ -1,6 +1,6 @@
 IN: persistent.hashtables.tests
 USING: persistent.hashtables persistent.assocs hashtables assocs
-tools.test kernel namespaces random math.ranges sequences fry ;
+tools.test kernel locals namespaces random math.ranges sequences fry ;
 
 [ t ] [ PH{ } assoc-empty? ] unit-test
 
@@ -86,7 +86,7 @@ M: hash-0-b hashcode* 2drop 0 ;
 : random-assocs ( n -- hash phash )
     [ random-string ] replicate
     [ H{ } clone [ '[ swap _ set-at ] each-index ] keep ]
-    [ PH{ } clone swap [ spin new-at ] each-index ]
+    [ PH{ } clone swap [| ph elt i | i elt ph new-at ] each-index ]
     bi ;
 
 : ok? ( assoc1 assoc2 -- ? )
index 0179216e62a7acc1f0a474e613695316dac56150..256baabd5ed825c457cf8b72a73cfad945286092 100644 (file)
@@ -1,7 +1,7 @@
 ! Based on Clojure's PersistentHashMap by Rich Hickey.
 
 USING: kernel math accessors assocs fry combinators parser
-prettyprint.custom make
+prettyprint.custom locals make
 persistent.assocs
 persistent.hashtables.nodes
 persistent.hashtables.nodes.empty
@@ -38,8 +38,8 @@ M: persistent-hash pluck-at
 
 M: persistent-hash >alist [ root>> >alist% ] { } make ;
 
-: >persistent-hash ( assoc -- phash )
-    T{ persistent-hash } swap [ spin new-at ] assoc-each ;
+:: >persistent-hash ( assoc -- phash )
+    T{ persistent-hash } assoc [| ph k v | v k ph new-at ] assoc-each ;
 
 M: persistent-hash equal?
     over persistent-hash? [ assoc= ] [ 2drop f ] if ;
index 2527959f325f0317cd6540a0c3ab2a625e45f2fe..b02604e9bd8ca02f856a2cd27d1d8c7697cef08a 100644 (file)
@@ -58,7 +58,7 @@ M: persistent-vector nth-unsafe
     [ 2array ] [ drop level>> 1 + ] 2bi node boa ;
 
 : new-child ( new-child node -- node' expansion/f )
-    dup full? [ tuck level>> 1node ] [ node-add f ] if ;
+    dup full? [ [ level>> 1node ] keep swap ] [ node-add f ] if ;
 
 : new-last ( val seq -- seq' )
     [ length 1 - ] keep new-nth ;
@@ -70,7 +70,7 @@ M: persistent-vector nth-unsafe
     dup level>> 1 = [
         new-child
     ] [
-        tuck children>> last (ppush-new-tail)
+        [ nip ] 2keep children>> last (ppush-new-tail)
         [ swap new-child ] [ swap node-set-last f ] ?if
     ] if ;
 
index 2de4e8b0e02322d7a3391c86f607944d18125ace..fa75232fd5c0b7472da6c765b6bca3b60a43aa8b 100644 (file)
@@ -25,7 +25,7 @@ IN: regexp.dfa
     ] unless ;
 
 : epsilon-table ( states nfa -- table )
-    [ H{ } clone tuck ] dip
+    [ [ H{ } clone ] dip over ] dip
     '[ _ _ t epsilon-loop ] each ;
 
 : find-epsilon-closure ( states nfa -- dfa-state )
index 876d898cb4e48ca36ad058bf5758b704bdbc7f4e..fcde135cf887c0fb1af245ef8332f1d634624f91 100644 (file)
@@ -44,12 +44,12 @@ TUPLE: parts in out ;
         [ _ meaningful-integers ] keep add-out
     ] map ;
 
-: class-partitions ( classes -- assoc )
-    [ integer? ] partition [
-        dup powerset-partition spin add-integers
-        [ [ partition>class ] keep 2array ] map
-        [ first ] filter
-    ] [ '[ _ singleton-partition ] map ] 2bi append ;
+:: class-partitions ( classes -- assoc )
+    classes [ integer? ] partition :> ( integers classes )
+    
+    classes powerset-partition classes integers add-integers
+    [ [ partition>class ] keep 2array ] map [ first ] filter
+    integers [ classes singleton-partition ] map append ;
 
 : new-transitions ( transitions -- assoc ) ! assoc is class, partition
     values [ keys ] gather
index 1885144e6ccb45937d7aa3d8174fa37aa5870ff5..a6eb4f00a288dbf752ccd8a1d2fd74aa9b441321 100644 (file)
@@ -85,7 +85,7 @@ IN: regexp.minimize
     '[ _ delete-duplicates ] change-transitions ;
 
 : combine-state-transitions ( hash -- hash )
-    H{ } clone tuck '[
+    [ H{ } clone ] dip over '[
         _ [ 2array <or-class> ] change-at
     ] assoc-each [ swap ] assoc-map ;
 
index 15398450a7e63d238a22abe0e6cd0d933d5c731c..ebb87eda7a66c2c3b2a37e9f97fd089c676115d2 100644 (file)
@@ -1,5 +1,6 @@
 USING: help.markup help.syntax ;
 IN: shuffle
 
+HELP: spin  $complex-shuffle ;
 HELP: roll  $complex-shuffle ;
 HELP: -roll $complex-shuffle ;
index 43c0b75be1cd91b38cb90af537a04eeeaee82407..4388aedb3e9d8a68171c0cc797f106fc76feed9a 100644 (file)
@@ -22,6 +22,8 @@ MACRO: shuffle-effect ( effect -- )
 SYNTAX: shuffle(
     ")" parse-effect suffix! \ shuffle-effect suffix! ;
 
+: spin ( x y z -- z y x ) swap rot ; inline deprecated
+
 : roll ( x y z t -- y z t x ) [ rot ] dip swap ; inline deprecated
 
 : -roll ( x y z t -- t x y z ) swap [ -rot ] dip ; inline deprecated
index 931cb36ea949b8c394164e3e85d9bbdaa34b09bb..f486adcb32e27f882289eb4a6b4b567c41706126 100755 (executable)
@@ -22,8 +22,7 @@ IN: suffix-arrays
 
 : <funky-slice> ( from/f to/f seq -- slice )
     [
-        tuck
-        [ drop 0 or ] [ length or ] 2bi*
+        [ drop 0 or ] [ length or ] bi-curry bi*
         [ min ] keep
     ] keep <slice> ; inline
 
index 089bad3158ba44dde8506b8b11a2956039421bd1..936d388b0126095ecfc58e72ec32cdfd4b997648 100755 (executable)
@@ -98,7 +98,7 @@ M: bad-developer-name summary
     [ main-file-string ] dip utf8 set-file-contents ;
 
 : scaffold-main ( vocab-root vocab -- )
-    tuck ".factor" vocab-root/vocab/suffix>path scaffolding? [
+    [ ".factor" vocab-root/vocab/suffix>path ] keep swap scaffolding? [
         set-scaffold-main-file
     ] [
         2drop
index 11c2a48a2a5408900b03b538f9390eae9f4a36bb..5a92a4cea211c4d711cd7ad7f46b3ec4d8743f97 100644 (file)
@@ -20,8 +20,9 @@ TUPLE: node value children ;
         ] [
             [
                 [ children>> swap first head-slice % ]
-                [ tuck traverse-step traverse-to-path ]
-                2bi
+                [ nip ]
+                [ traverse-step traverse-to-path ]
+                2tri
             ] make-node
         ] if
     ] if ;
@@ -35,7 +36,9 @@ TUPLE: node value children ;
         ] [
             [
                 [ traverse-step traverse-from-path ]
-                [ tuck children>> swap first 1 + tail-slice % ] 2bi
+                [ nip ]
+                [ children>> swap first 1 + tail-slice % ]
+                2tri
             ] make-node
         ] if
     ] if ;
index c4392c4c6da9ec3fb009c9d995fb4b58c992940a..02d9f370236d4d0135da2c688af99ebbdbd8e0d4 100644 (file)
@@ -23,7 +23,7 @@ GENERIC: group-struct ( obj -- group/f )
     gr_mem>> utf8 alien>strings ;
 
 : (group-struct) ( id -- group-struct id group-struct byte-array length void* )
-    \ unix:group <struct> tuck 4096
+    [ \ unix:group <struct> ] dip over 4096
     [ <byte-array> ] keep f <void*> ;
 
 : check-group-struct ( group-struct ptr -- group-struct/f )
index f0ee13dd382c205cd55806fc3097a290463cc5ee..f2c5691452458497180028612a5185d87aeaf571 100644 (file)
@@ -9,7 +9,7 @@ IN: validators
     >lower "on" = ;
 
 : v-default ( str def -- str/def )
-    over empty? spin ? ;
+    [ nip empty? ] 2keep ? ;
 
 : v-required ( str -- str )
     dup empty? [ "required" throw ] when ;
index ae8ef62c1631d7272efe80fa532ab3b76a33e789..25e30829c091f13bf77cad24a4a2bbf0092e0d79 100644 (file)
@@ -44,8 +44,8 @@ C: <test-implementation> test-implementation
         [ >>x drop ] ! IInherited::setX
     } }
     { IUnrelated {
-        [ swap x>> + ] ! IUnrelated::xPlus
-        [ spin x>> * + ] ! IUnrelated::xMulAdd
+        [ [ x>> ] [ + ] bi* ] ! IUnrelated::xPlus
+        [ [ x>> ] [ * ] [ + ] tri* ] ! IUnrelated::xMulAdd
     } }
 } <com-wrapper>
 dup +test-wrapper+ set [
index 6a6f6f2bb44ec8dd73699a55e786fc36d37a3fbd..0298e80445fb27436bbc003c72329404e3db2dc9 100644 (file)
@@ -27,8 +27,8 @@ COM-INTERFACE: IUnrelated IUnknown {b06ac3f4-30e4-406b-a7cd-c29cead4552c}
         [ >>x drop ]     ! IInherited::setX\r
     } }\r
     { "IUnrelated" {\r
-        [ swap x>> + ]   ! IUnrelated::xPlus\r
-        [ spin x>> * + ] ! IUnrealted::xMulAdd\r
+        [ [ x>> ] [ + ] bi* ]   ! IUnrelated::xPlus\r
+        [ [ x>> ] [ * ] [ + ] tri* ] ! IUnrealted::xMulAdd\r
     } }\r
 } <com-wrapper>""" } ;\r
 \r
index 97de95a932d8ded288a696cb4524e8c315b45f37..40b8e2191c1173a329ff4d9cd9e011b5f4e2dc1a 100644 (file)
@@ -110,7 +110,7 @@ ERROR: mutually-recursive-rulesets ruleset ;
     dup [ glob-matches? ] [ 2drop f ] if ;
 
 : suitable-mode? ( file-name first-line mode -- ? )
-    tuck first-line-glob>> ?glob-matches
+    [ nip ] 2keep first-line-glob>> ?glob-matches
     [ 2drop t ] [ file-name-glob>> ?glob-matches ] if ;
 
 : find-mode ( file-name first-line -- mode )
index d3a4f1e9a22a17c99af1bc999e4a4a159a53bdac..6b8db76ac97e88186280949eb8c9855a38563851 100755 (executable)
@@ -86,7 +86,7 @@ M: regexp text-matches?
     [ >string ] dip first-match dup [ to>> ] when ;
 
 : rule-start-matches? ( rule -- match-count/f )
-    dup start>> tuck swap can-match-here? [
+    [ start>> dup ] keep can-match-here? [
         rest-of-line swap text>> text-matches?
     ] [
         drop f
@@ -96,7 +96,7 @@ M: regexp text-matches?
     dup mark-following-rule? [
         dup start>> swap can-match-here? 0 and
     ] [
-        dup end>> tuck swap can-match-here? [
+        [ end>> dup ] keep can-match-here? [
             rest-of-line
             swap text>> context get end>> or
             text-matches?
@@ -170,7 +170,7 @@ M: seq-rule handle-rule-start
     ?end-rule
     mark-token
     add-remaining-token
-    tuck body-token>> next-token,
+    [ body-token>> next-token, ] keep
     delegate>> [ push-context ] when* ;
 
 UNION: abstract-span-rule span-rule eol-span-rule ;
@@ -179,7 +179,7 @@ M: abstract-span-rule handle-rule-start
     ?end-rule
     mark-token
     add-remaining-token
-    tuck rule-match-token* next-token,
+    [ rule-match-token* next-token, ] keep
     ! ... end subst ...
     dup context get (>>in-rule)
     delegate>> push-context ;
@@ -190,7 +190,7 @@ M: span-rule handle-rule-end
 M: mark-following-rule handle-rule-start
     ?end-rule
     mark-token add-remaining-token
-    tuck rule-match-token* next-token,
+    [ rule-match-token* next-token, ] keep
     f context get (>>end)
     context get (>>in-rule) ;
 
index 1434acf5217e53c4009e24414cdff8eeb7886c9a..5636c336c354d7bdc66ea893f5f6728712827691 100644 (file)
@@ -63,7 +63,7 @@ TUPLE: predicate-engine class methods ;
 
 C: <predicate-engine> predicate-engine
 
-: push-method ( method specializer atomic assoc -- )
+: push-method ( specializer method atomic assoc -- )
     dupd [
         [ ] [ H{ } clone <predicate-engine> ] ?if
         [ methods>> set-at ] keep
@@ -71,7 +71,7 @@ C: <predicate-engine> predicate-engine
 
 : flatten-method ( class method assoc -- )
     [ [ flatten-class keys ] keep ] 2dip [
-        [ spin ] dip push-method
+        [ swap rot ] dip push-method
     ] 3curry each ;
 
 : flatten-methods ( assoc -- assoc' )
index f70d9d42145ae9659c636faf7b548d40873f02b3..7327285ffd0bb79b5483bf964f412ffccb0682ba 100644 (file)
@@ -21,7 +21,6 @@ HELP: 2over                          $shuffle ;
 HELP: pick  ( x y z -- x y z x )     $shuffle ;
 HELP: swap  ( x y -- y x )           $shuffle ;
 
-HELP: spin                     $complex-shuffle ;
 HELP: rot   ( x y z -- y z x ) $complex-shuffle ;
 HELP: -rot  ( x y z -- z x y ) $complex-shuffle ;
 HELP: dupd  ( x y -- x x y )   $complex-shuffle ;
@@ -828,7 +827,6 @@ $nl
     swapd
     rot
     -rot
-    spin
 } ;
 
 ARTICLE: "shuffle-words" "Shuffle words"
index a0934c2b17bcbc2d1201538d8fb62358f233a9dd..bb27f7e57e499983f0f8dbb971a6ed3033a1da96 100644 (file)
@@ -8,8 +8,6 @@ DEFER: 2dip
 DEFER: 3dip
 
 ! Stack stuff
-: spin ( x y z -- z y x ) swap rot ; inline
-
 : 2over ( x y z -- x y z x y ) pick pick ; inline
 
 : clear ( -- ) { } set-datastack ;
index 31a4b75eb2e985bddb92e7b55d992bd2671c0f92..a379a03828a227d7269b5befdda8e5ce050e4b22 100644 (file)
@@ -63,7 +63,7 @@ C: <transaction> transaction
 
 : process-to-date ( account date -- account )
     over interest-last-paid>> 1 days time+
-    [ dupd process-day ] spin each-day ;
+    [ [ dupd process-day ] ] 2dip swap each-day ;
 
 : inserting-transactions ( account transactions -- account )
     [ [ date>> process-to-date ] keep >>transaction ] each ;
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 e8176c8df8a99403449da335b5187f83d42a6924..d69583e12447c3b397c332f1e40c05468af18f00 100644 (file)
@@ -93,11 +93,11 @@ ERROR: header-file-missing path ;
     skip-whitespace/comments
     [ current { [ blank? ] [ CHAR: ( = ] } 1|| ] take-until ;
 
-: handle-define ( preprocessor-state sequence-parser -- )
-    [ take-define-identifier ]
-    [ skip-whitespace/comments take-rest ] bi 
-    "\\" ?tail [ readlns append ] when
-    spin symbol-table>> set-at ;
+:: handle-define ( preprocessor-state sequence-parser -- )
+    sequence-parser take-define-identifier :> ident
+    sequence-parser skip-whitespace/comments take-rest :> def
+    def "\\" ?tail [ readlns append ] when :> def
+    def ident preprocessor-state symbol-table>> set-at ;
 
 : handle-undef ( preprocessor-state sequence-parser -- )
     take-token swap symbol-table>> delete-at ;
index da71acb07408a94b9446bfcaadaa8cca948ded10..ed5dd1268fa9042a445a176879a9e454a6dbad04 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs continuations debugger hashtables http
 http.client io io.encodings.string io.encodings.utf8 json.reader
-json.writer kernel make math math.parser namespaces sequences strings
-urls urls.encoding vectors ;
+json.writer kernel locals make math math.parser namespaces sequences
+strings urls urls.encoding vectors ;
 IN: couchdb
 
 ! NOTE: This code only works with the latest couchdb (0.9.*), because old
@@ -136,8 +136,9 @@ C: <db> db
 : attachments> ( assoc -- attachments ) "_attachments" swap at ;
 : >attachments ( assoc attachments -- assoc ) "_attachments" pick set-at ;
 
-: copy-key ( to from to-key from-key -- )
-    rot at spin set-at ;
+:: copy-key ( to from to-key from-key -- )
+    from-key from at
+    to-key to set-at ;
 
 : copy-id ( to from -- )
     "_id" "id" copy-key ;
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 2b3379861f3c3c7752bbd892df61eea2a035e250..ccbe90fb3c40ddbecd2d600605b2c37e3dc8f0d8 100755 (executable)
@@ -44,7 +44,7 @@ DEFER: (topological-sort)
     ] if ;
 
 : topological-sort ( digraph -- seq )
-    dup clone V{ } clone spin
+    [ V{ } clone ] dip [ clone ] keep
     [ drop (topological-sort) ] assoc-each drop reverse ;
 
 : topological-sorted-values ( digraph -- seq )
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 133e8913ddf684ffd83e9abedf7241684a6c0d8c..3f970a86bfa91554c10bb2f823e9f7c64f6a9e48 100644 (file)
@@ -1,11 +1,15 @@
 USING: arrays vectors combinators effects kernel math sequences splitting
 strings.parser parser fry sequences.extras ;
+
+! a b c glue => acb
+! c b a [ append ] dip prepend
+
 IN: fries
 : str-fry ( str on -- quot ) split
-    [ unclip-last [ [ spin glue ] reduce-r ] 2curry ]
+    [ unclip-last [ [ [ append ] [ prepend ] bi* ] reduce-r ] 2curry ]
     [ length 1 - 1 <effect> [ call-effect ] 2curry ] bi ;
 : gen-fry ( str on -- quot ) split
-    [ unclip-last [ [ spin 1array glue ] reduce-r ] 2curry ]
+    [ unclip-last [ [ [ 1array ] [ append ] [ prepend ] tri* ] reduce-r ] 2curry ]
     [ length 1 - 1 <effect> [ call-effect ] 2curry ] bi ;
 
 SYNTAX: i" parse-string rest "_" str-fry append! ;
index efd71782d01550e353d9c22e94f0b27231d94a2a..bea72961e4f6729f074e01a3294af398823c8f90 100755 (executable)
@@ -157,10 +157,13 @@ M: renderbuffer framebuffer-attachment-dim
     [ swap depth-attachment>>   [ swap call ] [ drop ] if* ]
     [ swap stencil-attachment>> [ swap call ] [ drop ] if* ] 2tri ; inline
 
-: each-attachment-target ( framebuffer quot: ( attachment-target attachment -- ) -- )
-    [ [ color-attachments>> ] dip [ GL_COLOR_ATTACHMENT0 + swap ] prepose each-index ]
-    [ swap depth-attachment>>   [ GL_DEPTH_ATTACHMENT   spin call ] [ drop ] if* ]
-    [ swap stencil-attachment>> [ GL_STENCIL_ATTACHMENT spin call ] [ drop ] if* ] 2tri ; inline
+:: each-attachment-target ( framebuffer quot: ( attachment-target attachment -- ) -- )
+    framebuffer color-attachments>>
+    [| attachment n | n GL_COLOR_ATTACHMENT0 + attachment quot call ] each-index
+    framebuffer depth-attachment>>
+    [| attachment | GL_DEPTH_ATTACHMENT attachment quot call ] when*
+    framebuffer stencil-attachment>>
+    [| attachment | GL_STENCIL_ATTACHMENT attachment quot call ] when* ; inline
 
 GENERIC: bind-framebuffer-attachment ( attachment-target attachment -- )
 
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 f7eac9d02cab343f611abc49532e3c237adcbb8f..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
@@ -77,10 +78,10 @@ CONSTANT: default-segment-radius 1
     find 2drop ;
     
 : nearest-segment-forward ( segments oint start -- segment )
-    rot dup length swap <slice> find-nearest-segment ;
+    rot tail-slice find-nearest-segment ;
 
 : nearest-segment-backward ( segments oint start -- segment )
-    swapd 1 + 0 spin <slice> <reversed> find-nearest-segment ;
+    1 + rot head-slice <reversed> find-nearest-segment ;
 
 : nearest-segment ( segments oint start-segment -- segment )
     #! find the segment nearest to 'oint', and return it.
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 59efec1c02302124c896aa0956fc71e538470e8b..f5b30f49da7a61dfa2659cec521e483d30195ed8 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2006, 2007 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays hashtables assocs io kernel math
+USING: accessors arrays hashtables assocs io kernel locals math
 math.vectors math.matrices math.matrices.elimination namespaces
 parser prettyprint sequences words combinators math.parser
 splitting sorting shuffle sets math.order ;
@@ -191,12 +191,12 @@ DEFER: (d)
     [ ?nth ?nth ] 3keep [ [ 2 + ] dip 1 - ] dip ?nth ?nth
     dim-im/ker-d ;
 
-: bigraded-ker/im-d ( bigraded-basis -- seq )
-    dup length [
-        over first length [
-            [ 2dup ] dip spin (bigraded-ker/im-d)
-        ] map 2nip
-    ] with map ;
+:: bigraded-ker/im-d ( basis -- seq )
+    basis length iota [| z |
+         basis first length iota [| u |
+            u z basis (bigraded-ker/im-d)
+        ] map
+    ] map ;
 
 : bigraded-betti ( u-generators z-generators -- seq )
     [ basis graded ] bi@ tensor bigraded-ker/im-d
@@ -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 )
@@ -270,12 +268,12 @@ DEFER: (d)
     3tri
     3array ;
 
-: bigraded-triples ( grid -- triples )
-    dup length [
-        over first length [
-            [ 2dup ] dip spin bigraded-triple
-        ] map 2nip
-    ] with map ;
+:: bigraded-triples ( grid -- triples )
+    grid length [| z |
+        grid first length [| u |
+            u z grid bigraded-triple
+        ] map
+    ] map ;
 
 : bigraded-laplacian ( u-generators z-generators quot -- seq )
     [ [ basis graded ] bi@ tensor bigraded-triples ] dip
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 9eb2804b4298c7f89aaba649211618e83fc0352b..cc6c9ee33f174d94c75883efefaaf9d633dee566 100755 (executable)
@@ -49,15 +49,12 @@ IN: reports.noise
         { nkeep 5 }\r
         { npick 6 }\r
         { nrot 5 }\r
-        { ntuck 6 }\r
         { nwith 4 }\r
         { over 2 }\r
         { pick 4 }\r
         { rot 3 }\r
-        { spin 3 }\r
         { swap 1 }\r
         { swapd 3 }\r
-        { tuck 2 }\r
         { with 1/2 }\r
 \r
         { bi 1/2 }\r
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 04731b0e27d6210833b4c500a029090ba7d2a4a1..80d8bf224695914714862a7264ed4d225ff0cef7 100644 (file)
@@ -1,9 +1,9 @@
-USING: accessors assocs fry generalizations kernel math
-namespaces parser sequences words ;
+USING: accessors assocs fry generalizations kernel locals math
+namespaces parser sequences shuffle words ;
 IN: set-n
 : get* ( var n -- val ) namestack dup length rot - head assoc-stack ;
 
 : set* ( val var n -- ) 1 + namestack [ length swap - ] keep nth set-at ;
 
 ! dynamic lambda
-SYNTAX: :| (:) dup in>> dup length [ spin '[ _ narray _ swap zip _ bind ] ] 2curry dip define-declared ;
\ No newline at end of file
+SYNTAX: :| (:) dup in>> dup length [ spin '[ _ narray _ swap zip _ bind ] ] 2curry dip define-declared ;
index 07b5608a767159e16f5ecb69d83584033450cf25..3d0369128740fb471c3a19a5dcdfaafcc6171c84 100755 (executable)
@@ -14,7 +14,9 @@ USING:
     io.files
     io.pathnames
     kernel 
+    locals
     math
+    math.order
     openal
     opengl.gl
     sequences
@@ -40,12 +42,11 @@ CONSTANT: game-height 256
   #! Point is a {x y}.
   first2 game-width 3 * * swap 3 * + ;
 
-: set-bitmap-pixel ( color point array -- )
-  #! 'color' is a {r g b}. Point is {x y}.
-  [ bitmap-index ] dip ! color index array
-  [ [ first ] 2dip set-nth ] 3keep
-  [ [ second ] 2dip [ 1 + ] dip set-nth ] 3keep
-  [ third ] 2dip [ 2 + ] dip set-nth ;
+:: set-bitmap-pixel ( bitmap point color -- )
+    point bitmap-index :> index
+    color first  index     bitmap set-nth
+    color second index 1 + bitmap set-nth
+    color third  index 2 + bitmap set-nth ;
 
 : get-bitmap-pixel ( point array -- color )
   #! Point is a {x y}. color is a {r g b} 
@@ -139,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? ;
@@ -317,19 +318,15 @@ CONSTANT: red   { 255 0 0 }
 
 : plot-bitmap-pixel ( bitmap point color -- )
   #! point is a {x y}. color is a {r g b}.
-  spin set-bitmap-pixel ;
-
-: within ( n a b -- bool )
-  #! n >= a and n <= b
-  rot tuck swap <= [ swap >= ] dip and ;
+  set-bitmap-pixel ;
 
 : 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 ff20f1520469107d7e4b912eec893c132dc49a2b..c7bc6944fb9eb6812edcf08438fcad9dbfc3eb04 100644 (file)
@@ -21,7 +21,7 @@ IN: sudokus
 : solution ( puzzle random? -- solution ) dupd solutions dup +nil+ = [ drop "Unsolvable" alert* ] [ nip car ] if ;
 : hint ( puzzle -- puzzle' ) [ [ f swap indices random dup ] [ f solution ] bi nth ] keep swapd >vector [ set-nth ] keep ;
 : create ( difficulty -- puzzle ) 81 [ f ] replicate
-    40 random solution [ [ dup length random f spin set-nth ] curry times ] keep ;
+    40 random solution [ [ f swap [ length random ] keep set-nth ] curry times ] keep ;
 
 : do-sudoku ( -- ) [ [
         [
index e1b5867f64ed684ae5095036171bd144b60da824..c9e235ff7953ef71350d8b78cf2e4608d842c39d 100644 (file)
@@ -38,7 +38,7 @@ CONSTANT: default-height 20
     level>> 1 - 60 * 1000 swap - ;
 
 : add-block ( tetris block -- )
-    over board>> spin current-piece tetromino>> colour>> set-block ;
+    over [ board>> ] 2dip current-piece tetromino>> colour>> set-block ;
 
 : game-over? ( tetris -- ? )
     [ board>> ] [ next-piece ] bi piece-valid? not ;
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 122e6133874fbdbb0e8bbbad8b21e00043620d74..bb2b1d8b6d8be5b8c7c6606f72b00c3b3e67423f 100644 (file)
@@ -44,11 +44,11 @@ M: TYPE assoc-size ( db -- size ) handle>> DBRNUM ;
 M: TYPE >alist ( db -- alist )
     [ DBKEYS dup ] keep '[ dup _ at 2array ] map! drop ;
 
-M: TYPE set-at ( value key db -- )
-    handle>> spin [ object>bytes dup length ] bi@ DBPUT drop ;
+M:: TYPE set-at ( value key db -- )
+    db handle>> key value [ object>bytes dup length ] bi@ DBPUT drop ;
 
-M: TYPE delete-at ( key db -- )
-    handle>> swap object>bytes dup length DBOUT drop ;
+M:: TYPE delete-at ( key db -- )
+    db handle>> key object>bytes dup length DBOUT drop ;
 
 M: TYPE clear-assoc ( db -- ) handle>> DBVANISH drop ;
 
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 7bdde95d60e8fd4499be1a6e2b0ee3d492e15e95..c287b9a0598ed33f4525c0b509ca30ca8ec8be59 100644 (file)
@@ -23,8 +23,9 @@ TUPLE: placeholder < gadget members ;
 ! Just take the previous mentioned placeholder and use it
 ! If there is no previously mentioned placeholder, we're probably making a box, and will create the placeholder ourselves
 DEFER: with-interface
-: insertion-quot ( quot -- quot' ) make:building get [ [ placeholder? ] find-last nip [ <placeholder> dup , ] unless*
-    templates get spin '[ [ _ templates set _ , @ ] with-interface ] ] when* ;
+: insertion-quot ( quot -- quot' )
+    make:building get [ [ placeholder? ] find-last nip [ <placeholder> dup , ] unless*
+    [ templates get ] 2dip swap '[ [ _ templates set _ , @ ] with-interface ] ] when* ;
 
 SYNTAX: ,% scan string>number [ <layout> , ] curry append! ;
 SYNTAX: ->% scan string>number '[ [ _ <layout> , ] [ output-model ] bi ] append! ;
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 b8e3f45a16eca370ff3ed7c63f1689c5dcd0252f..a293d79f78cc3c962e7cbc85e508bb3699da35f5 100755 (executable)
@@ -28,9 +28,9 @@ M: dimensions-not-equal summary drop "Dimensions do not match" ;
     dimensioned boa ;
 
 : >dimensioned< ( d -- n top bot )
-    [ value>> ] [ top>> ] [ bot>> ] tri ;
+    [ bot>> ] [ top>> ] [ value>> ] tri ;
 
-\ <dimensioned> [ >dimensioned< ] define-inverse
+\ <dimensioned> [ [ dimensioned boa ] undo ] define-inverse
 
 : dimensions ( dimensioned -- top bot )
     [ top>> ] [ bot>> ] bi ;
@@ -65,7 +65,7 @@ M: dimensions-not-equal summary drop "Dimensions do not match" ;
 : d-sq ( d -- d ) dup d* ;
 
 : d-recip ( d -- d' )
-    >dimensioned< spin recip dimension-op> ;
+    >dimensioned< recip dimension-op> ;
 
 : d/ ( d d -- d ) d-recip d* ;
 
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 )