Article View: net.lang.forth
Article #347Information Hiding in FORTH
From: Tim Olson
Date: Wed, 25 Jun 1986 16:35
Date: Wed, 25 Jun 1986 16:35
45 lines
1879 bytes
1879 bytes
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; something like:
: random-package ;
VARIABLE randval
: init-rand ( seed -- )
randval ! ;
: rand ( range -- rand# )
randval @ 21709 + 15273 * randval !
mod ;
HIDE randval
(No flames on the "randomness" of this random package, please :-)
HIDE is a word which, like tic ('), searches the dictionary for the
target word. HIDE also keeps a trailing pointer to the previous
word in the dictionary. When it finds the target word in the dictionary,
it takes it out of the dictionary search path by changing the previous
word's next pointer to point to the word following the target word.
This allows a VARIABLE or procedure word to be used normally in a
"package" and then be hidden from subsequent definitions.
a) Is this a useful construct, or is it the attempt of an
admittedly neophyte forth programmer (me) to force
other language ideas onto forth?
b) Can HIDE be written in forth, or must it be written in
assembly language?
c) Is there another (easier) way to do this that I am not
aware of?
Tim Olson
Advanced Micro Devices
ihnp4!amdcad!tim
no.6: "What do you want?"
no.2: "Information."
no.6: "You won't get it!"
Technical Details
Message-ID:
<12110@amdcad.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!linus!philabs!prls!pyramid!decwrl!amdcad!timShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!linus!philabs!prls!pyramid!decwrl!amdcad!tim From: tim@amdcad.UUCP (Tim Olson) Newsgroups: net.lang.forth Subject: Information Hiding in FORTH Message-ID: <12110@amdcad.UUCP> Date: Wed, 25-Jun-86 12:35:47 EDT Article-I.D.: amdcad.12110 Posted: Wed Jun 25 12:35:47 1986 Date-Received: Fri, 27-Jun-86 05:37:56 EDT Organization: AMDCAD, Sunnyvale, CA Lines: 45