]> gitweb.factorcode.org Git - factor.git/commitdiff
: spin swap rot ;
authorSlava Pestov <slava@factorcode.org>
Sat, 29 Dec 2007 16:36:20 +0000 (11:36 -0500)
committerSlava Pestov <slava@factorcode.org>
Sat, 29 Dec 2007 16:36:20 +0000 (11:36 -0500)
20 files changed:
core/bit-arrays/bit-arrays.factor [changed mode: 0644->0755]
core/combinators/combinators.factor
core/kernel/kernel-docs.factor
core/kernel/kernel.factor
core/sequences/sequences.factor
core/words/words.factor
extra/cocoa/pasteboard/pasteboard.factor [changed mode: 0644->0755]
extra/combinators/lib/lib.factor [changed mode: 0644->0755]
extra/delegate/delegate.factor [changed mode: 0644->0755]
extra/hashtables/lib/lib.factor [changed mode: 0644->0755]
extra/jamshred/tunnel/tunnel.factor [changed mode: 0644->0755]
extra/koszul/koszul.factor [changed mode: 0644->0755]
extra/math/matrices/elimination/elimination.factor [changed mode: 0644->0755]
extra/prolog/prolog.factor [changed mode: 0644->0755]
extra/space-invaders/space-invaders.factor [changed mode: 0644->0755]
extra/ui/gadgets/grid-lines/grid-lines.factor [changed mode: 0644->0755]
extra/unicode/unicode.factor [changed mode: 0644->0755]
extra/units/units.factor [changed mode: 0644->0755]
extra/x/widgets/wm/root/root.factor [changed mode: 0644->0755]
extra/xml/utilities/utilities.factor [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 185ca0c..d1eb780
@@ -20,7 +20,7 @@ IN: bit-arrays
 
 : (set-bits) ( bit-array n -- )
     over length bits>cells -rot [
-        swap rot 4 * set-alien-unsigned-4
+        spin 4 * set-alien-unsigned-4
     ] 2curry each ; inline
 
 PRIVATE>
index 2c418768c67ee78e8e022e557ce0d06c85a6fb48..6f39925bd090e384b044def8ce89e01f034da23f 100755 (executable)
@@ -63,7 +63,7 @@ M: sequence hashcode*
     next-power-of-2 swap [ nip clone ] curry map ;
 
 : distribute-buckets ( assoc initial quot -- buckets )
-    swap rot [ length <buckets> ] keep
+    spin [ length <buckets> ] keep
     [ >r 2dup r> dup first roll call (distribute-buckets) ] each
     nip ; inline
 
index af6acd004b31b9c742ba107be13da1ce45ce2e89..ae30edc7b8c9bdb6ffd72fe03cd3c139bdb31d29 100755 (executable)
@@ -26,6 +26,7 @@ $nl
 { $subsection swapd }
 { $subsection rot }
 { $subsection -rot }
+{ $subsection spin }
 { $subsection roll }
 { $subsection -roll }
 "Sometimes an additional storage area is needed to hold objects. The " { $emphasis "retain stack" } " is an auxilliary stack for this purpose. Objects can be moved between the data and retain stacks using the following two words:"
@@ -37,7 +38,9 @@ $nl
 { $code
     ": foo ( m ? n -- m+n/n )"
     "    >r [ r> + ] [ drop r> ] if ; ! This is OK"
-} ;
+}
+"An alternative to using " { $link >r } " and " { $link r> } " is the following:"
+{ $subsection dip } ;
 
 ARTICLE: "basic-combinators" "Basic combinators"
 "The following pair of words invoke words and quotations reflectively:"
@@ -159,6 +162,7 @@ HELP: tuck  ( x y -- y x y )         $shuffle ;
 HELP: over  ( x y -- x y x )         $shuffle ;
 HELP: pick  ( x y z -- x y z x )     $shuffle ;
 HELP: swap  ( x y -- y x )           $shuffle ;
+HELP: spin                           $shuffle ;
 HELP: roll                           $shuffle ;
 HELP: -roll                          $shuffle ;
 
@@ -541,6 +545,14 @@ HELP: 3compose
     "However, " { $link 3compose } " runs in constant time, and the compiler is able to compile code which calls composed quotations."
 } ;
 
