1 USING: io kernel math math.functions math.parser parser lexer
2 namespaces sequences splitting grouping combinators
3 continuations sequences.lib ;
6 : dollars/cents ( dollars -- dollars cents )
9 : money>string ( object -- string )
13 <reversed> 3 group "," join <reversed> %
14 "." % number>string 2 CHAR: 0 pad-left %
17 : money. ( object -- )
20 ERROR: not-a-decimal x ;
22 : parse-decimal ( str -- ratio )
24 >r dup "-" head? [ drop t "0" ] [ f swap ] if r>
25 [ [ "0" ] when-empty ] bi@
27 >r [ dup string>number [ nip ] [ not-a-decimal ] if* ] bi@ r>
28 10 swap ^ / + swap [ neg ] when ;
31 scan parse-decimal parsed ; parsing