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 %
] "" make print ;
TUPLE: not-a-decimal ;
: not-a-decimal ( -- * )
T{ not-a-decimal } throw ;
ERROR: not-a-decimal x ;
: parse-decimal ( str -- ratio )
"." split1
>r dup "-" head? [ drop t "0" ] [ f swap ] if r>
[ dup empty? [ drop "0" ] when ] bi@
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 ;
: DECIMAL: