]> gitweb.factorcode.org Git - factor.git/commitdiff
Fix conflict
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 2 Feb 2009 12:07:59 +0000 (06:07 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 2 Feb 2009 12:07:59 +0000 (06:07 -0600)
15 files changed:
basis/alien/structs/structs.factor
basis/biassocs/biassocs-docs.factor
basis/compiler/tree/normalization/introductions/introductions.factor
basis/compiler/tree/normalization/normalization.factor
basis/stack-checker/branches/branches.factor
basis/tools/disassembler/udis/udis.factor
basis/wrap/wrap-tests.factor [new file with mode: 0644]
basis/wrap/wrap.factor
basis/xml/writer/writer.factor
extra/project-euler/008/008.factor
extra/project-euler/011/011.factor
extra/project-euler/044/044.factor
extra/project-euler/056/056.factor
extra/sequences/modified/modified.factor
extra/tetris/tetromino/tetromino.factor

index a3c616cda2d8dee7f4d162357af8ead626e8f23c..42923fb28bbe475565eb7097479f701cb3a7b22b 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays generic hashtables kernel kernel.private
 math namespaces parser sequences strings words libc fry
-alien.c-types alien.structs.fields cpu.architecture ;
+alien.c-types alien.structs.fields cpu.architecture math.order ;
 IN: alien.structs
 
 TUPLE: struct-type size align fields ;
@@ -47,7 +47,7 @@ M: struct-type stack-size
     [ first2 <field-spec> ] with with map ;
 
 : compute-struct-align ( types -- n )
-    [ c-type-align ] map supremum ;
+    [ c-type-align ] [ max ] map-reduce ;
 
 : define-struct ( name vocab fields -- )
     [
@@ -59,5 +59,5 @@ M: struct-type stack-size
 
 : define-union ( name members -- )
     [ expand-constants ] map
-    [ [ heap-size ] map supremum ] keep
+    [ [ heap-size ] [ max ] map-reduce ] keep
     compute-struct-align f (define-struct) ;
index 31258a7ddc1e847d15e203a719486b5acdfe5815..b55af5b902ca76cbe2a826da40d4590263c555b2 100644 (file)
@@ -23,7 +23,7 @@ HELP: >biassoc
 ARTICLE: "biassocs" "Bidirectional assocs"
 "A " { $emphasis "bidirectional assoc" } " combines a pair of assocs to form a data structure where both normal assoc opeartions (eg, " { $link at } "), as well as " { $link "assocs-values" } " (eg, " { $link value-at } ") run in sub-linear time."
 $nl
-"Bidirectional assocs implement the entire " { $link "assoc-protocol" } " with the exception of " { $link delete-at } ". Duplicate values are allowed, however value lookups with " { $link value-at } " only return the first key that a given value was stored with."
+"Bidirectional assocs implement the entire " { $link "assocs-protocol" } " with the exception of " { $link delete-at } ". Duplicate values are allowed, however value lookups with " { $link value-at } " only return the first key that a given value was stored with."
 $nl
 "The class of biassocs:"
 { $subsection biassoc }
index 9e96dc0472846dcd1018492d3fc267160cec9653..743b8c56da8827dc050a06a988937f03c645f1b1 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: namespaces sequences accessors math kernel
-compiler.tree ;
+compiler.tree math.order ;
 IN: compiler.tree.normalization.introductions
 
 SYMBOL: introductions
@@ -25,7 +25,7 @@ M: #introduce count-introductions*
 
 M: #branch count-introductions*
     children>>
-    [ count-introductions ] map supremum
+    [ count-introductions ] [ max ] map-reduce
     introductions+ ;
 
 M: #recursive count-introductions*
index 3f1e9e2667ee08016a9f66b4e5b99ce7bdff77d9..ee7bf8672e2515d8d5cf44509faacb77fc644633 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: fry namespaces sequences math accessors kernel arrays
+USING: fry namespaces sequences math math.order accessors kernel arrays
 combinators compiler.utilities assocs
 stack-checker.backend
 stack-checker.branches
@@ -54,7 +54,7 @@ M: #branch normalize*
         ] map unzip swap
     ] change-children swap
     [ remaining-introductions set ]
