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

[REBOL] latest utility function

From: jelinem1::nationwide::com at: 11-May-2001 13:34

My latest utility function: To insert commas into a number (how many of us already have one of these?). It uses my version of 'rejoin, which is enhanced with the /with refinement (how many of us have already done this?). Currently only works with integers. If the use of commas offends you (for non-USA people) substitute the character appropriate to your country. ; ---------------------------------------------------------------------- comma-ize: function [ "Insert commas into a number" some-num [string! integer!] ][digit b str here there][ digit: charset "1234567890" b: make block! 10 reverse str: to-string some-num parse str [any [here: 1 3 digit there: (append b copy/part :here :there)]] head reverse str: rejoin/with b #"," ] ; ---------------------------------------------------------------------- rejoin: func [ "Reduces and joins a block of values - allows /with refinement." block [block!] "Values to reduce and join" /with join-thing "Value to place in between each element" ][ block: reduce block if with [ while [not tail? block: next block][insert block join-thing block: next block] block: head block ] append either series? first block [copy first block] [form first block] next block ] ; ----------------------------------------------------------------------
>> comma-ize 12345678
== "12,345,678" - Michael Jelinek