Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #43682 > unrolled thread

description of Forth-2012's `synonym`

Started byMarcos Cruz <use_the_contact_page@programandala.net>
First post2015-11-23 20:47 +0000
Last post2015-11-26 14:39 -0800
Articles 9 on this page of 29 — 9 participants

Back to article view | Back to comp.lang.forth


Contents

  description of Forth-2012's `synonym` Marcos Cruz <use_the_contact_page@programandala.net> - 2015-11-23 20:47 +0000
    Re: description of Forth-2012's `synonym` Bernd Paysan <bernd.paysan@gmx.de> - 2015-11-23 22:55 +0100
      Re: description of Forth-2012's `synonym` Marcos Cruz <use_the_contact_page@programandala.net> - 2015-11-23 22:20 +0000
        Re: description of Forth-2012's `synonym` anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-11-24 05:12 +0000
      Re: description of Forth-2012's `synonym` Marcos Cruz <use_the_contact_page@programandala.net> - 2015-11-24 17:29 +0000
        Re: description of Forth-2012's `synonym` Bernd Paysan <bernd.paysan@gmx.de> - 2015-11-25 02:46 +0100
          Re: description of Forth-2012's `synonym` Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-11-24 22:46 -0800
            Re: description of Forth-2012's `synonym` Mark Wills <markwills1970@gmail.com> - 2015-11-25 01:39 -0800
              Re: description of Forth-2012's `synonym` Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-11-25 02:37 -0800
            Re: description of Forth-2012's `synonym` anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-11-25 13:13 +0000
              Re: description of Forth-2012's `synonym` Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-11-25 09:06 -0800
                Re: description of Forth-2012's `synonym` anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-11-25 18:33 +0000
                  Re: description of Forth-2012's `synonym` Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-11-25 23:01 -0800
                    Re: description of Forth-2012's `synonym` anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-11-26 07:15 +0000
                      Re: description of Forth-2012's `synonym` Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-11-26 02:30 -0800
                        Re: description of Forth-2012's `synonym` anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-11-26 13:44 +0000
              Re: description of Forth-2012's `synonym` Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2015-11-25 17:27 +0000
                Re: description of Forth-2012's `synonym` anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-11-26 07:56 +0000
                  Re: description of Forth-2012's `synonym` Albert van der Horst <albert@spenarnc.xs4all.nl> - 2015-11-26 11:25 +0000
                  Re: description of Forth-2012's `synonym` Bernd Paysan <bernd.paysan@gmx.de> - 2015-11-27 01:36 +0100
                    Re: description of Forth-2012's `synonym` Albert van der Horst <albert@spenarnc.xs4all.nl> - 2015-11-27 16:57 +0000
                      Re: description of Forth-2012's `synonym` Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2015-11-27 19:18 +0000
                        Re: description of Forth-2012's `synonym` Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2015-11-27 19:22 +0000
                          Re: description of Forth-2012's `synonym` Mark Wills <markwills1970@gmail.com> - 2015-11-27 11:48 -0800
                    Re: description of Forth-2012's `synonym` anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-11-28 11:07 +0000
                      Re: description of Forth-2012's `synonym` Matthias Trute <matthias.trute@gmail.com> - 2015-11-28 12:34 -0800
        Re: description of Forth-2012's `synonym` hughaguilar96@gmail.com - 2015-11-26 18:43 -0800
          Re: description of Forth-2012's `synonym` Marcos Cruz <use_the_contact_page@programandala.net> - 2015-12-05 03:35 +0000
      Re: description of Forth-2012's `synonym` hughaguilar96@gmail.com - 2015-11-26 14:39 -0800

Page 2 of 2 — ← Prev page 1 [2]


#43869

FromAlbert van der Horst <albert@spenarnc.xs4all.nl>
Date2015-11-27 16:57 +0000
Message-ID<56588b81$0$23839$e4fe514c@news.xs4all.nl>
In reply to#43853
Bernd Paysan <bernd.paysan@gmx.de> writes:

>Anton Ertl wrote:

>> I think the solution is to have FIND-NAME ( c-addr u -- nt | 0 ) and
>> something like Gforth's (SEARCH-WORDLIST) ( c-addr u wid -- nt | 0 )
>> (but with a better name).

>I'm suggesting

>FIND-NAME-IN ( c-addr u wid -- nt | 0 )

