From 15257b91ac4489fd4fe447204bcb3a88b96f28f8 Mon Sep 17 00:00:00 2001 From: Aaron Schaefer Date: Wed, 5 Nov 2008 22:59:06 -0500 Subject: [PATCH] Refactor math.text.english using new combinators --- extra/math/text/english/english.factor | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/extra/math/text/english/english.factor b/extra/math/text/english/english.factor index 439d0a75fe..dfb0c00388 100755 --- a/extra/math/text/english/english.factor +++ b/extra/math/text/english/english.factor @@ -1,7 +1,7 @@ -! Copyright (c) 2007 Aaron Schaefer. +! Copyright (c) 2007, 2008 Aaron Schaefer. ! See http://factorcode.org/license.txt for BSD license. -USING: combinators.lib kernel math math.functions math.parser namespaces -sequences splitting grouping combinators.short-circuit ; +USING: combinators.short-circuit grouping kernel math math.parser namespaces + sequences ; IN: math.text.english text ( n -- str ) - dup hundreds-place swap tens-place append ; + [ hundreds-place ] [ tens-place ] bi append ; : text-with-scale ( index seq -- str ) - dupd nth 3digits>text swap - scale-numbers [ - " " swap 3append - ] unless-empty ; + [ nth 3digits>text ] [ drop scale-numbers ] 2bi + [ " " swap 3append ] unless-empty ; : append-with-conjunction ( str1 str2 -- newstr ) over length zero? [ @@ -68,20 +66,19 @@ SYMBOL: and-needed? and-needed? off ] if ; -: (recombine) ( str index seq -- newstr seq ) +: (recombine) ( str index seq -- newstr ) 2dup nth zero? [ - nip + 2drop ] [ - [ text-with-scale ] keep - -rot append-with-conjunction swap + text-with-scale append-with-conjunction ] if ; : recombine ( seq -- str ) dup length 1 = [ first 3digits>text ] [ - dup set-conjunction "" swap - dup length [ swap (recombine) ] each drop + [ set-conjunction "" ] [ length ] [ ] tri + [ (recombine) ] curry each ] if ; : (number>text) ( n -- str )