Bruce McFarling <agila61@[EMAIL PROTECTED]
> wrote:
> \ hide the stack noise inside edge generating words
> : dup-points ( x1 y1 x2 y2 -- x1 y1 x2 y2 x1 y1 x2 y2 ) 2OVER 2OVER ;
> : topline ( x1 y1 x2 y2 -- x1 y1 x2 y1 ) DROP OVER ;
> : rightline ( x1 y1 x2 y2 -- x2 y1 x2 y2 ) >R ROT DROP TUCK R> ;
> : bottomline ( x1 y1 x2 y2 -- x1 y2 x2 y2 ) ROT DROP TUCK ;
> : leftline ( x1 y1 x2 y2 -- x1 y1 x1 y2 ) >R DROP OVER R> ;
>
> : BOX3 ( x1 y1 x2 y2 -- )
> dup-points topline LINE
> dup-points rightline LINE
> dup-points bottomline LINE
> leftline LINE ;
>
> And we see there are two factors there ... one to replace the 1st with
> the 3rd, and one to replace the 3rd with the 1st:
>
> : dup-points ( x1 y1 x2 y2 -- x1 y1 x2 y2 x1 y1 x2 y2 ) 2OVER 2OVER ;
>
> : 1->3 ( a b c -- c b c ) ROT DROP TUCK ;
> : 2->4 ( a b c d -- c b c d ) >R 1>3 R>
> : 3->1 ( a b c -- a b a ) DROP OVER ;
> : 4->2 ( a b c d -- a b a d ) >R 3>1 R> ;
>
> ' 3->1 ALIAS topline ( x1 y1 x2 y2 -- x1 y1 x2 y1 )
> ' 2->4 ALIAS rightline ( x1 y1 x2 y2 -- x2 y1 x2 y2 )
> ' 1->3 ALIAS bottomline ( x1 y1 x2 y2 -- x1 y2 x2 y2 )
> ' 4->2 ALIAS leftline ( x1 y1 x2 y2 -- x1 y1 x1 y2 )
>
> : BOX3 ( x1 y1 x2 y2 -- )
> dup-points topline LINE
> dup-points rightline LINE
> dup-points bottomline LINE
> leftline LINE ;
I want to point out that what you've done here is semantic sugar. You've
hidden the stack mechanics with code that shows the meaning and that
doesn't show the mechanics.
This makes the upper-level code more readable, which is usually a good
thing. But it doesn't address Douglas's main concerns. You still had to
figure out ROT DROP TUCK etc and make sure they work before you could
hide them. A Forth newbie would have to get the concepts and apply them
to make it work, while in other languages this complication would simply
not exist. They might have type-cast variables in place of a stack, and
they have a lot of extra bother in there which they've already learned
to ignore. Or they might have locals.
You have to think to re-order the stack. You don't much have to think to
use variable names. The compiler does it for you.
Semantic sugar means people don't have to think as much when they read
the code. But you have to think at least as much when you write it.
People generally don't like lots of mindless boilerplate they have to
type out to get stuff done. But stuff they have to think about is even
worse.