modernize extra/roman
parent
aa8c85f010
commit
c876388e6a
|
@ -1,26 +1,20 @@
|
|||
! Copyright (C) 2007 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
|
||||
USING: arrays assocs kernel math math.order math.vectors namespaces
|
||||
quotations sequences sequences.lib sequences.private strings unicode.case ;
|
||||
IN: roman
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: roman-digits ( -- seq )
|
||||
{ "m" "cm" "d" "cd" "c" "xc" "l" "xl" "x" "ix" "v" "iv" "i" } ;
|
||||
|
||||
: roman-values ( -- seq )
|
||||
{ 1000 900 500 400 100 90 50 40 10 9 5 4 1 } ;
|
||||
|
||||
TUPLE: roman-range-error n ;
|
||||
ERROR: roman-range-error n ;
|
||||
|
||||
: roman-range-check ( n -- )
|
||||
dup 1 3999 between? [
|
||||
drop
|
||||
] [
|
||||
roman-range-error boa throw
|
||||
] if ;
|
||||
dup 1 3999 between? [ drop ] [ roman-range-error ] if ;
|
||||
|
||||
: roman<= ( ch1 ch2 -- ? )
|
||||
[ 1string roman-digits index ] bi@ >= ;
|
||||
|
@ -39,7 +33,6 @@ TUPLE: roman-range-error n ;
|
|||
] [
|
||||
first2 swap -
|
||||
] if ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: >roman ( n -- str )
|
||||
|
@ -55,13 +48,11 @@ PRIVATE>
|
|||
] map sum ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: 2roman> ( str1 str2 -- m n )
|
||||
[ roman> ] bi@ ;
|
||||
|
||||
: binary-roman-op ( str1 str2 quot -- str3 )
|
||||
>r 2roman> r> call >roman ; inline
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: roman+ ( str1 str2 -- str3 )
|
||||
|
|
Loading…
Reference in New Issue