Everything with NAME in it is bad. It is meant to be searching for a
NAME-token (which is a bad name, should be dea) but it is interpreted
as looking for the *name* `` c-addr u''.
Apart from having two hyphens this ambiguousness kills it for me.

>as in "find name in <wordlist>".  (search-wordlist) is too ugly and way too
>useful to stay that ugly ;-).

I go for FOUND and (FOUND).

>--
>Bernd Paysan
>"If you want it done right, you have to do it yourself"
>net2o ID: kQusJzA;7*?t=uy@X}1GWr!+0qqp_Cn176t4(dQ*
>http://bernd-paysan.de/
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#43880

FromGerry Jackson <gerry@jackson9000.fsnet.co.uk>
Date2015-11-27 19:18 +0000
Message-ID<n3aa64$sjt$1@dont-email.me>
In reply to#43869
On 27/11/2015 16:57, Albert van der Horst wrote:
> Bernd Paysan <bernd.paysan@gmx.de> writes:
>
>> Anton Ertl wrote:
>
>>> I think the solution is to have FIND-NAME ( c-addr u -- nt | 0 ) and
>>> something like Gforth's (SEARCH-WORDLIST) ( c-addr u wid -- nt | 0 )
>>> (but with a better name).
>
>> I'm suggesting
>
>> FIND-NAME-IN ( c-addr u wid -- nt | 0 )
>
> Everything with NAME in it is bad. It is meant to be searching for a
> NAME-token (which is a bad name, should be dea) but it is interpreted
> as looking for the *name* `` c-addr u''.
> Apart from having two hyphens this ambiguousness kills it for me.
>
>> as in "find name in <wordlist>".  (search-wordlist) is too ugly and way too
>> useful to stay that ugly ;-).
>
> I go for FOUND and (FOUND).
>

I've called it FIND-NAME in my system because that's what it does. FOUND 
is awful.


-- 
Gerry

[toc] | [prev] | [next] | [standalone]


#43881

FromGerry Jackson <gerry@jackson9000.fsnet.co.uk>
Date2015-11-27 19:22 +0000
Message-ID<n3aac4$t65$1@dont-email.me>
In reply to#43880
On 27/11/2015 19:18, Gerry Jackson wrote:
> On 27/11/2015 16:57, Albert van der Horst wrote:
>> Bernd Paysan <bernd.paysan@gmx.de> writes:
>>
>>> Anton Ertl wrote:
>>
>>>> I think the solution is to have FIND-NAME ( c-addr u -- nt | 0 ) and
>>>> something like Gforth's (SEARCH-WORDLIST) ( c-addr u wid -- nt | 0 )
>>>> (but with a better name).
>>
>>> I'm suggesting
>>
>>> FIND-NAME-IN ( c-addr u wid -- nt | 0 )
>>
>> Everything with NAME in it is bad. It is meant to be searching for a
>> NAME-token (which is a bad name, should be dea) but it is interpreted
>> as looking for the *name* `` c-addr u''.
>> Apart from having two hyphens this ambiguousness kills it for me.
>>
>>> as in "find name in <wordlist>".  (search-wordlist) is too ugly and
>>> way too
>>> useful to stay that ugly ;-).
>>
>> I go for FOUND and (FOUND).
>>
>
> I've called it FIND-NAME in my system because that's what it does. FOUND
> is awful.
>
>
Calling it FOUND presupposes that the name will be found. I don't like 
INCLUDED either but we're stuck with it.

-- 
Gerry

[toc] | [prev] | [next] | [standalone]


#43882

FromMark Wills <markwills1970@gmail.com>
Date2015-11-27 11:48 -0800
Message-ID<3d69a139-6778-4490-8108-3db94ad0978a@googlegroups.com>
In reply to#43881
How about FOUND?

I.e with a question mark. 

[toc] | [prev] | [next] | [standalone]


#43894

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2015-11-28 11:07 +0000
Message-ID<2015Nov28.120751@mips.complang.tuwien.ac.at>
In reply to#43853
Bernd Paysan <bernd.paysan@gmx.de> writes:
>Anton Ertl wrote:
>
>> I think the solution is to have FIND-NAME ( c-addr u -- nt | 0 ) and
>> something like Gforth's (SEARCH-WORDLIST) ( c-addr u wid -- nt | 0 )
>> (but with a better name).
>
>I'm suggesting
>
>FIND-NAME-IN ( c-addr u wid -- nt | 0 )
>
>as in "find name in <wordlist>".

I like it.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2015: http://www.rigwit.co.uk/EuroForth2015/

