ftran201.f 
Author Message
 ftran201.f

Dear Forth Community,

The new, improved version of ftran is now on my
computational methods page,

    http://www.*-*-*.com/ .{*filter*}ia.edu/classes/551.jvn.fall01/

under the rubric of "Forth system and example programs ".

Be sure to download ALL the files associated with it.
In particular, the documentation has gotten so long
I separated it out. Also the state machine and vectoring
code is sufficiently useful that I put them into separate
files.

The new version uses EVALUATE much more than the old did
(sorry, Anton, it was the easiest way ;-/ ) . You can
translate a formula to Forth on the screen or compile it
into a word definition, as before.

However, you can also now evaluate an expression inter-
actively with the locution

  fvariable x  fvariable y  ok
  3e0 x f!     4e0 y f!  ok
  f$" x*(x^2+y^2)" f. 75.0000  ok

Finally, I have included a limited ability to handle
complex variables. The words f" and f$" are replaced
with zz" and z$" for complex arithmetic. Happy FOR-
mula TRANslating!

I don't currently have GForth available (I have moved
both my home and office machines) nor do I own Swift
Forth, so I have been unable to test with anything but
Win32Forth 4.2. Please let me know of any problems that
arise. (If you use Swift Forth, say REQUIRES FPMATH
before loading ftran201.f .)

For Krishna Myneni, here (at last!) is the interactive
evaluation I promised you for kForth and xyPlot.

Regards.

--
Julian V. Noble
Professor of Physics

Galileo's Commandment:

   "Science knows only one commandment: contribute to science."
   -- Bertolt Brecht, "Galileo".



Thu, 11 Mar 2004 04:04:20 GMT  
 ftran201.f
I tried loading under SwiftForth 2.2.2

1. Problems loading complex.f from FSL on SwiftForth distribution CD
  a. SwiftForth uses Private and Public not  Private: and Public:
  b. After removing colons loaded with "Package balance changed "
warning
  c. Version from your site loaded without error/warning

2. vector1.f not in FSL on SwiftForth distribution CD, didn't see it on
your site

3. Did not see fsm2.f or chr_tbl.f on your site



Thu, 11 Mar 2004 05:22:13 GMT  
 ftran201.f


Quote:
> The new, improved version of ftran is now on my
> computational methods page,

> http://www.*-*-*.com/ .{*filter*}ia.edu/classes/551.jvn.fall01/

> under the rubric of "Forth system and example programs ".

I enjoy Julian's programming because it is so different from mine.
For the difference, compare his FTrans with my Operator Precedence
Grammar - two approaches to the same topic.

My program is at < http://www.*-*-*.com/ ~neilbawd/opg.html> and
< http://www.*-*-*.com/ ~neilbawd/opg.txt>.  The HTML is generated
automatically from the TEXT.  Save the TEXT as Plain Text.

I hope that my code has everything needed to compile and test.  Let me
know if I missed something.

I know that Julian, like me, will appreciate the opinions of CLF readers
on the codes.

(
--  

)



Thu, 11 Mar 2004 09:20:58 GMT  
 ftran201.f

Quote:

> Dear Forth Community,

> The new, improved version of ftran is now on my
> computational methods page,

>     http://www.*-*-*.com/ .{*filter*}ia.edu/classes/551.jvn.fall01/

> under the rubric of "Forth system and example programs ".

> Be sure to download ALL the files associated with it.
> In particular, the documentation has gotten so long
> I separated it out. Also the state machine and vectoring
> code is sufficiently useful that I put them into separate
> files.

Several remarks:

        1. Although v. 2.01 worked fine in all interactive
           tests, it seemed to have a problem compiling when
           the source was a file. This happened both under
           Win32Forth 4.2 and GForth 4.9. Displayed a lot of
           "Unbalanced () !" messages that were actually
           meaningless since everything compiled fine anyway.

           I expect it is something to do with the way files
           and EVALUATE manage the input stream. Since I don't
           have time to bug-hunt at the moment, I just disabled
           the message.

        2. For Richard Owlett, all the named files were on the
           page

            http://www.*-*-*.com/ .{*filter*}ia.edu/classes/551.jvn.fall01/ftran2x.htm

           However I realize I should have included a test file,
           so I now append a translation of Neil Bawd's test file
           (from his OPG.f translator to my ftranxxx.f notation).