-    [ [ length ] map infimum introduction-stack [ swap head ] change ]
+    [ [ length ] [ min ] map-reduce introduction-stack [ swap head ] change ]
     bi ;
 
 : eliminate-phi-introductions ( introductions seq terminated -- seq' )
index 2eb4fb46a9f0ab2f6e67e7302fa210fc1ae346eb..690af39c28cc2bf645b7859073f5f587a893fb16 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: fry vectors sequences assocs math accessors kernel
+USING: fry vectors sequences assocs math math.order accessors kernel
 combinators quotations namespaces grouping stack-checker.state
 stack-checker.backend stack-checker.errors stack-checker.visitor
 stack-checker.values stack-checker.recursive-state ;
@@ -16,7 +16,7 @@ SYMBOL: +bottom+
 
 : pad-with-bottom ( seq -- newseq )
     dup empty? [
-        dup [ length ] map supremum
+        dup [ length ] [ max ] map-reduce
         '[ _ +bottom+ pad-head ] map
     ] unless ;
 
index cb52b1d5dbf80f611db285773bd464328c734375..cfa2483c7e7e50f24bbab5a5ae1aea0d06f968d4 100644 (file)
@@ -2,7 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: tools.disassembler namespaces combinators
 alien alien.syntax alien.c-types lexer parser kernel
-sequences layouts math math.parser system make fry arrays ;
+sequences layouts math math.order
+math.parser system make fry arrays ;
 IN: tools.disassembler.udis
 
 <<
@@ -56,7 +57,7 @@ SINGLETON: udis-disassembler
 : buf/len ( from to -- buf len ) [ drop <alien> ] [ swap - ] 2bi ;
 
 : format-disassembly ( lines -- lines' )
-    dup [ second length ] map supremum
+    dup [ second length ] [ max ] map-reduce
     '[
         [
             [ first >hex cell 2 * CHAR: 0 pad-head % ": " % ]
diff --git a/basis/wrap/wrap-tests.factor b/basis/wrap/wrap-tests.factor
new file mode 100644 (file)
index 0000000..b2d1876
--- /dev/null
@@ -0,0 +1,48 @@
+IN: wrap.tests
+USING: tools.test wrap multiline sequences ;
+    
+[
+    {
+        {
+            T{ word f 1 10 f }
+            T{ word f 2 10 f }
+            T{ word f 3 2 t }
+        }
+        {
+            T{ word f 4 10 f }
+            T{ word f 5 10 f }
+        }
+    }
+] [
+    {
+        T{ word f 1 10 f }
+        T{ word f 2 10 f }
+        T{ word f 3 2 t }
+        T{ word f 4 10 f }
+        T{ word f 5 10 f }
+    } 35 wrap [ { } like ] map
+] unit-test
+
+[
+    <" This is a
+long piece
+of text
+that we
+wish to
+word wrap.">
+] [
+    <" This is a long piece of text that we wish to word wrap."> 10
+    wrap-string
+] unit-test
+    
+[
+    <"   This is a
+  long piece
+  of text
+  that we
+  wish to
+  word wrap.">
+] [
+    <" This is a long piece of text that we wish to word wrap."> 12
+    "  " wrap-indented-string
+] unit-test
\ No newline at end of file
index 87a870d75d771421e6abdf58bfdf1dbf2eb2809c..8e4e2753a866d423e46bd8535036bdd9db9d252f 100644 (file)
@@ -1,32 +1,60 @@
-USING: sequences kernel namespaces make splitting math math.order ;
+USING: sequences kernel namespaces make splitting
+math math.order fry assocs accessors ;
 IN: wrap
 
-! Very stupid word wrapping/line breaking
-! This will be replaced by a Unicode-aware method,
-! which works with variable-width fonts
+! Word wrapping/line breaking -- not Unicode-aware
+
+TUPLE: word key width break? ;
+
+C: <word> word
+
+<PRIVATE
 
 SYMBOL: width
 
-: line-chunks ( string -- words-lines )
-    "\n" split [ " \t" split harvest ] map ;
+: break-here? ( column word -- ? )
+    break?>> not [ width get > ] [ drop f ] if ;
+
+: find-optimal-break ( words -- n )
+    [ 0 ] dip [ [ width>> + dup ] keep break-here? ] find drop nip ;
 
-: (split-chunk) ( words -- )
-    -1 over [ length + 1+ dup width get > ] find drop nip
-    [ 1 max cut-slice swap , (split-chunk) ] [ , ] if* ;
+: (wrap) ( words -- )
+    dup find-optimal-break
+    [ 1 max cut-slice [ , ] [ (wrap) ] bi* ] [ , ] if* ;
 
-: split-chunk ( words -- lines )
-    [ (split-chunk) ] { } make ;
+: intersperse ( seq elt -- seq' )
+    [ '[ _ , ] [ , ] interleave ] { } make ;
 
-: join-spaces ( words-seqs -- lines )
-    [ [ " " join ] map ] map concat ;
+: split-lines ( string -- words-lines )
+    string-lines [
+        " \t" split harvest
+        [ dup length f <word> ] map
+        " " 1 t <word> intersperse
+    ] map ;
 
-: broken-lines ( string width -- lines )
+: join-words ( wrapped-lines -- lines )
+    [
+        [ break?>> ]
+        [ trim-head-slice ]
+        [ trim-tail-slice ] bi
+        [ key>> ] map concat
+    ] map ;
+
+: join-lines ( strings -- string )
+    "\n" join ;
+
+PRIVATE>
+
+: wrap ( words width -- lines )
     width [
-        line-chunks [ split-chunk ] map join-spaces
+        [ (wrap) ] { } make
     ] with-variable ;
 
-: line-break ( string width -- newstring )
-    broken-lines "\n" join ;
+: wrap-lines ( lines width -- newlines )
+    [ split-lines ] dip '[ _ wrap join-words ] map concat ;
+
+: wrap-string ( string width -- newstring )
+    wrap-lines join-lines ;
 
-: indented-break ( string width indent -- newstring )
-    [ length - broken-lines ] keep [ prepend ] curry map "\n" join ;
+: wrap-indented-string ( string width indent -- newstring )
+    [ length - wrap-lines ] keep '[ _ prepend ] map join-lines ;
index 146e67e70f77d989fe4d3e9f71e167fdc9f3ee6f..a713790973282a7566c230107979210affb17940 100755 (executable)
@@ -69,7 +69,7 @@ M: string write-xml
     escape-string xml-pprint? get [\r
         dup [ blank? ] all?\r
         [ drop "" ]\r
-        [ nl 80 indent-string indented-break ] if\r
+        [ nl 80 indent-string wrap-indented-string ] if\r
     ] when write ;\r
 \r
 : write-tag ( tag -- )\r
index 24ccbb443a8bdb83d4b2b3a844366ed5fe2f4a04..1e8dade646d603ff2460d6c879ba7572f8b2889c 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: grouping math.parser sequences ;
+USING: grouping math.order math.parser sequences ;
 IN: project-euler.008
 
 ! http://projecteuler.net/index.php?section=problems&id=8
@@ -64,7 +64,7 @@ IN: project-euler.008
 PRIVATE>
 
 : euler008 ( -- answer )
-    source-008 5 clump [ string>digits product ] map supremum ;
+    source-008 5 clump [ string>digits product ] [ max ] map-reduce ;
 
 ! [ euler008 ] 100 ave-time
 ! 2 ms ave run time - 0.79 SD (100 trials)
index 094069572684b34e1944549d14ea78a557cdac34..122eec2c2e6904c1dfc6a9cf7fb38b98e0d6aea0 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: grouping kernel make sequences ;
+USING: grouping kernel make math.order sequences ;
 IN: project-euler.011
 
 ! http://projecteuler.net/index.php?section=problems&id=11
@@ -88,7 +88,7 @@ IN: project-euler.011
 
 : max-product ( matrix width -- n )
     [ clump ] curry map concat
-    [ product ] map supremum ; inline
+    [ product ] [ max ] map-reduce ; inline
 
 PRIVATE>
 
index e7b1959023840c568115257eafa17113da454b60..46b20253ee48392458b80a3c2f63e88dcbe6a9e5 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions math.ranges project-euler.common sequences ;
+USING: kernel math math.functions math.ranges math.order
+project-euler.common sequences ;
 IN: project-euler.044
 
 ! http://projecteuler.net/index.php?section=problems&id=44
@@ -37,7 +38,7 @@ PRIVATE>
 
 : euler044 ( -- answer )
     2500 [1,b] [ nth-pentagonal ] map dup cartesian-product
-    [ first2 sum-and-diff? ] filter [ first2 - abs ] map infimum ;
+    [ first2 sum-and-diff? ] filter [ first2 - abs ] [ min ] map-reduce ;
 
 ! [ euler044 ] 10 ave-time
 ! 4996 ms ave run time - 87.46 SD (10 trials)
index 34626b796d8de38d202b2dc184f9f420755917e3..4e7bbdc0df1979c417e5ff8d8af7262968fbcb1e 100644 (file)
@@ -23,7 +23,7 @@ IN: project-euler.056
 
 : euler056 ( -- answer )
     90 100 [a,b) dup cartesian-product
-    [ first2 ^ number>digits sum ] map supremum ;
+    [ first2 ^ number>digits sum ] [ max ] map-reduce ;
 
 ! [ euler056 ] 100 ave-time
 ! 22 ms ave run time - 2.13 SD (100 trials)
index 3e4c1b1bdc3d14719d80acba9a295e1544f91ec1..d552f2dc77a9ede9af6930d911df60a5a9146eb4 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2008 Alex Chapman
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays kernel math sequences sequences.private shuffle ;
+USING: accessors arrays kernel math math.order
+sequences sequences.private shuffle ;
 IN: sequences.modified
 
 TUPLE: modified ;
@@ -50,7 +51,7 @@ M: offset modified-set-nth ( elt n seq -- )
 TUPLE: summed < modified seqs ;
 C: <summed> summed
 
-M: summed length seqs>> [ length ] map supremum ;
+M: summed length seqs>> [ length ] [ max ] map-reduce ;
 
 <PRIVATE
 : ?+ ( x/f y/f -- sum )
index 7e6b2ecf341943555e300101986b9b4cae689d76..127e4854e0d569a8bd5292e6fe76d38ab594fb41 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2006, 2007, 2008 Alex Chapman
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel arrays namespaces sequences math math.vectors
-colors random ;
+USING: kernel arrays namespaces sequences math math.order
+math.vectors colors random ;
 IN: tetris.tetromino
 
 TUPLE: tetromino states colour ;
@@ -104,7 +104,7 @@ SYMBOL: tetrominoes
     tetrominoes get random ;
 
 : blocks-max ( blocks quot -- max )
-    map [ 1+ ] map supremum ; inline
+    map [ 1+ ] [ max ] map-reduce ; inline
 
 : blocks-width ( blocks -- width )
     [ first ] blocks-max ;