mikpa@massormetrix.ida.liu.se (Mikael Patel) (08/02/89)
Hi, Forth-world, I am doing some work on comparing Forth with other programming languages with regard to incapsulation and visibility of symbols (Forth: words). Basically Forth seems to have only have these methods: 1) The "compilation" and "interpretation" mode mark as for words such as "if" which is marked as only usable during compilation and then always executed. 2) The use of vocabularies. This does not generally solve the problem of visibility of words as all words defined in a vocabulary are visible by a "user". 3) Don't care about internal words as these are allowed to be redefined. The problem of incapsulation and visibility has come some what of the main attributes of a programming language because of all the "noise" around object-orientation. What I would like to propose is the following three words, similar to "immediate", as mode markers to give Forth a more well defined notion of incapsulation and visibility. private ( -- ) Marks the most recently created dictionary entry as a word which is only available in the dictionary it is created in. The word is not available when the dictionary is not current. execution ( -- ) Marks the most recently created dictionary entry as a word which is only available in execution mode. compilation ( -- ) Marks the most recently created dictionary entry as a word which is only available in compilation mode. So compilation words like "if" become: : if ( flag -- ) .... ; compilation immediate So what do you say Forthians? Seen something like this or maybe an other approach! Tell us about it! Mikael Patel 'Just the place for a Snark! I have said it thrice: What I tell you three times is true.' - Lewis Carrol -
RAYBRO%UTRC@utrcgw.utc.COM ("William R Brohinsky", ay) (08/03/89)
Mikael Patel: I must admit that I don't have a good grasp on "incapsulation", as you are using it. I think a definition or reference to some available work would be helpful. Most forths have some "behead" mechanism which leaves "orphan" code with only those words that call it knowing where to find it. After the beheading, the user is not able to use the word directly unless he can find the PFA and incorporate it directly (push it on the stack as a literal and EXECUTE it, usually speaking). I dislike this very much. In my experience, if you can use any forth words as forth words, you are a "programmer" as well as a user, or at least have the ability to act as such. I really dislike ASYST, PolyFORTH(tm), and a few other implementations for doing just this: there is no decompile, and may be no word listing facility, so that the "proprietary" portions of the code stay that way. The carrot for me as programmer is the ability to see how EMIT was done when I need a new EMIT-type word, allowing MYEMIT to function similarly to how the person(s) who implemented my forth did it. For those of you who wrote your own forths (which I will, Leo, in my copious spare time, some day...), why would you WANT to have a mechanism to hide words from yourselves? I are times when I see things like this (or like C) that I believe in my heart-of-heart that I am an inferior outsider. Can the rest of you really remember everything you ever wrote without ever having to decompile? Am I the only one to ride on the coattails of my putative implementator? Or to forget what STLSRGAT was supposed to do? When I don't burn my bridges behind me, I shorten the time a bad memory imposes on me when I must back- track. Maybe when I see the reason for the importance of incapsulation and visibility as programming language parameters (if indeed, programming languages can be so parameterized), I will realize that I am also the only one of us with his thigh in his mouth... -raybro
toma@tekgvs.LABS.TEK.COM (Tom Almy) (08/03/89)
In article <1@massormetrix.ida.liu.se> mikpa@massormetrix.ida.liu.se (Mikael Patel) writes: >So what do you say Forthians? Seen something like this or maybe >an other approach! Tell us about it! You can (permanently) hide headers by unlinking them or otherwise disposing of them (if headers are kept separate). The earliest approach I have seen, in the Vol II, #5 issue of Forth Dimensions, involves three words INTERNAL EXTERNAL and MODULE. It is used: INTERNAL \ definitions which are local (headers will be unlinked) EXTERNAL \ definitions which are externally accessed -- they may call internal words MODULE \ excises headers These can also be nested. Very effective, and simple to implement. Tom Almy toma@tekgvs.labs.tek.com Standard Disclaimers Apply
andrew@idacom.UUCP (Andrew Scott) (08/09/89)
In article <1@massormetrix.ida.liu.se>, mikpa@massormetrix.ida.liu.se (Mikael Patel) writes: > execution ( -- ) > Marks the most recently created dictionary entry as a word > which is only available in execution mode. > > compilation ( -- ) > Marks the most recently created dictionary entry as a word > which is only available in compilation mode. > > So compilation words like "if" become: > > : if ( flag -- ) .... ; compilation immediate I like these words a lot, not for their encapsulation properties, but for error handling. In FIG-Forth, the words ?EXEC and ?COMP are used for words that should only be executed in execution or compilation mode respectively. I find that these words are a bit awkward to use and add clutter to the body of the words. -- Andrew Scott andrew@idacom - or - {att, watmath, ubc-cs}!alberta!idacom!andrew