10.01.2015 Views

1 - Forth Interest Group

1 - Forth Interest Group

1 - Forth Interest Group

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure One.<br />

FORTH-WORDLIST CONSTANT 4TH ( A convenient abbreviation. )<br />

: GENERAL 4TH 1 SET-ORDER 4TH SET-CURRENT ; ( -- 1<br />

WORDLIST CONSTANT IMP ( For implementation words. )<br />

: PRIVATE 4TH IMP 2 SET-ORDER IMP SET-CURRENT ; ( -- )<br />

: PUBLIC 4TH IMP 2 SET-ORDER 4TH SET-CURRENT ; ( -- )<br />

Figure Two.<br />

: GENERAL ONLY FORTH ( ALSO ) DEFINITIONS ;<br />

: PRIVATE ONLY FORTH ALSO IMPLEMENTATION DEFINITIONS ;<br />

: PUBLIC ONLY FORTH ALSO IMPLEMENTAT97-05-17<br />

ALSO FORTH DEFINITIONS PREVIOUS ;<br />

Figure Three.<br />

PRIVATE<br />

VARIABLE SEED<br />

PUBLIC<br />

: SRAND SEED ! ; 1 SRAND (n--)<br />

PRIVATE<br />

312748364721 CONSTANT MULTIPLIER<br />

: SCi7AMBLE MULTIPLIER * 1t ; ( n -- n' )<br />

PUBLIC<br />

: RAND SEEC @ SCRAMBLE DUP SEED ! ; ( -- n )<br />

GENERAL<br />

Figure Four.<br />

PRIVATE ORGER<br />

Search Order ( f irsi to last) : IMPLEMENTATION FOXTH<br />

Current : IMPLEIvlENTATION<br />

PUBLIC ORDER<br />

Search Order (first to last) : IMPLEMENTATION FORTH<br />

Current : FORTH<br />

GENERAL ORDER<br />

Search Order (first to last) : FORTH<br />

Current: FORTH<br />

or<br />

Search Order (first to last) : FORTH FORTH<br />

Current: FORTH<br />

%<br />

PRIVATE WORDS<br />

SCRAMBLE<br />

MUI.,TI PLIZR<br />

SEED<br />

PUBLIC WORDS<br />

SCRAMBLE MULTIPLIER SEED<br />

GENERAL WORDS<br />

RAND SRAND PUBLIC PRIVATE<br />

GENERAL IMPLEMENTATION etcetera<br />

PRIVATE ... PUBLIC ... GENERAL<br />

In "Yet Another Modest Proposal," (FD<br />

XVII116, 1997), RICHARD ASTLE proposes<br />

patching the dictionary structure to hide<br />

words used for implementation from the<br />

end user.<br />

In the early 1980s, VAL SHORRE proposed<br />

INTERNAL ... EXTERNAL ... MODULE for what<br />

Dr. ASTLE calls PRIVATE ... PUBLIC ... END-<br />

MODULE.<br />

Dr. SHORRE did this like Dr. ASTLE, by<br />

patching the dictionary structure.<br />

Patching the dictionary structure is not<br />

portable, and often is not possible.<br />

Standard <strong>Forth</strong> recognizes what ASTLE<br />

and SHORRE have done as search orders, and<br />

can define them accordingly. As a search<br />

order, GENERAL is a better name than MOD-<br />

ULE 01 END-MODULE.<br />

Portable standard code is given in Figure<br />

One. This code can be modified for<br />

more than one implementation wordlist.<br />

If ONLY ... ALSO is used, first define vocabulary<br />

IMPLEMENTATION and then the<br />

words in Figure Two.<br />

An elaborated mini-example is given in<br />

Figure Three.<br />

In GENERAL, the implementation words<br />

won't be available. Any names used in the<br />

implementation that were previously defined<br />

are still valid, with their original<br />

meaning.<br />

Some reports appear in Figure Four.<br />

P.S. In the <strong>Forth</strong> Scientific Library, IMP, GEN-<br />

ERAL, PUBLIC, and PRIVATE are named hidden-wordlist,Reset-Search-Order--<br />

lic :, and Private :, but otherwise with<br />

identical definitions.<br />

Wil Baden Costa Mesa, California<br />

wilbaden@netcom.com<br />

Richard Astle replies:<br />

1. I should have been more careful.<br />

Although I took pains to indicate-by<br />

citing other languages (Modula-2, Ada,<br />

etc.)-that the MODULE idea was not my<br />

own, 1 was not aware of Val Shorre's<br />

proposal for <strong>Forth</strong>, or if 1 was 1 had<br />

forgotten it. My first exposure to the<br />

technique of patching the dictionary<br />

structure came from Bob LaQuey in the<br />

early 80s, who used it in an implementation<br />

of a code overlay mechanism in<br />

an Apple fig<strong>Forth</strong>. If the dictionary<br />

Continued on page 19<br />

<strong>Forth</strong> Dimensions XlWl

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!