[toc] | [prev] | [next] | [standalone]


#43913

FromMatthias Trute <matthias.trute@gmail.com>
Date2015-11-28 12:34 -0800
Message-ID<8c3adb9c-9119-459f-8d8d-7e3efced60b0@googlegroups.com>
In reply to#43894
> >> I think the solution is to have FIND-NAME ( c-addr u -- nt | 0 ) and
> >> something like Gforth's (SEARCH-WORDLIST) ( c-addr u wid -- nt | 0 )
> >> (but with a better name).
> >
> >I'm suggesting
> >
> >FIND-NAME-IN ( c-addr u wid -- nt | 0 )
> >
> >as in "find name in <wordlist>".
> 
> I like it.

in amforth I have find-name ( addr len -- nt|0) 
and search-name ( addr len wid -- nt|0).

Matthias

[toc] | [prev] | [next] | [standalone]


#43855

Fromhughaguilar96@gmail.com
Date2015-11-26 18:43 -0800
Message-ID<dd2c891b-ed67-4569-83c4-326f5e0eaee6@googlegroups.com>
In reply to#43709
On Tuesday, November 24, 2015 at 10:29:29 AM UTC-7, Marcos Cruz wrote:
> En/Je/On 2015-11-23, Bernd Paysan <bernd.paysan@gmx.de>
> escribió/skribis/wrote:
> 
> >> ----
> >> : synonym  ( "newname" "oldname" -- )
> >>   create immediate
> >>     hide ' , reveal
> >>   does>  ( -- )
> >>    ( pfa ) @ ( cfa ) dup >name dup ( cfa nfa nfa )
> >>    compile-only? executing? and -14 ?throw
> >>    immediate? executing? or
> >>    if  execute  else  compile,  then  ;
> >> ----
> 
> > The more problematic part is that you are using create does> for it.  Just 
> > think what will happen with ' <newname> execute.
> 
> What do you mean? I've tried synonyms of `if`, `postpone`, `literal`,
> non-immediate words..., and everything seems to work fine: the synonym
> has the semantics of the original.
> ...
> Am I missing something?

Well, I didn't test your code because it is Forth-200x and uses a lot of Forth-200x enhancements, but I only have ANS-Forth compilers available to me. It looks like it should work. The problem with this is that >BODY won't work on it, so if Bernd wanted to beat you up for something that would be it, but he didn't notice this problem --- what he said about ' xxx EXECUTE not working was not true.

Note that you are depending upon ' to work for all words, but it doesn't in ANS-Forth, and I never heard of the problem being fixed in Forth-200x --- you need the disambiguifiers in order to assure that ' works correctly.

You are also doing a lot of checking of stuff at run-time (in the DOES> part of your word), but this stuff is known at compile-time --- that makes your code somewhat inefficient.

For the most part though, I think that you are programming reasonably well. :-)

Here is my ALIAS word (comments removed for brevity):

1234512345 constant alias-id  

0
    w field alias.xt  
    w field alias.adr 
    w field alias.id  
constant alias-struct

: alias ( wid -- )                          \ stream: new-name old-name     
    get-current  swap set-current  create  set-current
        here >r  alias-struct allot
        'find if  immediate  then   r@ alias.xt !
        r@                          r@ alias.adr !
        alias-id                    r@ alias.id !
        rdrop
    does>
        alias.xt @  execute ;

: >body ( xt -- adr )
    >body >r
    r@ alias.adr @  r@ = if  r@ alias.id @  alias-id = if 
        r> alias.xt @  >body  exit then then
            r> ;                                                                    

Any use of CREATE DOES> results in slow code, especially in SwiftForth. Because of this, I originally did not use CREATE DOES> at all. The downside was that >BODY didn't work, but I almost never use CREATE DOES> so I didn't care that >BODY didn't work. ALIAS is only for people who use CREATE DOES> and care about >BODY working, but otherwise SYNONYM or SYNONYM-FAST should be used.

: :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                  
    bl word find  dup 0= abort" *** 'FIND couldn't find the word ***" ;

: synonym { wid | new -- }                  \ stream: new-name old-name    
    bl word hstr to new  
    'find  new  wid :synonym
    new dealloc ;

: synonym-fast { wid | new -- }             \ stream: new-name old-name 
    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.

[toc] | [prev] | [next] | [standalone]


#44071

