Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!samsung!uakari.primate.wisc.edu!crdgw1!sunbelt!eaker From: eaker@sunbelt.crd.ge.com (Charles E Eaker) Newsgroups: comp.lang.forth Subject: Re: redefining words Message-ID: <10838@crdgw1.crd.ge.com> Date: 7 Aug 90 18:05:09 GMT References: <9008070137.AA00402@ucbvax.Berkeley.EDU> Sender: news@crdgw1.crd.ge.com Organization: General Electric Corporate R&D Center Lines: 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