Article View: net.lang.forth
Article #348Re: Information Hiding in FORTH
From: John Wavrik
Date: Thu, 26 Jun 1986 17:33
Date: Thu, 26 Jun 1986 17:33
41 lines
2572 bytes
2572 bytes
In article <12110@amdcad.UUCP>, tim@amdcad.UUCP (Tim Olson) writes:
> I have been recently thinking of a way to implement something like the
> 'C' static scoping type in forth. This would allow a word or group of
> words to use a VARIABLE without letting the VARIABLE be visible outside
> the group;
>
> c) Is there another (easier) way to do this that I am not
> aware of?
When a name is re-used in Forth, the earlier
definition remains in the dictionary and is automatically used
by all words compiled when it was active. You can have many
variables named X -- and all will be, in effect local.
The problem comes if you would later like to refer to a variable
(or other object) that has been "covered". One way to do this
(absolutely against standards!) is to define a word ZAP
which locates the name field of a word and changes the
length byte to zero (make sure to preserve the higher
bits if necessary); or the first character of the name
to ascii 0; or in any other way destroys the name field
so that the word will not be found in a dictionary
search [the best change is system dependent].
Vocabularies can also be used to equip sub-applications
with special names without destroying access to previous
words with the same name.
Some Forth systems (e.g. MMS-Forth) provide for a
temporary dictionary area used only during compilation.
Words can have their name fields in the temporary area.
This creates local words -- with a saving of space in
the main dictionary (local words have no headers and
are not linked into the dictionary when the temporary
area is deleted - but their body is left in the dictionary).
There have been some experiments in Forth syntax
in which stack manipulation is eliminated by making
all arguments to a word into named local variables
(whose scope is just the word being defined). See
Dr. Dobbs journal of a few years ago.
--John J Wavrik
Math Dept - UCSD
..ucbvax!sdcsvax!sdcc3!ma168x
Technical Details
Message-ID:
<3448@sdcc3.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!caip!nike!ucbcad!ucbvax!sdcsvax!sdcc6!sdcc3!ma168aReferences:
<12110@amdcad.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!caip!nike!ucbcad!ucbvax!sdcsvax!sdcc6!sdcc3!ma168a From: ma168a@sdcc3.UUCP (John Wavrik) Newsgroups: net.lang.forth Subject: Re: Information Hiding in FORTH Message-ID: <3448@sdcc3.UUCP> Date: Thu, 26-Jun-86 13:33:35 EDT Article-I.D.: sdcc3.3448 Posted: Thu Jun 26 13:33:35 1986 Date-Received: Sat, 28-Jun-86 03:56:23 EDT References: <12110@amdcad.UUCP> Organization: U.C. San Diego, Academic Computer Center Lines: 41 Summary: You can ZAP!