Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!dino!ux1.cso.uiuc.edu!tank!keith@curry.uchicago.edu From: keith@curry.uchicago.edu (Keith Waclena) Newsgroups: comp.lang.forth Subject: FORTH Modules: current confusion? Summary: what's current @ @? Keywords: modules; dictionary structure; compiler mods Message-ID: <6708@tank.uchicago.edu> Date: 13 Dec 89 21:24:33 GMT References: <5596@sdcc6.ucsd.edu> Sender: news@tank.uchicago.edu Reply-To: keith@curry.uchicago.edu (Keith Waclena) Organization: TIRA / UofC Lines: 79 Some background: It's the end of the quarter and I'm about to slip a little FORTH into a reading course I'm teaching on data encapsulation in programming languages. The course has followed a historical progression from block structure through modules, abstract data types and finally object-oriented programming. We read a paper by Friedman and Felleisen[1] detailing how one can add modules to Scheme with a page or so of relatively portable code. Now I thought I'd give my students a one-page paper by Schorre[2] on how to add modules to FORTH in 3 short lines of code. My problem is this: Schorre's code is (I think) fig-FORTH and needs to be updated to FORTH-83 for the systems I have around. Here is Schorre's complete code: : internal current @ @ ; : external here ; : module pfa lfa ! ; I think I understand how this is intended to work, and here's my translation to FORTH-83 (using Harris's proposed words for definition field address conversion): : internal current @ @ ; : external here ; : module n>link ! ; My problem is that, while Harris's words seem to be a de facto standard (all my systems have them), this code only works on one system: Laboratory Microsystems PC/FORTH. It fails to work under F83 and F83S, and also under F-PC (version 2.something). Here's an example of the use of these words, to create a global variable that's private to three routines that use it for communication: internal variable foo external : reset 0 foo ! ; : inc 1 foo +! ; : hmm foo @ . ; module The idea is that foo is only visible to the three words after external, because module has adjusted the dictionary links to jump over foo. And sure enough, under PC/FORTH, the three words can find foo, though it doesn't show up in the dictionary anymore. In F83 and F83S, however, the three words can find foo, but it never vanishes from the dictionary! Exactly the same thing occurs with F-PC. Strangely enough, the system doesn't crash, even though I don't know where I'm storing that address... Can anyone tell me what the difference is between these systems that explains this? I realize that this sort of dictionary manipulation isn't really in line with the 83 standard (which I think is too bad), but I didn't think I'd have this much trouble with such a simple idea. My two guesses as to where my problem lies are as follows: lack of understanding of current (what exactly *does* it point to, anyway? This is not at all clear from the standard document.), or perhaps a problem with hashed dictionaries? Thanks in advance, Keith References: Felleisen, M. and D. P. Friedman. 1986. ``A Closer Look at Export and Import Statements''. *Computer Languages* (11), pp. 29-37. Schorre, Dewey Val. 1980. ``Adding Modules to Forth''. *Proceedings of the 1980 FORML Conference*, p. 71. -- Keith WACLENA keith@curry.uchicago.edu CILS / TIRA / U of Chicago keith%curry@uchimvs1.bitnet 1100 E.57th.St Chi IL 60637 USA ...!uunet!curry.uchicago.edu!keith