+HELP: dip
+{ $values { "obj" object } { "quot" quotation } }
+{ $description "Calls " { $snippet "quot" } " with " { $snippet "obj" } " hidden on the retain stack." }
+{ $notes "The following are equivalent:"
+    { $code ">r foo bar r>" }
+    { $code "[ foo bar ] dip" }
+} ;
+
 HELP: while
 { $values { "pred" "a quotation with stack effect " { $snippet "( -- ? )" } } { "body" "a quotation" } { "tail" "a quotation" } }
 { $description "Repeatedly calls " { $snippet "pred" } ". If it yields " { $link f } ", iteration stops, otherwise " { $snippet "quot" } " is called. After iteration stops, " { $snippet "tail" } " is called." }
index 6fe0a9588ce3e674baceaf8b438d01aa98a3ac93..625c31eba1b71a6e5f1a42a0762756e617e6e6c7 100755 (executable)
@@ -6,6 +6,8 @@ IN: kernel
 : version ( -- str ) "0.92" ; foldable
 
 ! Stack stuff
+: spin ( x y z -- z y x ) swap rot ; inline
+
 : roll ( x y z t -- y z t x ) >r rot r> swap ; inline
 
 : -roll ( x y z t -- t x y z ) swap >r -rot r> ; inline
@@ -49,7 +51,7 @@ DEFER: if
 
 : 3slip ( quot x y z -- x y z ) >r >r >r call r> r> r> ; inline
 
-: dip ( obj callable -- obj ) swap slip ; inline
+: dip ( obj quot -- obj ) swap slip ; inline
 
 : keep ( x quot -- x ) over slip ; inline
 
index de10e5c2e424f466bb503bbebdaade422a94948b..b5955d01971a1a59c75d5bf87fbbb4f20c6b3374 100755 (executable)
@@ -115,7 +115,7 @@ INSTANCE: integer immutable-sequence
     [ tuck nth-unsafe >r nth-unsafe r> ] 3keep tuck
     >r >r set-nth-unsafe r> r> set-nth-unsafe ; inline
 
-: (head) ( seq n -- from to seq ) 0 swap rot ; inline
+: (head) ( seq n -- from to seq ) 0 spin ; inline
 
 : (tail) ( seq n -- from to seq ) over length rot ; inline
 
@@ -270,7 +270,7 @@ PRIVATE>
 : tail* ( seq n -- tailseq ) from-end tail ;
 
 : copy ( src i dst -- )
-    pick length >r 3dup check-copy swap rot 0 r>
+    pick length >r 3dup check-copy spin 0 r>
     (copy) drop ; inline
 
 M: sequence clone-like
@@ -579,7 +579,7 @@ M: sequence <=>
 
 : join ( seq glue -- newseq )
     [
-        2dup joined-length over new-resizable -rot swap
+        2dup joined-length over new-resizable spin
         [ dup pick push-all ] [ pick push-all ] interleave drop
     ] keep like ;
 
index baec10a8213728e0c7a58f58a622ef9bf99dbce8..23dba982bb81773f0b960fec3a502c573638c41e 100755 (executable)
@@ -94,8 +94,6 @@ M: compound redefined* ( word -- )
 
 <PRIVATE
 
-: changed-word ( word -- ) dup changed-words get set-at ;
-
 : define ( word def -- )
     over unxref
     over redefined
old mode 100644 (file)
new mode 100755 (executable)
index 58cbc88..d266c24
@@ -24,7 +24,7 @@ IN: cocoa.pasteboard
 
 : pasteboard-error ( error -- f )
     "Pasteboard does not hold a string" <NSString>
