Comparison with ANS Forth

From RevaWiki

Jump to: navigation, search

There are a lot of differences between Reva and ANS Forth.

For starters, Reva doesn't even try to be compatible with ANS. "But...", I hear you say, "ANS is the standard! Surely adhering to the standard is good!". Well, if the standard were good, and if ANS-compatible Forths all looked the same, you would have a point. There's an ironic statement, "Once you've seen one Forth, you've seen one Forth". I'm afraid that is mostly true.

In order to make life easier for ANS-ifiles, there is actually an ANS compatibility layer to Reva. Happily for most of us, it is not loaded by default. If you with to use the ANS layer (such as it is), do:

needs ansi

within Reva, or launch Reva with a command-line paramter of '-a':

reva -a

Now when you do words you will see some ANS compatible things. Be warned: the ANS layer currently breaks many "normal" Reva libraries, since it redefines the word repeat in a most incompatible manner. I hope to have this fixed sometime soon, but it is very low priority to me.

Reva has some words which are similar to ANS words yet not the same:

  • " is used to create a string, whether interactively or compiled. ANS uses S"
  • find is quite different
  • in Reva words occur immediately at the time they are defined in dictionary. ANS-FORTH has a concept of delayed visibility of words. That indirectly implies mechanisms as SMUDGE are to be defined. The way ANS goes is sometimes nice for redefining words when you want to inherit the old functionality. In Reva/HelFORTH/Retro you have to do some workarounds for that - eg.
  : emit prior emit '* prior emit ;
instead of ANS-version:
  : emit emit [char] * emit ;
While for this specific task ANS looks easier to program, there are a lot of implementation details that make the way Reva uses easier to implement and if extended by special words even more interesting - eg. with some extensions of HelFORTH (it's no big exercise to have this in Reva) the example would look this way:
  :: v: emit '* v: emit ; is emit
("v:" means to compile the current target of a deferred word or as in HelFORTH terms: compile the current target of a DOER).



(crc or Helmar - can you help me out here? ron 18:15, 23 March 2006 (PST))

(With regards to the ANS layer, if you do it in uppercase, as per the requirements of the standard, it can coexist with the lowercase Reva words peacefully. crc 25 March 2006)

    crc: I'm unsure. I think ANS did specify only that the UPPERCASE things have to be recognized this and only this way by the system. What the system does with lowercase similar words is not that clearly specified (I think there was a note about system-dependend behaviour...) But words later defined in a special "case" order do have to be recognized only as this word. Again, if CaSe changes, there is system dependend behaviour. This thing I used with my ANS-layer in HelFORTH to make it confirming to the standard. Well, but not all software claiming ANS-compatiblity uses UPERCASE. Sometimes they use strange mixes of the "CasE". So if Ron would implement ANS compat in a special dictionary in UPPERCASE, there would be a possibility to change "find" so that it searches only this dictionary for some special part of the software - making the ANS-layer more perfect. So I agree. Helmar 16:25, 25 March 2006 (PST)

OK, I like that. So I'll change the ANS layer to be case-sensitive like the rest of Reva, and make all words there UPPERCASE. This is easy and will make it useful again :)

Personal tools