Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Translate this code into real Rebol?

From: rotenca:telvia:it at: 24-Jan-2002 17:07

> It's typical of the sort of code I knock out in a hurry--in this case for
the
> prototype I mention in an earlier post. It works, but it could almost be > Basic. Is there a more Rebolish (Rebellious? Rebvolting?) way of doing this? > > rebol [] > > Pretty-print-number: func [in-amount [Money! Integer! Decimal!]
This is my try (i do not if it is more ...anything, only sure that it uses parse :-) Note: The var 'tho-any keeps the number of digits before the thousands separator. Should not be difficult to change it to output a fixed number of decimal also for integer! and decimal!. REBOL [] context [ dec: #"." tho: #"," tho-any: 3 cur: #"" out: "" emit: func[x][insert tail out x] digit: make bitset! "0123456789" y: ism: none rule: [ [copy y some digit "." (emit y emit dec) | (if is-m [emit "00" emit dec])] copy y 1 tho-any digit (emit y) any [copy y 1 tho-any digit (emit tho emit y)] opt [#"$" (emit cur)] opt [#"-" (emit #"-")] ] do [ pretty-print-number: func [ x [Money! Integer! Decimal!] /brackets ][ is-m: money? x clear out x: form x reverse x parse/all x rule reverse out print either all [brackets #"-" = first out][ join replace out "-" "(" ")" ][ out ] ] ] ] --- Ciao Romano