On Sep 23, 6:42 pm, "Ed" <
inva...@nospam.com> wrote:
> Which doesn't rule out the usefulness of the simpler routine.
>
> Making things run faster often comes at the cost of more code.
> Whether it is justified will depend on the situation. Not every
> application needs arrays which run at the maximum possible
> speed. Factor in all the other things a program must do and
> array speed may become insignificant. Selecting a routine
> appropriate to the application is good economics.
I like your definer. I don't know if it is "Ninja Forth," but it is
definitely black-belt Forth (maybe shodan). With your permission I
will include it in the next novice-package release (with an attribute
of course) --- I've already got two ways to define arrays, so three
would be okay.
With low-level fundamental support code such as an array definer, I
will put in a lot of effort to make it fast. In many cases arrays may
be the crux of the program, and their speed the time-critical aspect
of the program.
With code that is not used much, you are right that simplicity out-
weighs efficiency. You can get the program running first, and only
worry about the performance later on if the program is too slow.
Considering how fast modern computers are, speed is not going to be an
issue very often.
I remember when I was a teenager one of my first Forth programs was a
port of a BASIC program from a book. It was a simulation of a simple
ecosystem with predators and prey. The prey moved around randomly at
first, but they could "learn" to avoid getting eaten. There was an 8
dimensional array. The 8 dimensions represented the 8 adjacent
squares. When they succeeded in not getting eaten, they would remember
what their environment looked like at the time (what was adjacent to
them) and what they did to live (which direction they moved), and they
would do the same thing again. Because the predators moved according
to fixed rules, some of the prey would "learn" a pattern to travel in
which they were guaranteed to live, although most of them would get
eaten before they figured this out. That program definitely needed
fast arrays! The advantage of Forth over BASIC was that I could make
the arrays fast. I think I made sure the multiplications were powers
of two and could be done by shifting, to avoid integer multiplication
which was horribly slow on the 6502 --- I don't remember the details
very well --- that was a long time ago.
Back in the 1980s, there were books and magazines with programs like
this. Not very useful, but quite fun. We don't see this kind of
programming anymore. Nowadays programming is dull dull dull. :-( I
mean, really, who thinks that building websites is fun? But that is
what almost everybody is doing.
> I welcome your faster array routine. The more routines available
> to Forth users, the better off Forth will be.
I definitely agree with that. I would really like to see a lot more
Forth code made available. I think that novices feel overwhelmed when
they start learning Forth, because they have to implement so much low-
level stuff themselves before they can even begin to write
applications. If you tell a novice that he has to implement an array
definer, he is going to leave and not come back. They need to have fun
with the language first --- and the way to have fun is to write
programs that do something interesting. :-)