better error reporting for DECIMAL:

db4
erg 2008-05-20 10:17:34 -05:00
parent 7e4a34ca3e
commit 73352a3437
1 changed files with 2 additions and 5 deletions

View File

@ -15,17 +15,14 @@ IN: money
"." % number>string 2 CHAR: 0 pad-left % "." % number>string 2 CHAR: 0 pad-left %
] "" make print ; ] "" make print ;
TUPLE: not-a-decimal ; ERROR: not-a-decimal x ;
: not-a-decimal ( -- * )
T{ not-a-decimal } throw ;
: parse-decimal ( str -- ratio ) : parse-decimal ( str -- ratio )
"." split1 "." split1
>r dup "-" head? [ drop t "0" ] [ f swap ] if r> >r dup "-" head? [ drop t "0" ] [ f swap ] if r>
[ dup empty? [ drop "0" ] when ] bi@ [ dup empty? [ drop "0" ] when ] bi@
dup length dup length
>r [ string>number dup [ not-a-decimal ] unless ] bi@ r> >r [ dup string>number [ nip ] [ not-a-decimal ] if* ] bi@ r>
10 swap ^ / + swap [ neg ] when ; 10 swap ^ / + swap [ neg ] when ;
: DECIMAL: : DECIMAL: