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

[REBOL] Re: count characters. (Was: Simple things should be simple to do ?)

From: al:bri:xtra at: 16-Nov-2000 21:26

Bard wrote:
> REBOL []
I'd write a bit more stuff in the header.
> count-char: func [ > { > This function counts the number of occurrances of each character in > string str, and returns a printable block with the results. > } > str [string!] > /local count look
Instead of using '/local, I'd use 'function instead of 'func. This is because it makes it clearer what are local variables. It can be easy to mistype and put in "locale" instead. Using 'function makes locals obvious.
> ][ > count: make block! 0 > foreach char str [ > either look: find count char [
I'd use this instead: either found? look: find count char [ This is to help make it clear what you're looking for.
> change (next look) ((second look) + 1) > ][ > append count reduce [char 1 "^/"] > ] > ] > return count > ]
I hope that helps. Andrew Martin Rebol "purist"... ICQ: 26227169 http://members.nbci.com/AndrewMartin/