[REBOL] Re: byte frequencies
From: joel:neely:fedex at: 5-Jul-2001 20:25
Hi, Larry,
Good comments all; thanks!
Larry Palmiter wrote:
> bytefreq2: func [fi [file!] /local ft cnt] [
> ft: array/initial 256 0
> foreach ch read fi [
> ch: 1 + ch
> poke ft ch 1 + pick ft ch
> ]
> repeat ch length? ft [
> if 0 < cnt: pick ft ch [
> print [mold to-char ch - 1 tab cnt]
> ]
> ]
> ]
>
Nice!
> TO-FILE is superfluous because fi was declared as file! in
> the function spec.
>
I originally had
func [fi [file! string!] ...
and forgot to remove TO-FILE when I pruned the types. Silly
of me not to have cleaned out the leftovers!
> I added CNT as a local variable, but we could also have used
> the variable LOCAL if we wished to avoid declaring another
> local at the expense of readability.
>
I certainly think readability is The Right Thing, especially
when the potential "savings" from sacrificing it are so small!
> ... the reader should note that when adding characters and
> integers, the result is order dependent:
>
Right, which is why I chose the order I did. I suppose this
is another of those cases where an inconsistency occurred in
favor of anticipated use, given that
>> type? 1 + 1.0 ;== decimal!
>> type? 1.0 + 1 ;== decimal!
Thanks for the helpful feedback!
-jn-
--
------------------------------------------------------------
Programming languages: compact, powerful, simple ...
Pick any two!
joel'dot'neely'at'fedex'dot'com