Re: [Re: [colorforth] Dare I say ANS!]
- Subject: Re: [Re: [colorforth] Dare I say ANS!]
- From: "Samuel A. Falvo II" <kc5tja@xxxxxxxx>
- Date: Thu, 15 Jan 2004 13:36:17 -0800
On Thursday 15 January 2004 01:41 pm, Jeffrey Massung wrote:
> FOR .. NEXT counts down from N to 0. Think of it like this:
> : FOR ( -- a a ) (BEGIN) POSTPONE 1- (IF) SWAP ; IMMEDIATE
> : NEXT ( a a -- ) (AGAIN) (THEN) ; IMMEDIATE
This code isn't quite correct. FOR places the loop counter on the return
stack, not on the data stack. Hence the necessity for 'i', which is
just R@ in disguise (at least in ANSI Forth). 'i' could also be
implemented as reading from ECX directly in ColorForth as well.
I personally don't know, since I (a) don't use ColorForth often enough,
and (b) generally avoid such loops, choosing instead to use BEGIN/AGAIN
or their ColorForth-equivalent loops.
And, frankly, I'm currently investigating various vector techniques, as
used in APL and K, as opportunities to hide away the loops all-together,
thus making code vastly more maintainable. Not that I'm intending on
making this stuff part of the core Forth kernel, but as used in my
applications, loops are a major contributing factor to difficulty in
maintaining the code.
--
Samuel A. Falvo II
---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com