FIF. Another FORTH.

Discussion about ZX80 / ZX81 Software
Moggy
Posts: 2375
Joined: Wed Jun 18, 2008 2:00 pm

Re: FIF. Another FORTH.

Post by Moggy »

Hi Alan.

Question if I may?

All to do with my learning and not a complaint, criticism or a request for anything to be changed. (preamble done)

It involves the definition of SIGN that you are using for FIF79 which seems to be more of a Fig Forth definition than a Forth79 one and is acting as a double precision operator.

Example.

: .$ SWAP OVER DABS <# # # 46 HOLD # S 36 HOLD SIGN #> TYPE SPACE ;

-12345. .$ -123.45 ok


This works as shown above in FIF79 but not in Toddy Forth79 and according to the Forth79 standards blurb it is a single precision operator not a double.


Forth-79:
SIGN n -- C,140

Insert the ASCII "-" (minus sign) into the pictured numeric
output string, if n is negative.

: SIGN ( n -- )
0< IF 45 HOLD THEN




FigForth:
SIGN n d --- d L0
Stores an ascii "-" sign just before a converted numeric output
string in the text output buffer when n is negative. n is discarded
but double number d is maintained. Must be used between <# and #>.

: SIGN ( n d -- d )
ROT 0< IF 45 HOLD THEN ;


Note the added ROT in FigForth.
This looks like SIGN in FIF79 has been defined as per Fig Forth.

If I insert ROT into the .$ definition then TF79 works..

: .$ SWAP OVER DABS <# # # 46 HOLD #S 36 HOLD ROT SIGN #> TYPE SPACE ;

But the ROT addition is just allowing a single operator to be used in a double scenario.
If Forth79's definition of SIGN is as a single operator then how can it be used in FIF79 as a single if it's defined as a double operator that can only be used in a number formatted colon definition .

You have to allow for the fact I'm a bear of little brain on a very very steep learning curve and this is very hard for me honestly. :oops:
roganjosh
Posts: 56
Joined: Thu Jun 14, 2018 12:59 pm

Re: FIF. Another FORTH.

Post by roganjosh »

Hi Moggy,

Good spot. My mistake. The existing SIGN is only used internally by D.R and should have been headerless and therefore invisible. I was intending to then replace it with the Forth79 version. The glossary defined yet another variant (and there was even, at one stage, a development version that acted on a single byte). I'll put in the proper SIGN, update the glossary and put up a new version tomorrow (Wed). That's one of the best bug reports I've seen!

Alan
User avatar
kmurta
Posts: 205
Joined: Tue Sep 01, 2009 5:04 am
Location: Belo Horizonte - BR
Contact:

Re: FIF. Another FORTH.

Post by kmurta »

Hi Moggy and Alan!

This is a little confusing for me, while in Forth-79 Standard paper the SIGN word expect the sign flag at TOS, I found some references that say that the SIGN acts as in FigForth, that is, the signal flag is the third item in the stack and ROT is included to the SIGN definition.

Some of these references:

http://www.6502.org/trainers/synertek/s ... isting.pdf (page 49 of pdf, 94 of document)

https://1scyem2bunjw1ghzsf1cjwwn-wpengi ... -FORTH.pdf (pages 169 onwards)

http://mikeos.sourceforge.net/handbook-forth.html (at source code in download area)

But in Jupiter ACE's Forth (which is based on Forth-79) SIGN does not include the ROT and the definition of .$ described by Moggy needs to include ROT before SIGN.

So I'm really confused about what to do: define SIGN in order to conform with the literature of the time, or meet the specifications of the official standard?
1 x ZX81, 2 x TK85 , 1 TK82C, 1 TK95, 1 x Ringo R470, 1 x Alphacom 32 printer, 1 x ZXpand
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
roganjosh
Posts: 56
Joined: Thu Jun 14, 2018 12:59 pm

Re: FIF. Another FORTH.

Post by roganjosh »

Hi Kelly & Moggy,

That'll teach me to reply just before I go to bed. Forget what I said before as I'd just quickly looked at the F79 standard.

Given that all the pictured numeric conversion words in F79 are based on double integers then the F79 version of SIGN which expects an integer is a chocolate fireguard. There ought to be an easy way of testing the sign of the 3rd stack number without resorting to ROT. Looking at the references Kelly gave I could add another to the list:

https://stardot.org.uk/forums/download/ ... b36ff8445c

which is the BBC version. That also defines SIGN using double integer but it also has the 79-Standard word in its vocabulary. I must say that I've always used/coded a double version of SIGN.

I'd be tempted to think that the integer version is an erratum, however its definition also makes it into Forth-83 and you'd think it might have been corrected before then if that was the case.

Moggy: What version of SIGN do the examples you're working through in your book use?

