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 1 Topic 3939 of 4160
Post > Topic >>

Re: A Brief Look at History

by Bruce McFarling <agila61@[EMAIL PROTECTED] > Mar 20, 2008 at 12:13 PM

On Mar 20, 7:24 am, Jonah Thomas <jethom...@[EMAIL PROTECTED]
> wrote:
> 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.

The question of whether that is the optimal solution falls into the
hole that "optimal" is an empty box for holding objectives. It may
well be that the optimal solution is to find the working model that is
easier to work with that encapsulates that complexity. OTOH, the best
way to find a good working model is often to get something that works
as a foundation and then experiment from there ...

.... and for rapid prototyping of access to a C-function library,
that's pretty quick, since its turning Forth into a kind of RPN C.

And, indeed, experimenting with the library may uncover a flaw that is
not present in some other available library, in which case not
investing a lot of time in coming up with the interface wrappers is
time well saved.

Calling C code and defining specific math formulas are two areas where
locals are definitely time savers in bringing them up to the point of
being able to bench test them, and there really is not a major
question of having to factor that ... you can't factor past the C-
Forth interface layer, and well-established algorithms tend to
themselves function as factors that are used in a variety of settings.
 




 1 Posts in Topic:
Re: A Brief Look at History
Bruce McFarling <agila  2008-03-20 12:13:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Fri Jul 18 20:44:23 CDT 2008.