boris@prodigal.psych.rochester.edu (Boris "cull" Goldowsky) (08/05/90)
I've got an application where the definitions of words may be changed many times, and I'd like the new definition to actually replace the old one rather than simply being tacked on for future use. Is there any "standard" way to remove/replace words and reclaim the dictionary space for them? In a similar vein, does anyone have a forth memory allocator/freeer? Bng Boris Goldowsky The only way you'll end up in a corner Is by walking in too straight of a li boris@prodigal.psych.rochester.edu --Claudia Schmidt n boris%prodigal@uordbv.BITNET e
wmb@MITCH.ENG.SUN.COM (08/07/90)
> I've got an application where the definitions of words may be changed > many times, and I'd like the new definition to actually replace the > old one rather than simply being tacked on for future use. Is there > any "standard" way to remove/replace words and reclaim the dictionary > space for them? No. Some (not many) systems have this capability, but as far as I know there is no "common practice" in this area (other than FORGETting back to a certain point and reloading everything after that). The most common scheme for replacing the definition of a word is called "vectored execution", but it does not accomplish the aim of reclaiming the dictionary space used by the old definition. Vectored execution works as follows: VARIABLE 'FOO : FOO 'FOO @ EXECUTE ; To set the action performed by FOO , say to BAR , you execute ' BAR FOO ! Some systems have a built-in mechanism for doing this, e.g.: DEFER FOO ' BAR IS FOO Another common technique is the DOER ... MAKE construct described in _Thinking Forth_ . Personally, I do not like DOER ... MAKE because it adds yet another non-postfix syntactic construct to Forth. Mitch
eaker@sunbelt.crd.ge.com (Charles E Eaker) (08/08/90)
In article <9008070137.AA00402@ucbvax.Berkeley.EDU> wmb%MITCH.ENG.SUN.COM@SCFVM.GSFC.NASA.GOV writes: >Vectored execution works as follows: > > VARIABLE 'FOO > : FOO 'FOO @ EXECUTE ; > >To set the action performed by FOO , say to BAR , you execute > > ' BAR FOO ! > >Some systems have a built-in mechanism for doing this, e.g.: > > DEFER FOO > ' BAR IS FOO > >Another common technique is the DOER ... MAKE construct described in >_Thinking Forth_ . Personally, I do not like DOER ... MAKE because it >adds yet another non-postfix syntactic construct to Forth. I'm surprised you feel this way. The DOER...MAKE construct strikes me as being no more non-postfix than the _double_ non-postfixedness (??) of both ' and IS with DEFER. As I recall, DOER and DEFER are semantically equivalent, so your example above would be: DEFER FOO MAKE FOO BAR which I find slightly less opaque. Furthermore, the DOER...MAKE construct is far more versatile. For example, if BAR were: : BAR ." This is BAR executing." ; then the above MAKE line could be replaced with: MAKE FOO ." This is BAR executing." ; avoiding the need to add BAR to the dictionary. In addition, MAKE can be used in colon definitions of words that set DOER (or DEFER) variables that model, in a straight-forward way, state machines with actions associated with transitions (the Mealy model, I believe). Finally (although Leo Brodie lists several more uses in the work you cite), your prefered definitions of [ and ] would be slightly less ugly with the DOER ... MAKE construct. Instead of : : [ ( switch to interpretive mode ) ['] (literal? ['] literal? (is ['] interpret-do-defined ['] do-defined (is ['] interpret-do-literal ['] do-literal (is ['] interpret-do-undefined ['] do-undefined (is state off ; immediate : ] ( switch to compiling mode ) ['] (literal? ['] literal? (is ['] compile-do-defined ['] do-defined (is ['] compile-do-literal ['] do-literal (is ['] compile-do-undefined ['] do-undefined (is state on ; they would be: : [ ( switch to interpretive mode ) make literal? (literal? ;and make do-defined interpret-do-defined ;and make do-literal interpret-do-literal ;and make do-undefined interpret-do-undefined ;and state off ; immediate : ] ( switch to compiling mode ) make literal? (literal? ;and make do-defined compile-do-defined ;and make do-literal compile-do-literal ;and make do-undefined compile-do-undefined ;and state on ; As an aside to others on the net, I have heard that Prentice-Hall is letting _Thinking Forth_ go out of print. To anyone who doesn't have a copy, I urge you to try and find one before it's too late. In my opinion, the chapters on factoring and execution vectors are each well worth the price of the book. Chuck Eaker / P.O. Box 8, K-1 3C12 / Schenectady, NY 12301 USA eaker@sungod.crd.ge.com eaker@crdgw1.UUCP (518) 387-5964 -- Chuck Eaker | eaker@sunbelt.crd.ge.com GE Corporate Research & Development Center | eaker@crdgw1.UUCP P.O. Box 8, K-1 3C12 | (518) 387-5964 Schenectady, NY 12301 USA | DialComm 8*833-5964