-    0 swap rot set-void*-nth f ;
+    0 spin set-void*-nth f ;
 
 : ?pasteboard-string ( pboard error -- str/f )
     over pasteboard-string? [
old mode 100644 (file)
new mode 100755 (executable)
index 047887b..39a0457
@@ -120,7 +120,7 @@ MACRO: ifte ( quot quot quot -- )
 
 : preserving ( predicate -- quot )
   dup infer effect-in
-  dup 1+ swap rot
+  dup 1+ spin
   [ , , nkeep , nrot ]
   bake ;
 
old mode 100644 (file)
new mode 100755 (executable)
index 5614296..44da847
@@ -27,9 +27,6 @@ M: tuple-class group-words
     dup [ slot-spec-reader ] map
     swap [ slot-spec-writer ] map append ;
 
-: spin ( x y z -- z y x )
-    swap rot ;
-
 : define-consult-method ( word class quot -- )
     pick add <method> spin define-method ;
 
old mode 100644 (file)
new mode 100755 (executable)
index 1bcd139..9b3932a
@@ -9,7 +9,7 @@ IN: hashtables.lib
 
 ! set-hash with alternative stack effects
 
-: put-hash* ( table key value -- ) swap rot set-at ;
+: put-hash* ( table key value -- ) spin set-at ;
 
 : put-hash ( table key value -- table ) swap pick set-at ;
 
old mode 100644 (file)
new mode 100755 (executable)
index 149170e..4d60a65
@@ -89,7 +89,7 @@ TUPLE: segment number color radius ;
     rot dup length swap <slice> find-nearest-segment ;
 
 : nearest-segment-backward ( segments oint start -- segment )
-    swapd 1+ 0 swap rot <slice> <reversed> find-nearest-segment ;
+    swapd 1+ 0 spin <slice> <reversed> find-nearest-segment ;
 
 : nearest-segment ( segments oint start-segment -- segment )
     #! find the segment nearest to 'oint', and return it.
old mode 100644 (file)
new mode 100755 (executable)
index eb15336..7a97578
@@ -199,7 +199,7 @@ DEFER: (d)
 : bigraded-ker/im-d ( bigraded-basis -- seq )
     dup length [
         over first length [
-            >r 2dup r> swap rot (bigraded-ker/im-d)
+            >r 2dup r> spin (bigraded-ker/im-d)
         ] map 2nip
     ] curry* map ;
 
@@ -277,7 +277,7 @@ DEFER: (d)
 : bigraded-triples ( grid -- triples )
     dup length [
         over first length [
-            >r 2dup r> swap rot bigraded-triple
+            >r 2dup r> spin bigraded-triple
         ] map 2nip
     ] curry* map ;
 
old mode 100644 (file)
new mode 100755 (executable)
index b11ef5b..73f6dd7
@@ -84,7 +84,7 @@ SYMBOL: matrix
 : basis-vector ( row col# -- )
     >r clone r>
     [ swap nth neg recip ] 2keep
-    [ 0 swap rot set-nth ] 2keep
+    [ 0 spin set-nth ] 2keep
     >r n*v r>
     matrix get set-nth ;
 
old mode 100644 (file)
new mode 100755 (executable)
index 0a6a513..580bfaf
@@ -79,6 +79,6 @@ SYMBOL: plchoice
     ] if ;
 
 : binding-resolve ( binds name pat -- binds )
-    tuck lookup-rule dup backtrace? swap rot add-bindings ;
+    tuck lookup-rule dup backtrace? spin add-bindings ;
 
 : is ( binds val var -- binds ) rot [ set-at ] keep ;
old mode 100644 (file)
new mode 100755 (executable)
index 3f695a4..aa76f8e
@@ -293,7 +293,7 @@ M: invaders-gadget draw-gadget* ( gadget -- )
 
 : plot-bitmap-pixel ( bitmap point color -- )
   #! point is a {x y}. color is a {r g b}.
-  swap rot set-bitmap-pixel ;
+  spin set-bitmap-pixel ;
 
 : within ( n a b -- bool )
   #! n >= a and n <= b
old mode 100644 (file)
new mode 100755 (executable)
index f055ab0..8a38737
@@ -14,8 +14,8 @@ SYMBOL: grid-dim
 
 : grid-line-from/to ( orientation point -- from to )
     half-gap v-
-    [ half-gap swap rot set-axis ] 2keep
-    grid-dim get swap rot set-axis ;
+    [ half-gap spin set-axis ] 2keep
+    grid-dim get spin set-axis ;
 
 : draw-grid-lines ( gaps orientation -- )
     grid get rot grid-positions grid get rect-dim add [
old mode 100644 (file)
new mode 100755 (executable)
index bac768b..609b57d
@@ -100,7 +100,7 @@ IN: unicode
     [ dup CHAR: A CHAR: Z between? [ HEX: 20 + ] when ] map ;
 
 : replace ( seq old new -- newseq )
-    swap rot [ 2dup = [ drop over ] when ] map 2nip ;
+    spin [ 2dup = [ drop over ] when ] map 2nip ;
 
 : process-names ( data -- names-hash )
     1 swap (process-data)
@@ -382,7 +382,7 @@ SYMBOL: locale ! Just casing locale, or overall?
     ] if ; inline
 
 : insert ( seq quot elt n -- )
-    swap rot >r -rot [ swap set-nth ] 2keep r> (insert) ; inline
+    spin >r -rot [ swap set-nth ] 2keep r> (insert) ; inline
 
 : insertion-sort ( seq quot -- )
     ! quot is a transformation on elements
old mode 100644 (file)
new mode 100755 (executable)
index 95f4ed8..f7aad72
@@ -69,7 +69,7 @@ M: dimensions-not-equal summary drop "Dimensions do not match" ;
 : d-sq ( d -- d ) dup d* ;
 
 : d-recip ( d -- d' )
-    >dimensioned< swap rot recip dimension-op> ;
+    >dimensioned< spin recip dimension-op> ;
 
 : d/ ( d d -- d ) d-recip d* ;
 
old mode 100644 (file)
new mode 100755 (executable)
index 0ce91d5..f5352a0
@@ -74,7 +74,7 @@ dup XKeyEvent-state swap event>keyname 2array ;
   [ $keymap swap resolve-key-event call ]
 
 "grab-key" !( wm-root modifiers keyname -- wm-root modifiers keyname ) [
-  3dup name>keysym keysym-to-keycode swap rot
+  3dup name>keysym keysym-to-keycode spin
   False GrabModeAsync GrabModeAsync grab-key ]
 
 "set-key-action" !( wm-root modifiers keyname action -- wm-root ) [
old mode 100644 (file)
new mode 100755 (executable)
index 303de42..e64b959
-! Copyright (C) 2005, 2006 Daniel Ehrenberg\r
-! See http://factorcode.org/license.txt for BSD license.\r
-USING: kernel namespaces sequences words io assocs\r
-quotations strings parser arrays xml.data xml.writer debugger\r
-splitting ;\r
-IN: xml.utilities\r
-\r
-! * System for words specialized on tag names\r
-\r
-TUPLE: process-missing process tag ;\r
-M: process-missing error.\r
-    "Tag <" write\r
-    dup process-missing-tag print-name\r
-    "> not implemented on process process " write\r
-    process-missing-process word-name print ;\r
-\r
-: run-process ( tag word -- )\r
-    2dup "xtable" word-prop\r
-    >r dup name-tag r> at* [ 2nip call ] [\r
-        drop \ process-missing construct-boa throw\r
-    ] if ;\r
-\r
-: PROCESS:\r
-    CREATE\r
-    dup H{ } clone "xtable" set-word-prop\r
-    dup [ run-process ] curry define-compound ; parsing\r
-\r
-: TAG:\r
-    scan scan-word\r
-    parse-definition\r
-    swap "xtable" word-prop\r
-    rot "/" split [ >r 2dup r> swap set-at ] each 2drop ;\r
-    parsing\r
-\r
-\r
-! * Common utility functions\r
-\r
-: build-tag* ( items name -- tag )\r
-    "" swap "" <name>\r
-    swap >r { } r> <tag> ;\r
-\r
-: build-tag ( item name -- tag )\r
-    >r 1array r> build-tag* ;\r
-\r
-: build-xml ( tag -- xml )\r
-    T{ prolog f "1.0" "iso-8859-1" f } { } rot { } <xml> ;\r
-\r
-: children>string ( tag -- string )\r
-    tag-children\r
-    dup [ string? ] all?\r
-    [ "XML tag unexpectedly contains non-text children" throw ] unless\r
-    concat ;\r
-\r
-: children-tags ( tag -- sequence )\r
-    tag-children [ tag? ] subset ;\r
-\r
-: first-child-tag ( tag -- tag )\r
-    tag-children [ tag? ] find nip ;\r
-\r
-! * Utilities for searching through XML documents\r
-! These all work from the outside in, top to bottom.\r
-\r
-: with-delegate ( object quot -- object )\r
-    over clone >r >r delegate r> call r>\r
-    [ set-delegate ] keep ; inline\r
-\r
-GENERIC# xml-each 1 ( quot tag -- ) inline\r
-M: tag xml-each\r
-    [ call ] 2keep\r
-    swap tag-children [ swap xml-each ] curry* each ;\r
-M: object xml-each\r
-    call ;\r
-M: xml xml-each\r
-    >r delegate r> xml-each ;\r
-\r
-GENERIC# xml-map 1 ( quot tag -- tag ) inline\r
-M: tag xml-map\r
-    swap clone over >r swap call r> \r
-    swap [ tag-children [ swap xml-map ] curry* map ] keep \r
-    [ set-tag-children ] keep ;\r
-M: object xml-map\r
-    call ;\r
-M: xml xml-map\r
-    swap [ swap xml-map ] with-delegate ;\r
-\r
-: xml-subset ( quot tag -- seq ) ! quot: tag -- ?\r
-    V{ } clone rot [\r
-        swap >r [ swap call ] 2keep rot r>\r
-        swap [ [ push ] keep ] [ nip ] if\r
-    ] xml-each nip ;\r
-\r
-GENERIC# xml-find 1 ( quot tag -- tag ) inline\r
-M: tag xml-find\r
-    [ call ] 2keep swap rot [\r
-        f swap\r
-        [ nip over >r swap xml-find r> swap dup ] find\r
-        2drop ! leaves result of quot\r
-    ] unless nip ;\r
-M: object xml-find\r
-    keep f ? ;\r
-M: xml xml-find\r
-    >r delegate r> xml-find ;\r
-\r
-GENERIC# xml-inject 1 ( quot tag -- ) inline\r
-M: tag xml-inject\r
-    swap [\r
-        swap [ call ] keep\r
-        [ xml-inject ] keep\r
-    ] change-each ;\r
-M: object xml-inject 2drop ;\r
-M: xml xml-inject >r delegate >r xml-inject ;\r
-\r
-! * Accessing part of an XML document\r
-\r
-: get-id ( tag id -- elem ) ! elem=tag.getElementById(id)\r
-    swap [\r
-        dup tag?\r
-        [ "id" swap at over = ]\r
-        [ drop f ] if\r
-    ] xml-find nip ;\r
-\r
-: (get-tag) ( name elem -- ? )\r
-    dup tag? [ names-match? ] [ 2drop f ] if ;\r
-\r
-: tag-named* ( tag name/string -- matching-tag )\r
-    assure-name swap [ dupd (get-tag) ] xml-find nip ;\r
-\r
-: tags-named* ( tag name/string -- tags-seq )\r
-    assure-name swap [ dupd (get-tag) ] xml-subset nip ;\r
-\r
-: tag-named ( tag name/string -- matching-tag )\r
-    ! like get-name-tag but only looks at direct children,\r
-    ! not all the children down the tree.\r
-    assure-name swap [ (get-tag) ] curry* find nip ;\r
-\r
-: tags-named ( tag name/string -- tags-seq )\r
-    assure-name swap [ (get-tag) ] curry* subset ;\r
-\r
-: assert-tag ( name name -- )\r
-    names-match? [ "Unexpected XML tag found" throw ] unless ;\r
+! Copyright (C) 2005, 2006 Daniel Ehrenberg
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel namespaces sequences words io assocs
+quotations strings parser arrays xml.data xml.writer debugger
+splitting ;
+IN: xml.utilities
+
+! * System for words specialized on tag names
+
+TUPLE: process-missing process tag ;
+M: process-missing error.
+    "Tag <" write
+    dup process-missing-tag print-name
+    "> not implemented on process process " write
+    process-missing-process word-name print ;
+
+: run-process ( tag word -- )
+    2dup "xtable" word-prop
+    >r dup name-tag r> at* [ 2nip call ] [
+        drop \ process-missing construct-boa throw
+    ] if ;
+
+: PROCESS:
+    CREATE
+    dup H{ } clone "xtable" set-word-prop
+    dup [ run-process ] curry define-compound ; parsing
+
+: TAG:
+    scan scan-word
+    parse-definition
+    swap "xtable" word-prop
+    rot "/" split [ >r 2dup r> swap set-at ] each 2drop ;
+    parsing
+
+
+! * Common utility functions
+
+: build-tag* ( items name -- tag )
+    "" swap "" <name>
+    swap >r { } r> <tag> ;
+
+: build-tag ( item name -- tag )
+    >r 1array r> build-tag* ;
+
+: build-xml ( tag -- xml )
+    T{ prolog f "1.0" "iso-8859-1" f } { } rot { } <xml> ;
+
+: children>string ( tag -- string )
+    tag-children
+    dup [ string? ] all?
+    [ "XML tag unexpectedly contains non-text children" throw ] unless
+    concat ;
+
+: children-tags ( tag -- sequence )
+    tag-children [ tag? ] subset ;
+
+: first-child-tag ( tag -- tag )
+    tag-children [ tag? ] find nip ;
+
+! * Utilities for searching through XML documents
+! These all work from the outside in, top to bottom.
+
+: with-delegate ( object quot -- object )
+    over clone >r >r delegate r> call r>
+    [ set-delegate ] keep ; inline
+
+GENERIC# xml-each 1 ( quot tag -- ) inline
+M: tag xml-each
+    [ call ] 2keep
+    swap tag-children [ swap xml-each ] curry* each ;
+M: object xml-each
+    call ;
+M: xml xml-each
+    >r delegate r> xml-each ;
+
+GENERIC# xml-map 1 ( quot tag -- tag ) inline
+M: tag xml-map
+    swap clone over >r swap call r>
+    swap [ tag-children [ swap xml-map ] curry* map ] keep
+    [ set-tag-children ] keep ;
+M: object xml-map
+    call ;
+M: xml xml-map
+    swap [ swap xml-map ] with-delegate ;
+
+: xml-subset ( quot tag -- seq ) ! quot: tag -- ?
+    V{ } clone rot [
+        swap >r [ swap call ] 2keep rot r>
+        swap [ [ push ] keep ] [ nip ] if
+    ] xml-each nip ;
+
+GENERIC# xml-find 1 ( quot tag -- tag ) inline
+M: tag xml-find
+    [ call ] 2keep spin [
+        f swap
+        [ nip over >r swap xml-find r> swap dup ] find
+        2drop ! leaves result of quot
+    ] unless nip ;
+M: object xml-find
+    keep f ? ;
+M: xml xml-find
+    >r delegate r> xml-find ;
+
+GENERIC# xml-inject 1 ( quot tag -- ) inline
+M: tag xml-inject
+    swap [
+        swap [ call ] keep
+        [ xml-inject ] keep
+    ] change-each ;
+M: object xml-inject 2drop ;
+M: xml xml-inject >r delegate >r xml-inject ;
+
+! * Accessing part of an XML document
+
+: get-id ( tag id -- elem ) ! elem=tag.getElementById(id)
+    swap [
+        dup tag?
+        [ "id" swap at over = ]
+        [ drop f ] if
+    ] xml-find nip ;
+
+: (get-tag) ( name elem -- ? )
+    dup tag? [ names-match? ] [ 2drop f ] if ;
+
+: tag-named* ( tag name/string -- matching-tag )
+    assure-name swap [ dupd (get-tag) ] xml-find nip ;
+
+: tags-named* ( tag name/string -- tags-seq )
+    assure-name swap [ dupd (get-tag) ] xml-subset nip ;
+
+: tag-named ( tag name/string -- matching-tag )
+    ! like get-name-tag but only looks at direct children,
+    ! not all the children down the tree.
+    assure-name swap [ (get-tag) ] curry* find nip ;
+
+: tags-named ( tag name/string -- tags-seq )
+    assure-name swap [ (get-tag) ] curry* subset ;
+
+: assert-tag ( name name -- )
+    names-match? [ "Unexpected XML tag found" throw ] unless ;