]> gitweb.factorcode.org Git - factor.git/commitdiff
format-using: factor out some repeated code
authorAlexander Ilin <alex.ilin@protonmail.com>
Sun, 13 Aug 2023 11:36:12 +0000 (13:36 +0200)
committerAlexander Ilin <alex.ilin@protonmail.com>
Sun, 13 Aug 2023 12:08:29 +0000 (14:08 +0200)
extra/format-using/format-using.factor

index 4b685a3110c3011a9506bb877b1846da68737310..b7af761f950e215394d7969ef2b468d2ee0c1862 100644 (file)
@@ -18,8 +18,11 @@ IN: format-using
 : subsystem-clusters ( seq -- seq' )
     [ subsystem= ] monotonic-split ;
 
+: joined-length ( seq -- n )
+    [ length ] keep [ length ] map-sum + ;
+
 : costs ( vocabs -- length-on-new-line length-when-added-to-prev-line )
-    [ length 1 - ] keep [ length ] map-sum + [ indent length + ] [ 1 + ] bi ;
+    joined-length [ indent length + 1 - ] keep ;
 
 : sum-too-long? ( cost1 cost2 -- ? )
     [ first ] [ second ] bi* + too-long? ;
@@ -53,7 +56,7 @@ IN: format-using
     split-long-subsystems [ last " " join indent prepend ] map ;
 
 : oneliner-length ( vocabs -- n )
-    [ length ] keep [ length ] map-sum + "USING: ;" length + ;
+    joined-length "USING: ;" length + ;
 
 : format-using ( vocabs -- str )
     dup length 1 = [ first "USE: " prepend ] [