[colorforth] Question regarding if
- Subject: [colorforth] Question regarding if
- From: Mark Slicker <maslicke@xxxxxxxxxxx>
- Date: Sat, 13 Jul 2002 14:32:46 -0400 (EDT)
On Sat, 13 Jul 2002, Richard Collins wrote:
> Alex Thiel wrote:
> > I want to write a word that test the TOS for a non-zero value. I have tried
>
> I was getting really confused by this so I sacrificed some efficiency
> for some clarity.
>
> I have renamed 'if' to 'ifnz' to reflect the way it behaves.
> I have defined 'if' as the macro:
> (red) if (cyan) 0 + drop ifnz (green) ;
>
> So 'if' now works like it does in regular forths, where it's behaviour
> is determined by the TOS, which is then discarded.
>
I'm not sure the advantage of either style, for this some analysis of
colorForth code is required.
For comparison here is how one might define your words using the
colorForth 'if':
: gteq swap
: lteq 1 +
: lt less drop drop ;
: gt swap lt ;
: eq or drop ;
It is interesting that colorForth provides so few comparison operators
(none in the machine version), and also only primitive shift operations
(2* 2/). I think there is a lot of refinement going on here, both at the
machine level and language level. Trying to find the optimal set of
operators. A smaller vocabulary can make a language much easier to learn,
and also alows an application to define operators optimized for the
problem.
I for one, define arbritary shifting operators frequently. It is for
efficienty that I define these. If these were needed in every single
application, then it might make sense to include them in the core
language. But there is not a great burden in including them in an
application.
The 'drop' included with 'if' is debatable. A non-drop 'if' is suposedly
more efficient at the hardware level. However, it would be interesting to
know how often the pattern 'drop if' occurs in colorForth code.
Mark
------------------------
To Unsubscribe from this list, send mail to Mdaemon@xxxxxxxxxxxxxxxxxx with:
unsubscribe ColorForth
as the first and only line within the message body
Problems - List-Admin@xxxxxxxxxxxxxxxxxx
Main ColorForth site - http://www.colorforth.com
Wiki page http://kristopherjohnson.net/wiki/ColorForth
ColorForth index http://www.users.qwest.net/~loveall/c4index.htm