tag:blogger.com,1999:blog-2678811648497643881.post5765196369420858513..comments2021-05-02T15:33:44.236-07:00Comments on ColorForth Programming Tutorial: Fall through factoringjohnmdrakehttp://www.blogger.com/profile/08149380469759920889noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-2678811648497643881.post-26005441087172848762009-06-21T15:40:55.536-07:002009-06-21T15:40:55.536-07:00Hello David,
First I should point out that the &q...Hello David,<br /><br />First I should point out that the "yards - feet" example came from Starting Forth at the "8*" example came from Jeff Fox. So I'm simply using them as opposed to showing code from an actual application.<br /><br />That said, it all depends on your application. If I had an interactive calculator that I needed to make quick conversions I would need those conversions to happen at run time rather than compile time.<br /><br />Also I think it's important to distinguish between immediate code (yellow words) and inline code (words defined in the macro vocabulary with cyan instead of green compile words). Inline words run at runtime, but without the call overhead. Immediate words run at compile time. If you needed the ability to do conversions at run time you couldn't do it with immediate words and its difficult (though not impossible) to handle literals with cyan words.johnmdrakehttps://www.blogger.com/profile/08149380469759920889noreply@blogger.comtag:blogger.com,1999:blog-2678811648497643881.post-53495826440028035832009-06-20T12:06:37.387-07:002009-06-20T12:06:37.387-07:00In most applications, this sort of unit conversion...In most applications, this sort of unit conversion would be done as a compile time application, and not done at run time. These words would better be run as macros (aka immediate words).David J. Göhrighttps://www.blogger.com/profile/15912680537654316499noreply@blogger.comtag:blogger.com,1999:blog-2678811648497643881.post-23065961338478075322009-06-18T09:38:24.865-07:002009-06-18T09:38:24.865-07:00Yes you could do that. But you would take 1 multi...Yes you could do that. But you would take 1 multiplication for yards and make it 2. Depending on what you're doing that could significantly slow down your code. Fall through factoring shouldn't do that IMO.<br /><br />From my first example I'd rather do:<br /><br />4* 2 shl ;<br />8* 3 shl ;<br /><br />but ColorForth doesn't directly support shifting more than one bit at a time. (It's easy enough to add.)johnmdrakehttps://www.blogger.com/profile/08149380469759920889noreply@blogger.comtag:blogger.com,1999:blog-2678811648497643881.post-74694090227753382852009-06-18T08:16:10.442-07:002009-06-18T08:16:10.442-07:00In your second example of fall through factoring y...In your second example of fall through factoring you should have combined each concept and produced:<br><br /><i>yards</i><br><br /><i>yard</i><b> 3 *</b><br><br /><i>feet</i><br><br /><i>foot</i><b> 12 * ;</b><br><br /><br><br />This produces the same result, and factors out the 12 common to both 12 and 36. Aka classic factoring :)David J. Göhrighttps://www.blogger.com/profile/15912680537654316499noreply@blogger.com