Hope you find no glaring errors. It does ok on the formulas
I have tried.

--
Julian V. Noble
Professor of Physics

Galileo's Commandment:

   "Science knows only one commandment: contribute to science."
   -- Bertolt Brecht, "Galileo".



Thu, 11 Mar 2004 09:47:29 GMT  
 ftran201.f

Quote:



> > The new, improved version of ftran is now on my
> > computational methods page,

> > http://www.*-*-*.com/ .{*filter*}ia.edu/classes/551.jvn.fall01/

> > under the rubric of "Forth system and example programs ".

> I enjoy Julian's programming because it is so different from mine.
> For the difference, compare his FTrans with my Operator Precedence
> Grammar - two approaches to the same topic.

> My program is at < http://www.*-*-*.com/ ~neilbawd/opg.html> and
> < http://www.*-*-*.com/ ~neilbawd/opg.txt>.  The HTML is generated
> automatically from the TEXT.  Save the TEXT as Plain Text.

> I hope that my code has everything needed to compile and test.  Let me
> know if I missed something.

> I know that Julian, like me, will appreciate the opinions of CLF readers
> on the codes.

Neil's remarks are most kind. Actually I find his code
extremely instructive. In particular it has certain
characteristics that make it good for new users to
emulate.

First, Neil avoids "hacks" like the following:

