Article View: net.lang.forth
Article #364Re: Information Hiding in FORTH
From: pmy
Date: Mon, 07 Jul 1986 20:11
Date: Mon, 07 Jul 1986 20:11
57 lines
2717 bytes
2717 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?
Yes, i think this is a useful construct. It'd be nice too, if it
would "collapse" the now-useless word header to regain some dictionary
space. Of course, it would also have to relocate everything defined after
the target word. Could be tricky!
> b) Can HIDE be written in forth, or must it be written in
> assembly language?
I haven't played with FORTH in a long time, but i'm fairly certain that
it could be used to implement HIDE.
> c) Is there another (easier) way to do this that I am not
> aware of?
You could also corrupt the name field (e.g. blank fill it) to make the
word lexically unrecognizable. I think the pointer-shifting scheme is better
though, as it removes the word from the search stream altogether.
--
Pete Yadlowsky University of Virginia, Academic Computing Center
UUCP: decvax!mcnc!ncsu!uvacs!pmy
CSNET: pmy@virginia
"If ya can't stand the heat ... it's too hot!"
Technical Details
Message-ID:
<622@uvacs.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utcs!mnetor!seismo!husc6!harvard!panda!genrad!decvax!decwrl!pyramid!hplabs!hp-sdd!ncr-sd!ncrcae!ncsu!uvacs!pmyReferences:
<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!utcs!mnetor!seismo!husc6!harvard!panda!genrad!decvax!decwrl!pyramid!hplabs!hp-sdd!ncr-sd!ncrcae!ncsu!uvacs!pmy From: pmy@uvacs.UUCP Newsgroups: net.lang.forth Subject: Re: Information Hiding in FORTH Message-ID: <622@uvacs.UUCP> Date: Mon, 7-Jul-86 16:11:36 EDT Article-I.D.: uvacs.622 Posted: Mon Jul 7 16:11:36 1986 Date-Received: Sat, 12-Jul-86 06:14:30 EDT References: <12110@amdcad.UUCP> Organization: U.Va. CS dept. Charlottesville, VA Lines: 58