 : >ROMAN ( n -- str ) >roman >upper ;
 
 : roman> ( str -- n )
-    >lower [ roman>= ] monotonic-split [ (roman>) ] map-sum ;
+    >lower [ roman-digit>= ] monotonic-split
+    [ roman-value ] map-sum ;
 
 <PRIVATE
 

: roman-digit-index ( ch -- n )
    1string roman-digits index ; inline

: roman>= ( ch1 ch2 -- ? )
    [ roman-digit-index ] bi@ >= ;

: roman>n ( ch -- n )
    roman-digit-index roman-values nth ;

: (roman>) ( seq -- n )
    [ [ roman>n ] map ] [ all-eq? ] bi
    [ sum ] [ first2 swap - ] if ;

PRIVATE>

! Copyright (C) 2007 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors combinators.smart effects.parser fry
generalizations grouping kernel lexer macros math math.order
parser quotations sequences splitting.monotonic strings unicode
words ;
IN: roman

<PRIVATE
