]> gitweb.factorcode.org Git - factor.git/commitdiff
extra sequences functions moved out of core
authorSam Anklesaria <sam@Tintin.local>
Wed, 17 Jun 2009 17:35:09 +0000 (12:35 -0500)
committerSam Anklesaria <sam@Tintin.local>
Wed, 17 Jun 2009 17:35:09 +0000 (12:35 -0500)
core/sequences/sequences.factor
core/vocabs/parser/parser.factor [changed mode: 0644->0755]
extra/file-trees/file-trees.factor
extra/fries/fries.factor
extra/recipes/recipes.factor
extra/ui/frp/functors/functors.factor
extra/ui/frp/gadgets/gadgets.factor
extra/ui/frp/signals/signals.factor

index ab4772de51ccae591fb91b4ce09bb4a9e37470fe..6eea87234399ea509ab86847b8cd4498ea128360 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2005, 2009 Slava Pestov, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel kernel.private locals slots.private math
+USING: accessors kernel kernel.private slots.private math
 math.private math.order ;
 IN: sequences
 
@@ -358,8 +358,14 @@ PRIVATE>
 
 <PRIVATE
 
+: ((each)) ( seq -- n quot )
+    [ length ] keep [ nth-unsafe ] curry ; inline
+
 : (each) ( seq quot -- n quot' )
-    [ [ length ] keep [ nth-unsafe ] curry ] dip compose ; inline
+    [ ((each)) ] dip compose ; inline
+
+: (each-index) ( seq quot -- n quot' )
+    [ ((each)) [ keep ] curry ] dip compose ; inline
 
 : (collect) ( quot into -- quot' )
     [ [ keep ] dip set-nth-unsafe ] 2curry ; inline
@@ -498,19 +504,18 @@ PRIVATE>
 : follow ( obj quot -- seq )
     [ dup ] swap [ keep ] curry produce nip ; inline
 
-: prepare-index ( seq quot -- seq n quot )
-    [ dup length ] dip ; inline
-
 : each-index ( seq quot -- )
-    prepare-index 2each ; inline
+    (each-index) each-integer ; inline
 
 : interleave ( seq between quot -- )
-    swap [ drop ] [ [ 2dip call ] 2curry ] 2bi
-    [ [ 0 = ] 2dip if ] 2curry
-    each-index ; inline
+    pick empty? [ 3drop ] [
+        [ [ drop first-unsafe ] dip call ]
+        [ [ rest-slice ] 2dip [ bi* ] 2curry each ]
+        3bi
+    ] if ; inline
 
 : map-index ( seq quot -- newseq )
-    prepare-index 2map ; inline
+    [ dup length iota ] dip 2map ; inline
 
 : reduce-index ( seq identity quot -- )
     swapd each-index ; inline
@@ -931,17 +936,3 @@ PRIVATE>
             [ array-flip ] [ generic-flip ] if
         ] [ generic-flip ] if
     ] unless ;
-
-: reduce1 ( seq quot -- result ) [ unclip ] dip reduce ; inline
-
-:: reduce-r
-    ( list identity quot: ( obj1 obj2 -- obj ) -- result )
-    list empty?
-    [ identity ]
-    [ list rest identity quot reduce-r list first quot call ] if ;
-    inline recursive
-
-:: combos ( list1 list2 -- result ) list2 [ [ 2array ] curry list1 swap map ] map concat ;
-: (head-slice) ( seq n -- seq' ) over length over < [ drop ] [ head-slice ] if ;
-: find-all ( seq quot -- elts ) [ [ length iota ] keep ] dip
-    [ dupd call( a -- ? ) [ 2array ] [ 2drop f ] if ] curry 2map [ ] filter ; inline
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 98b8b8d..0bfb607
@@ -6,7 +6,7 @@ sets strings vocabs sorting accessors arrays compiler.units
 combinators vectors splitting continuations math
 parser.notes ;
 IN: vocabs.parser
+
 ERROR: no-word-error name ;
 
 : word-restarts ( possibilities -- restarts )
@@ -17,7 +17,7 @@ ERROR: no-word-error name ;
     word-restarts
     swap "Defer word in current vocabulary" swap 2array
     suffix ;
+
 : <no-word-error> ( name possibilities -- error restarts )
     [ drop \ no-word-error boa ] [ word-restarts-with-defer ] 2bi ;
 
@@ -198,4 +198,4 @@ PRIVATE>
     2dup qualified-search dup [ 2nip ] [ drop vocab-search ] if ;
 
 : search ( name -- word/f )
-    manifest get search-manifest ;
\ No newline at end of file
+    manifest get search-manifest ;
index 0329021f573e62bb8b52d57b37a656ecca1cf52b..adfb7d67de7b7f7e9d0decd747715d04c81ef3ab 100644 (file)
@@ -1,6 +1,7 @@
 USING: accessors arrays delegate delegate.protocols
 io.pathnames kernel locals sequences
-vectors make strings ui.frp.signals ui.frp.gadgets ;
+vectors make strings ui.frp.signals ui.frp.gadgets
+sequences.extras ;
 IN: file-trees
 
 TUPLE: walkable-vector vector father ;
index 6639607a1119c9983dc561f99374ef2dcdd27b7c..f67d0d7cd3ebc28358fcf82df5220aa11416fbb5 100644 (file)
@@ -1,5 +1,5 @@
 USING: arrays vectors combinators effects kernel math sequences splitting
-strings.parser parser fry ;
+strings.parser parser fry sequences.extras ;
 IN: fries
 : str-fry ( str on -- quot ) split
     [ unclip-last [ [ spin glue ] reduce-r ] 2curry ]
index 3fa65d336d9942de5e24593c4196848150dc3cd8..cec82a457d47f79eeaa9025f0c154d8a7b328264 100644 (file)
@@ -1,7 +1,7 @@
 USING: accessors arrays db.tuples db.sqlite persistency db.queries
 io.files.temp kernel monads sequences ui ui.frp.gadgets
 ui.frp.layout ui.frp.signals ui.gadgets.scrollers ui.gadgets.labels
-colors.constants ui.pens.solid combinators math locals strings fries
+colors.constants ui.pens.solid combinators math locals strings
 ui.images db.types ;
 FROM: sets => prune ;
 IN: recipes
@@ -11,7 +11,7 @@ STORED-TUPLE: recipe { title { VARCHAR 100 } } { votes INTEGER } { txt TEXT } {
 : top-recipes ( offset search -- recipes ) <query> T{ recipe } rot >>title >>tuple
     "votes" >>order 30 >>limit swap >>offset get-tuples ;
 : top-genres ( -- genres ) f f top-recipes [ genre>> ] map prune 4 (head-slice) ;
-: <image-button> ( str -- button ) i" vocab:recipes/icons/_.tiff" <image-name> <frp-button> ;
+: <image-button> ( str -- button ) "vocab:recipes/icons/" ".tiff" surround <image-name> <frp-button> ;
 
 : interface ( -- book ) [ 
      [
index cda6a0effa85ea887320b001ad470f461808c6ab..1b3115101389da68f410071b847545d18ffda121 100644 (file)
@@ -1,5 +1,5 @@
 USING: fry functors generalizations kernel macros peg peg-lexer
-sequences ;
+sequences sequences.extras ;
 FROM: ui.frp.signals => #1 ;
 IN: ui.frp.functors
 
index e5dae45b99c0df8e9fd77c584ebdfaf9d988b796..ddcde69eafceebdd9afd09875fa14d14055237ba 100644 (file)
@@ -6,8 +6,9 @@ IN: ui.frp.gadgets
 
 TUPLE: frp-button < button hook value ;
 : <frp-button> ( gadget -- button ) [
+      [ dup hook>> [ call( button -- ) ] [ drop ] if* ]
       [ [ [ value>> ] [ ] bi or ] keep set-control-value ]
-      [ dup hook>> [ call( button -- ) ] [ drop ] if* ] bi
+      [ model>> f swap (>>value) ] tri
    ] frp-button new-button f <basic> >>model ;
 : <frp-border-button> ( text -- button ) <frp-button> border-button-theme ;
 
index e48d477465fb34197d4a9e6f482e9943c768f189..b5389f7bb9cdbf1c0692e1d06b74bb066f004d0d 100644 (file)
@@ -1,4 +1,5 @@
-USING: accessors arrays kernel monads models models.product sequences classes ;
+USING: accessors arrays kernel monads models models.product sequences classes
+sequences.extras ;
 FROM: models.product => product ;
 IN: ui.frp.signals