]> gitweb.factorcode.org Git - factor.git/commitdiff
spelling: minor cleanup.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 31 Oct 2019 21:55:47 +0000 (14:55 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 31 Oct 2019 21:55:47 +0000 (14:55 -0700)
extra/spelling/spelling.factor

index 78e5b20a310005a9dffce418a9d0a27610fd9057..2ade0d1bbe33820315cb2c5be54c1bdcacc60121 100644 (file)
@@ -1,7 +1,9 @@
+! Copyright (C) 2010 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
 USING: arrays ascii assocs combinators combinators.smart fry
 http.client io.encodings.ascii io.files io.files.temp kernel
-literals locals math math.ranges math.statistics memoize
-sequences sequences.private sets sorting splitting strings urls ;
+locals math math.ranges math.statistics memoize sequences
+sequences.private sorting splitting urls ;
 IN: spelling
 
 ! http://norvig.com/spell-correct.html
@@ -12,23 +14,19 @@ CONSTANT: ALPHABET "abcdefghijklmnopqrstuvwxyz"
     [ length <iota> ] keep '[ _ remove-nth ] map ;
 
 : transposes ( word -- edits )
-    [ length [1,b) ] keep '[
-        dup 1 - _ clone [ exchange-unsafe ] keep
-    ] map ;
+    [ length [1,b) ] keep
+    '[ dup 1 - _ clone [ exchange-unsafe ] keep ] map ;
+
+: replace1 ( i word -- words )
+    [ ALPHABET ] 2dip bounds-check
+    '[ _ _ clone [ set-nth-unsafe ] keep ] { } map-as ;
 
 : replaces ( word -- edits )
-    [ length <iota> ] keep '[
-        ALPHABET [
-            swap _ clone [ set-nth-unsafe ] keep
-        ] with { } map-as
-    ] map concat ;
+    [ length <iota> ] keep '[ _ replace1 ] map concat ;
 
 : inserts ( word -- edits )
-    [ length [0,b] ] keep '[
-        CHAR: ? over _ insert-nth ALPHABET swap [
-            swapd clone [ set-nth-unsafe ] keep
-        ] curry with { } map-as
-    ] map concat ;
+    [ length [0,b] ] keep
+    '[ CHAR: ? over _ insert-nth replace1 ] map concat ;
 
 : edits1 ( word -- edits )
     [