On Monday, October 29, 2018 at 11:39:35 AM UTC-7,
hughag...@gmail.com wrote:
> Here is another interesting quote:
>
> On Thursday, April 2, 2015 at 10:07:52 AM UTC-7, Stephen Pelc wrote:
> > On Wed, 1 Apr 2015 13:40:52 -0700 (PDT),
hughag...@gmail.com
> > wrote:
> > >So how do you write SYNONYM so that it can make a synonym of an immediate word?
> >
> > The VFX source code is:
> >
> > : SynComp, \ xt --
> > \ Compile a child of SYNONYM.
> > >body @ compile,
> > ;
> >
> > : Synonym \ "<new-name>" "<curdef>" --
> > \ *G Create a new definition which redirects to an existing one.
> > \ ** Normal dictionary searches for *\i{<new-name>} will return
> > \ ** the xt of *\i{<curdef>}.
> > create
> > hide ' reveal dup , immediate?
> > if immediate endif
> > ['] SynComp, set-compiler
> > $010 latest set-bit \ set header's alias bit
> > interp>
> > @ execute
> > ;
> >
> > For some words you may have to RTFM.
> >
> > Stephen
>
> Cynical readers will notice that this code is not ANS-Forth. When Stephen Pelc (Forth-200x committee member) tells the plebian (Hugh Aguilar) to RTFM (Read The F'ing Manual), he is referring to the VFX manual. All of that code is VFX-specific. Stephen Pelc is trying to trap the VFX users into relying on vendor-specific code so they won't be able to port their code to competitor's ANS-Forth compilers --- vendor lock-in, of course, is what the standard is supposed to prevent!
>
> Alert readers will also notice this code has a bug in it. If SYNONYM is used to make a synonym of a word defined with CREATE and then >BODY is used on the synonym, >BODY will not return the body-address of the original word. I have read on comp.lang.forth that VFX has a new version that fixes this bug. I haven't bothered to download the new version however, so I haven't verified this. The more important problem is that Stephen Pelc is refusing to acknowledge the existence of the disambiguifiers and he is insisting that a word such as SYNONYM "requires carnal knowledge."
>
> On Thursday, April 2, 2015 at 11:42:55 PM UTC-7, Stephen Pelc wrote:
> > On Thu, 2 Apr 2015 19:18:04 -0700 (PDT),
hughag...@gmail.com
> > wrote:
> > >This is not ANS-Forth code --- I don't want to RTFM because I don't want to
> > > become an expert on VFX --- I'm already an expert on ANS-Forth.
> >
> > You asked a tech-support question about VFX. I answered it pointing
> > out that your initial assumption (how IF works) was wrong.
> >
> > The code illustrates precisely why SYNONYM is defined the way it is
> > defined - because it requires carnal knowledge. If you want to know
> > how SYNONYM works:
> > "So how do you write SYNONYM so that it can make a synonym of an
> > immediate word?"
> > then do not complain when you are told.
> >
> > Stephen
>
> My assumption about IF was that it was immediate. This is sometimes right (SwiftForth) and sometimes wrong (VFX). The ambiguity of ANS-Forth, however, is meta-wrong --- ambiguity such as this is absurd --- ANS-Forth is a standard that doesn't standardize.
>
> Stephen Pelc is an extremely arrogant person! He is trying hard to say that I'm incompetent and that I need to learn basic Forth programming from him.
> He is incompetent and should learn from me! He does not deserve to be the Forth-200x chair-person!
>
> Anyway, my SYNONYM SYNONYM-FAST and ALIAS are all ANS-Forth and they all support immediate words. They depend upon the disambiguifiers to work:
> -----------------------------------------------------------------------
> : oink postpone if ; immediate ok
> : test oink ." true" else ." false" then ; ok
> 1 test true ok
> 0 test false ok
> get-current alias oinkA oink ok
> : testA oinkA ." true" else ." false" then ; ok
> 1 testA true ok
> 0 testA false ok
> get-current synonym oinkS oink ok
> : testS oinkS ." true" else ." false" then ; ok
> 1 testS true ok
> 0 testS false ok
> get-current synonym-fast oinkFS oink ok
> : testFS oinkFS ." true" else ." false" then ; ok
> 1 testFS true ok
> 0 testFS false ok
> -----------------------------------------------------------------------
>
> Also, ALIAS supports >BODY correctly, which Stephen Pelc's non-standard code shown above failed to support:
> -----------------------------------------------------------------------
> create foo 1234 , ok
> get-current alias bar foo ok
> foo @ . 1234 ok
> bar @ . 1234 ok
> ' foo >body @ . 1234 ok
> ' bar >body @ . 1234 ok
> foo . 5167168 ok
> bar . 5167168 ok
> ok
> 5678 foo ! ok
> foo @ . 5678 ok
> bar @ . 5678 ok
> ' foo >body @ . 5678 ok
> ' bar >body @ . 5678 ok
> -----------------------------------------------------------------------
Stephen Pelc still doesn't know how to write SYNONYM in ANS-Forth!
He says:
On Wednesday, September 18, 2019 at 12:31:34 PM UTC-7, Stephen Pelc wrote:
> On Tue, 17 Sep 2019 12:16:40 -0700 (PDT),
m...@iae.nl wrote:
>
> >I'll bite. Why do I want SYNONYM, and what are those interesting new
> >features" ?
>
> I want SYNONYM when a porting code that uses WORD1 when the same
> behaviour is provided in my system by WORD2.
> SYNONYM WORD1 WORD2
>
> That's all. I regret that SYNONYM lead to nts and so on. Mea culpa.
> As always, be careful what you wish for.
>
> Stephen
Here is the ANS-Forth code (that depends upon having disambiguifiers
already loaded). There are no NTs and so on.
--------------------------------------------------------------------
\ ******
\ ****** Our SYNONYM SYNONYM-FAST and ALIAS words --- these depend upon having the disambiguifiers available.
\ ******
: :synonym { xt flg str wid -- } \ FLG is 1 for immediate and -1 for non-immediate
str wid :name
flg 1 = if xt lit, execute, ;, immediate exit then
flg -1 = if xt compile, ;, exit then
true abort" *** :SYNONYM given an invalid xt ***" ;
: :synonym-fast-check ( -- )
state @ 0= abort" *** a word created by :SYNONYM-FAST can't be used in interpretive mode ***" ;
: :synonym-fast { xt flg str wid -- } \ FLG is 1 for immediate and -1 for non-immediate
str wid :name
flg 1 = if xt lit, execute, ;, immediate exit then
flg -1 = if postpone :synonym-fast-check
xt lit, postpone compile, ;, immediate exit then
true abort" *** :SYNONYM-FAST given an invalid xt ***" ;
: 'find ( -- xt flg ) \ stream: name \ FLG is 1 for immediate and -1 for non-immediate
bl word find dup 0= abort" *** 'FIND couldn't find the word ***" ;
: synonym { wid | new -- } \ stream: new-name old-name \ the new word is compiled into the WID word-list
bl word hstr to new
'find new wid :synonym
new dealloc ;
: synonym-fast { wid | new -- } \ stream: new-name old-name \ the new word is compiled into the WID word-list
bl parse <hstr> to new
'find new wid :synonym-fast
new dealloc ;
\ :SYNONYM-FAST generates faster executing code than :SYNONYM but the words can't be used in interpretive mode.
\ This may not be necessary with a good optimizing compiler, but I'm not aware of any at this time.
1234512345 constant alias-id \ an arbitrary number used to identify alias'd definitions
0
w field alias.xt \ this should be the first field so the DOES> portion of ALIAS will be fast (no addition needed)
w field alias.adr \ the address of the body, used to identify alias'd definitions
w field
alias.id \ the constant ALIAS-ID, used to identify alias'd definitions
constant alias-struct
: alias ( wid -- ) \ stream: new-name old-name \ the new word is compiled into the WID word-list
get-current swap set-current create set-current
here >r alias-struct allot
'find 1 = if immediate then r@ alias.xt !
r@ r@ alias.adr !
alias-id r@
alias.id !
rdrop
does>
alias.xt @ execute ;
\ ALIAS does the same thing as SYNONYM but has the advantage that ' ['] and >BODY will work on it.
\ It is slower executing though (especially under SwiftForth in which CREATE DOES> words are very inefficient).
: ' ( -- xt ) \ stream: name
' \ -- xt
dup >body >r
r@ alias.adr @ r@ = if r@
alias.id @ alias-id = if \ is this an alias'd word?
drop r> alias.xt @ exit then then \ return the xt of the original word
rdrop ;
: ['] ( -- ) \ stream: name \ runtime: -- xt
' postpone literal ; immediate
: >body ( xt -- adr )
>body >r
r@ alias.adr @ r@ = if r@
alias.id @ alias-id = if \ is this an alias'd word?
r> alias.xt @ >body exit then then \ return the body of the original word
r> ; \ return the body of this word
\ Note that >BODY still has an undefined result if used on a word that wasn't defined with CREATE or isn't an alias of such a word.
: special-macro: ( xt -- xt | 0 ) \ returns 0 if xt was special-cased
[ 'special-macro: @ ] literal execute dup 0= if exit then
case
['] ['] of postpone ['] postpone lit, 0 exit endof
exit endcase ; \ -- xt \ EXIT with xt if it was never special-cased
' special-macro: 'special-macro: !
\ We need to upgrade SPECIAL-MACRO: with our new ['] because the old one isn't valid anymore.
--------------------------------------------------------------------
On a related note, these quotes come from VFX's "tip of the day"
--------------------------------------------------------------------
"Never attribute to malice that which can be explained by stupidity."
Hanlon's Razor
"Stupidity maintained long enough is a form of malice."
Richard Bos's corollary to Hanlon's Razor.
--------------------------------------------------------------------