FromMarcos Cruz <use_the_contact_page@programandala.net>
Date2015-12-05 03:35 +0000
Message-ID<n3tm1m$jr5$1@speranza.aioe.org>
In reply to#43855
En/Je/On 2015-11-27, hughaguilar96@gmail.com <hughaguilar96@gmail.com>
escribió/skribis/wrote:

> On Tuesday, November 24, 2015 at 10:29:29 AM UTC-7, Marcos Cruz wrote:

>> >> ----
>> >> : synonym  ( "newname" "oldname" -- )
>> >>   create immediate
>> >>     hide ' , reveal
>> >>   does>  ( -- )
>> >>    ( pfa ) @ ( cfa ) dup >name dup ( cfa nfa nfa )
>> >>    compile-only? executing? and -14 ?throw
>> >>    immediate? executing? or
>> >>    if  execute  else  compile,  then  ;
>> >> ----

> Well, I didn't test your code because it is Forth-200x and uses a lot
> of Forth-200x enhancements, but I only have ANS-Forth compilers

No Forth-200x enhancements, but just some common use or internal words.
No intention to make this `synonym` portable, even if it were possible.

> You are also doing a lot of checking of stuff at run-time (in the
> DOES> part of your word), but this stuff is known at compile-time ---
> that makes your code somewhat inefficient.

Right.  The nt, and two flags are calculated.  But this implementation
is for a Z80, and saving some cells in every possible word created by
`synonym` could be as important as saving some run-time operation (a
more powerful platform eliminates such dilemmas).  Beside, if those
values were calculated at compile-time, they should be fetched at
run-time. I'm not sure if it would be faster in this case, but it seems
an intereresting benchmark.

Anyway, the system already provides a classic `alias` which is much more
efficient,

----
: code-alias?  ( cfa -- wf )  @ dup body> @ =  ;
  \ Is _cfa_ a word created by `code-alias` or `code`?

: defer-alias  ( cfa "name" -- )
  defer latest name> defer!  ;
  \ Create a deferred word _name_ that executes _cfa_.

: code-alias  ( cfa "name" -- )
  @ header reveal latest name> !  ;
  \ Create a code word that executes the code pointed by _cfa_.

: alias  ( cfa "name" -- )
  dup code-alias? if  code-alias exit  then  defer-alias  ;
----

It's based on an implementation of `defer` that creates a machine code
jump into the inner interpreter:

----
  _colon_header defer_,'DEFER'

; defer  ( "name" -- )

  dw header_,reveal_
  _literal 0x21           ; Z80 opcode for `ld hl,NN`
  dw c_comma_
  _literal paren_defer_   ; default cfa to execute
  dw comma_
  _literal 0xC3           ; Z80 opcode for `jp NN`
  dw c_comma_
  _literal next2          ; address to jump to
  dw comma_
  dw exit_
---

-- 
Marcos Cruz
http://programandala.net

[toc] | [prev] | [next] | [standalone]


#43850

Fromhughaguilar96@gmail.com
Date2015-11-26 14:39 -0800
Message-ID<7b7bab23-010a-48bd-812c-c437f5c33efb@googlegroups.com>
In reply to#43686
On Monday, November 23, 2015 at 2:55:13 PM UTC-7, Bernd Paysan wrote:
> Marcos Cruz wrote:
> 
> > I have a doubt about the description of `synonym`:
> ...
> This word just can't be 
> implemented using standard means, which is why we added it.

Bernd Paysan, you are a liar! I have already implemented SYNONYM SYNONYM-FAST and ALIAS in ANS-Forth --- this is trivial with the disambiguifiers available. This was here:
https://groups.google.com/forum/#!topic/comp.lang.forth/oXXQAGDKP7w%5B1-25%5D

Bernd Paysan, you are incompetent at Forth programming. Your greatest crime however, is that you use your position on the Forth-200x committee to project your incompetence onto the entire Forth community. You failed to implement quotations, but then you faked it by writing a "quotation" that lacks access to the parent function's locals, so it isn't a quotation at all. You are doing the same thing here --- you are just too incompetent to implement SYNONYM in ANS-Forth and so you declare that it is impossible. 

The code that you say is impossible I can write in 10 minutes --- you just aren't any good at Forth programming --- worse than incompetent though, is that you are a liar and you strive continuously to conceal your incompetence by projecting your own failures onto the entire Forth community.

Bernd Paysan is the face of Forth-200x --- incompetent and deceitful --- this is what Forth-200x is all about.

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.forth


csiph-web