Unless someone can find a more definitive reference than the F79 document my instinct would be to follow it and optionally add a word (#SIGN or somesuch) that expects double ints. Very odd.


Thoughts?

I'll see if a dog walk brings enlightenment...

Alan
Moggy
Posts: 2375
Joined: Wed Jun 18, 2008 2:00 pm

Re: FIF. Another FORTH.

Post by Moggy »

The book I'm using is The complete Forth by Alan Winfield which can be found here...

http://jupiter-ace.co.uk/BookReader/br- ... 1/mode/1up


I would ask both of you do your Forths include the variable DPL (section 8-1 of the book) which apparently is used to count the places after the point and is used in a definition on page 83 for a number formatting routine I would find very useful.
However I fear you would both hit me with sticks and burn me with fire for all the aggravation I am causing you both! :lol:


The main reason for using Winfield's book is that it is supposedly based entirely on Forth 79, unlike Brodie's online works which which he insisted on being brought up to a more modern forth standard for online use, which means either owning the original book or seeking out a very old PDF of Brodie's original book which is Forth 79 compliant and one that I have posted on the forum.

All the examples within Winfield's book play quite nicely with both Kelly's and your own Forth hence my use of it to test for compatibility as it is quite disconcerting when reading so called standard works only to find the flavour of Forth you happen to be using has a lot of incompatibility with the books contents.

The SIGN definition confused me initially as it refers to n singular in its definition but seems only usable as a double number operator in formatted number output which as I understand it only uses doubles numbers, as per the .$ example where no single precision integer is involved.

Below is the SIGN definition as per Winfield's book.

SIGN (n ud -> ud )

Insert an ASCII minus sign "-" into the formatted number string if n is negative. Use between <# and #>. .


The example he uses


: .$ SWAP OVER DABS <# # # 46 HOLD # S 36 HOLD SIGN #> TYPE SPACE ;

-12345. .$ -123.45 ok



The relevant pages are 80 to 85.
roganjosh
Posts: 56
Joined: Thu Jun 14, 2018 12:59 pm

Re: FIF. Another FORTH.

Post by roganjosh »

Moggy wrote: Wed May 05, 2021 2:23 pm
Below is the SIGN definition as per Winfield's book.

SIGN (n ud -> ud )

Insert an ASCII minus sign "-" into the formatted number string if n is negative. Use between <# and #>. .


The example he uses


: .$ SWAP OVER DABS <# # # 46 HOLD # S 36 HOLD SIGN #> TYPE SPACE ;

-12345. .$ -123.45 ok


The relevant pages are 80 to 85.

Well that definition of SIGN is what FIF has been using all along (but I did have the glossary entry showing something different). It's almost as if, after the F79 standard was released, a lot of people thought "Nah, they must have meant THIS!"

If the chap is using DPL then that's certainly not F79. I can't find it in the F83 standard either. It looks to be FigForth/gforth. I can take a look. I've a sneaky suspicion it'll mean breaking open the numeric input code again though.


Alan
Moggy
Posts: 2375
Joined: Wed Jun 18, 2008 2:00 pm

Re: FIF. Another FORTH.

Post by Moggy »

I think we can all agree that some Figforth has crept into Winfield's definitions as SIGN and now DPL which is curious as in the preface he thanks both Charles Moore and Elizabeth Rather for the Forth79 dialect used in the book, which would suggest and reinforces in my mind at least how fragmented Forth has become considering that there was supposed to be some sort of standard.

As for DPL I am now pouring petrol over myself and will shortly pluck up courage to light the match for having the temerity to bring it up! :oops:
roganjosh
Posts: 56
Joined: Thu Jun 14, 2018 12:59 pm

Re: FIF. Another FORTH.

Post by roganjosh »

Don't light that match! I've just implemented DPL for you. It seems to work OK. I'll upload it after giving Kelly a chance to reply about the SIGN thing. It would seem to make sense if we both adopted the same SIGN definition, otherwise you'd have to maintain multiple versions. The dog walk didn't achieve much except for a tired dog.

Alan
Moggy
Posts: 2375
Joined: Wed Jun 18, 2008 2:00 pm

Re: FIF. Another FORTH.

Post by Moggy »

At which point you realised that Bonzo was actually fluent in LISP,COBOL and six dialects of Forth and had the answer all long!


(Sorry but I'm on my third Tramadol, head swimmy, streams of consciousness and all that )
User avatar
kmurta
Posts: 205
Joined: Tue Sep 01, 2009 5:04 am
Location: Belo Horizonte - BR
Contact:

Re: FIF. Another FORTH.

Post by kmurta »

I once read somewhere that there was no forth commercial system that was 100% standards compliant, perhaps that explains the divergence between the F79 documentation and the referenced compilers and books. It seems to me that at the time they did not like the new definition for SIGN and kept the old one. So I think it is consistent to maintain compatibility with the old systems and literature, even if it disagrees with the official standard.

Another reference that supports this decision is the following document, which deals with the conversion of a FigForth system into a Forth-79 standard. There is no reference to the word SIGN in it, so it is understood that they work the same way in both systems: http://www.stackosaurus.com/misc/Forth- ... ersion.pdf

About DPL, it is not required by the F79 standard but is provided in the section "REFERENCE WORD SET" along with other known words (PAGE --> .R 2* 2/ ASCII AGAIN and many others):

REFERENCE WORD SET
FORTH-79

The Reference Word Set contain both Standard Word Definitions (with
serial number identifiers in the range 100 through 999), and
uncontrolled word definitions.

Uncontrolled definitions are included for public reference of words
that have present usage and/or are candidates for future
standardization.

No restrictions are placed on the definition or usage of
uncontrolled words. However, use of these names for procedures
differing from the given definitions is discouraged.


https://www.complang.tuwien.ac.at/forth ... RTH-79.TXT
1 x ZX81, 2 x TK85 , 1 TK82C, 1 TK95, 1 x Ringo R470, 1 x Alphacom 32 printer, 1 x ZXpand
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
Post Reply