: [put_char]  ( c -- col#)  \ char -> col #:    in     out
                                            \ -------------
    1 OVER  BL       =  AND       ( -- c n) \  other    0
    OVER    [CHAR] { =  2 AND +   ( -- c n) \    bl     1
    SWAP    [CHAR] } =  3 AND +   ( -- #)   \    {      2
;                                           \    }      3

My code uses logic to compute the result without decisions.
That is, I got into the habit, years ago when computers were
smaller and multiple pipelines a thing of engineers' pipe
dreams, of avoiding decisions wherever possible.

Neil would code this as

: [put_char]  ( c -- col#)  \ char -> col #
        CASE  BL        OF  1  ENDOF
              [CHAR] {  OF  2  ENDOF
              [CHAR] }  OF  3  ENDOF
              0=
        0 ENDCASE
;

which would do the same thing and be clearer to novices.

I have in the past tended to avoid CASE statements
in favor of things like jump tables or logical arithmetic
because the branches would slow things down measurably.
To those unused to it, logical arithmetic can seem arcane.

Nowadays clarity of code may a better guiding principle.

Other ways that my code differs from Neil/Wil's are

        1. I tend to use symbols in names when they serve
           a telegraphic purpose in keeping names short.

        2. I try to keep words short (although rarely as
           short as Charles Moore's), hence tend to have'
           many short definitions.

        3. Neil/Wil tends to use longer, hyphenated names
           a la C, and he tends to have fewer, but much
           longer, words in a comparable program.

        4. Finally, I tend to be careless about questions
           of embedability, or reloadability, since I have
           not been bitten by the problems associated there-
           with. For example, Neil notes that my word

             : defines   ( xt --)  

                IF   POSTPONE  LITERAL    POSTPONE  !
                ELSE   !   THEN  ;  IMMEDIATE

           would be better as

             : defines   ( xt --)  

                IF  POSTPONE >BODY   POSTPONE  LITERAL    POSTPONE  !
                ELSE   >BODY  !   THEN  ;  IMMEDIATE

           because >BODY can get relocated. Having never had the
           problem, I did not think to prevent it.

           Neil's code is undoubtedly safer to use than mine.

--
Julian V. Noble
Professor of Physics

Galileo's Commandment:

   "Science knows only one commandment: contribute to science."
   -- Bertolt Brecht, "Galileo".



Thu, 11 Mar 2004 10:45:06 GMT  
 ftran201.f

Quote:

> For Krishna Myneni, here (at last!) is the interactive
> evaluation I promised you for kForth and xyPlot.

I will surely take a look at using ftran as an expression
evaluator as a Forth module for xyplot. Thanks.

Krishna



Thu, 11 Mar 2004 11:16:40 GMT  
 ftran201.f
[snip]
Quote:

>         4. Finally, I tend to be careless about questions
>            of embedability, or reloadability, since I have
>            not been bitten by the problems associated there-
>            with. For example, Neil notes that my word

>              : defines   ( xt --)
[snip]
>            would be better as

>              : defines   ( xt --)

>                 IF  POSTPONE >BODY   POSTPONE  LITERAL    POSTPONE  !

                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Quote:
>                 ELSE   >BODY  !   THEN  ;  IMMEDIATE

        This is
                  IF  POSTPONE  LITERAL    POSTPONE >BODY   POSTPONE  !
right?

Quote:

>            because >BODY can get relocated. Having never had the
>            problem, I did not think to prevent it.

>            Neil's code is undoubtedly safer to use than mine.

        This is certainly true, but does any Forth system exist now that would
relocate the >BODY relationship? This relocation could conceivably
happen only after compiling a program, saving it and running it later. I
admit that the possibility for such a relocation never crossed my mind;
I was naively assuming that the developers of any Forth system would
take care to insure relocation transparency. Actually, by looking at the
Standard now, I see that the only thing it says is that the relationship
b/n code and data space is "implementation dependent". What was the
intention re: relocatability of the relationship? Shouldn't a data space
address (obtained by means of >BODY in this particular example) and
compiled into a definition by using LITERAL, be always valid?
        Greetings,
Elko
-----------------------------------------------------------------------
I want to be a nothing-knower,               Elko Tchernev

for time is dead, the sun is over            www.gl.umbc.edu/~etcher1
and there is nothing left to kill.           tel/fax (613) 246 6313


Thu, 11 Mar 2004 12:38:05 GMT  
 ftran201.f


Quote:
>Shouldn't a data space
>address (obtained by means of >BODY in this particular example) and
>compiled into a definition by using LITERAL, be always valid?

On a standard system, and as long as you use only standard words, yes.
Image saving and restoring is outside the standard, though, and
anything can happen.

In Gforth, body addresses are valid across image saving and
relocation, but, e.g., ALLOCATEd regions, code addresses (the results
of >CODE-ADDRESS) or hash values involving addresses are not.

- anton
--
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html



Thu, 11 Mar 2004 17:19:14 GMT  
 ftran201.f
Quote:


> [snip]

> >         4. Finally, I tend to be careless about questions
> >            of embedability, or reloadability, since I have
> >            not been bitten by the problems associated there-
> >            with. For example, Neil notes that my word

> >              : defines   ( xt --)
> [snip]
> >            would be better as

> >              : defines   ( xt --)

> >                 IF  POSTPONE >BODY   POSTPONE  LITERAL    POSTPONE  !
>                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >                 ELSE   >BODY  !   THEN  ;  IMMEDIATE

>         This is
>                   IF  POSTPONE  LITERAL    POSTPONE >BODY   POSTPONE  !
> right?

        Yes, I was sleepy when I wrote it and got it Forth-wise
        (that is, backward ;-)

--
Julian V. Noble
Professor of Physics



Thu, 11 Mar 2004 23:22:46 GMT  
 ftran201.f

Quote:

>         2. For Richard Owlett, all the named files were on the
>            page

>             http://www.*-*-*.com/ .{*filter*}ia.edu/classes/551.jvn.fall01/ftran2x.htm

Copying all the files on that page to a single directory I got

SwiftForth 2.2.2 09Mar2001
INCLUDE C:\ForthInc\SwiftForth\User\ftran\ftran201.f
[UNDEFINED] isn't unique. F1.0 ?
[undefined] 1/f       [IF]  : 1/f   F1.0  FSWAP  F/ ; [THEN]
At line 37 in C:\ForthInc\SwiftForth\User\ftran\complex.f

include complex.f               \ complex arithmetic package
At line 25 in C:\ForthInc\SwiftForth\User\ftran\ftran201.f

1 definition was hidden

fvariable x  fvariable y  ok
  3e0 x f!     4e0 y f!  ok
 f$" x*(x^2+y^2)" f. f$" ?

when i loaded ftran201.f

I had added the lines

 REQUIRES FPMATH                \ mod to work with SwiftForth
                                \ per instructions of jvn

prior to

MARKER -ftran                   \ say -ftran to remove all, ANS-ly



Fri, 12 Mar 2004 03:12:16 GMT  
 ftran201.f

Quote:
> I tried loading under SwiftForth 2.2.2

Under iForth I had to comment out the wrong [UNDEFINED] ( BL
WORD FIND , we discussed that recently ), and ticking the >0
constants when compiling. I changed 0 CONSTANT >0 to : >0 0 ; etc.

The result is quite good:

FVARIABLE a  
FVARIABLE b

: test0   f" 10000000*(b-c)/(b+c)" FE. ;

FORTH> see test0
$004B01C0  : test0
$004B0211  fld         $004B0280 qword-ptr  ( 1e7 )
$004B0217  fld         $004B0158 qword-ptr
$004B021D  fld         $004B0170 qword-ptr
$004B0223  fsubp       ST(1), ST
$004B0225  fld         $004B0158 qword-ptr
$004B022B  fadd        $004B0170 qword-ptr
$004B0231  fdivp       ST(1), ST
$004B0233  fmulp       ST(1), ST
$004B0235  sub         $10 [edi], 8 d#
$004B023C  mov         eax, $10 [edi]
$004B023F  fstp        [eax] qword-ptr
$004B0241  jmp         FE.+6 NEAR

-marcel



Fri, 12 Mar 2004 07:27:34 GMT  
 ftran201.f

Quote:

> I tried loading under SwiftForth 2.2.2

> 1. Problems loading complex.f from FSL on SwiftForth distribution CD
>   a. SwiftForth uses Private and Public not  Private: and Public:
>   b. After removing colons loaded with "Package balance changed "
> warning
>   c. Version from your site loaded without error/warning

> 2. vector1.f not in FSL on SwiftForth distribution CD, didn't see it on
> your site

> 3. Did not see fsm2.f or chr_tbl.f on your site

SwiftForth is tested with the release of FSL included with the product.
There may be/may have been other releases of FSL that aren't
tested.  There's a "compatibility layer" for mating FSL with various
Forths, and we maintain the one for SwiftForth, but only to the
FSL release we distribute.  From this message, I can't tell what
compatibility issues there may be with ftran201.f, but if our users are
interested in using it, we'll appreciate any reports of issues and

subscribe to).

Cheers,
Elizabeth



Sat, 13 Mar 2004 02:01:11 GMT  
 ftran201.f
Take my feedback with skepticism  -- I suspect I'm having harware/OS
problems [ previously working code just failed ], but will not be able
to really investigate until this weekend.
Quote:


> > I tried loading under SwiftForth 2.2.2

> > 1. Problems loading complex.f from FSL on SwiftForth distribution CD
> >   a. SwiftForth uses Private and Public not  Private: and Public:
> >   b. After removing colons loaded with "Package balance changed "
> > warning
> >   c. Version from your site loaded without error/warning

> > 2. vector1.f not in FSL on SwiftForth distribution CD, didn't see it on
> > your site

> > 3. Did not see fsm2.f or chr_tbl.f on your site

> SwiftForth is tested with the release of FSL included with the product.
> There may be/may have been other releases of FSL that aren't
> tested.  There's a "compatibility layer" for mating FSL with various
> Forths, and we maintain the one for SwiftForth, but only to the
> FSL release we distribute.  From this message, I can't tell what
> compatibility issues there may be with ftran201.f, but if our users are
> interested in using it, we'll appreciate any reports of issues and

> subscribe to).

> Cheers,
> Elizabeth



Sat, 13 Mar 2004 02:13:46 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Unexpected abilities (and disabilities) of Ftran201

2. Bug found in ftran201.f

 

 
Powered by phpBB® Forum Software