Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Re: A Brief Loo...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 3936 of 4288
Post > Topic >>

Re: A Brief Look at History

by Jonah Thomas <jethomas5@[EMAIL PROTECTED] > Mar 20, 2008 at 07:24 AM

Andrew Haley <andrew29@[EMAIL PROTECTED]
> wrote:
> Doug Hoffman <no.spam> wrote:

> > Anyway.  Bottom Line.  *If* we are interested in attracting newbies
> > to Forth, I maintain that BOX2 is going to be far more effective
> > than DRAW-BOX.  I believe that DRAW-BOX, or anything like it, will
> > send newbies running to look for a different language.  BOX2 has a
> > good chance of attracting new programmers to Forth. *In my opinion*.
> 
> Why would it doi so?  It's just the same as
> 
> void box2 (int l, int t, int r, int b)
> {
>   line (l, t, r, b);
>   line (r, t, r, b);
>   line (r, b, l, b);
>   line (l, b, l, t);
> }

I remember once a long time ago somebody put up a challenge here to find
a good solution for this exact same problem. And a large handful of
prominent clf posters were all having a bad day together and came up
with various unsatisfactory solutions until somebody (you?) came up with
your solution. I vaguely remember them saying it was in Thinking Forth. 

If we have a simple obvious problem (draw a box) and it takes somebody
with a lot of insight to come up with the good solution, that isn't good
for Forth. It isn't good if you have to come up with tricky insights to
solve simple problems. But locals give you a no-brainer. Lots of stack
problems just go away. The stack is a problem for Forth because with
Forth people have to solve stack problems and with C they don't. Locals
let us play catch-up with C for that. They don't make Forth better than
C, but at least in that particular area Forth is not worse.

Since the line-drawing didn't show something that couldn't be done
adequately without locals, I will give another hypothetical challenge to
do that.

Imagine that we have six routines that are called from a C library.
These routines have the following stack diagrams:

DO-SOMETHING ( ac n der gan dd har -- ac' )
DO-ANOTHER ( pul n gan ac har der -- gan' )
AND-ANOTHER ( dd n ac sli pul gan -- pul' )
YET-ANOTHER ( har sli der n dd pul -- dd' )
PULL-LEG ( n der dd ac har sli -- pul' )
PULL-THE-OTHER ( har dd gan der n ac -- sli' )

The Forth word should call these six routines in this same order, and
each should use the outputs of the others. That is, the last five should
use ac' in place of ac, the last 4 should use gan' in place of gan, etc.


SOLUTION ( har der ac n dd sli gan pul -- sli' )

With locals this is trivial.

: SOLUTION { har der ac n dd sli gan pul }
   ac n der gan dd har DO-SOMETHING TO ac
   pul n gan ac har der DO-ANOTHER TO gan
   dd n ac sli pul gan AND-ANOTHER TO pul
   har sli der n dd pul YET-ANOTHER TO dd
   n der dd ac har sli PULL-LEG TO pul
   har dd gan der n ac PULL-THE-OTHER ;

No thought required. Nothing to it. But it isn't trivial in Forth
without locals. If you're going to call C libraries, the C guys can
throw you whatever stack snarls they feel like. It's nothing to them.
And you can use locals and have it be nothing to you, or you can
struggle with it. Or you can rewrite each function in Forth and factor
them carefully, and when they work -- then if you want you can translate
them into C to get a better C library.
 




 4 Posts in Topic:
Re: A Brief Look at History
Jonah Thomas <jethomas  2008-03-20 07:24:58 
Re: A Brief Look at History
Andrew Haley <andrew29  2008-03-20 12:40:26 
Re: A Brief Look at History
Elizabeth D Rather <er  2008-03-20 08:37:41 
Re: A Brief Look at History
Doug Hoffman <no.spam&  2008-03-20 17:35:19 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 8:38:11 CDT 2008.