Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Truth has always been found to promote the best interests of mankind... -- Percy Bysshe Shelley


devel / comp.lang.forth / Another example of factoring and locals

SubjectAuthor
* Another example of factoring and localsAnton Ertl
`* Re: Another example of factoring and localsdxforth
 `* Re: Another example of factoring and localsAnton Ertl
  `* Re: Another example of factoring and localsdxforth
   `* Re: Another example of factoring and localsHans Bezemer
    `* Re: Another example of factoring and localsAnton Ertl
     `* Re: Another example of factoring and localsdxforth
      +* Re: Another example of factoring and localsPaul Rubin
      |+* Re: Another example of factoring and localsminf...@arcor.de
      ||+* Re: Another example of factoring and localsHans Bezemer
      |||+* Re: Another example of factoring and localsPaul Rubin
      ||||`* Re: Another example of factoring and localsdxforth
      |||| `* Re: Another example of factoring and localsPaul Rubin
      ||||  `* Re: Another example of factoring and localsdxforth
      ||||   `* Re: Another example of factoring and localsPaul Rubin
      ||||    +* Re: Another example of factoring and localsdxforth
      ||||    |+* Re: Another example of factoring and localsMarcel Hendrix
      ||||    ||`* Re: Another example of factoring and localsPaul Rubin
      ||||    || `* Re: Another example of factoring and localsdxforth
      ||||    ||  `- Re: Another example of factoring and localsMarcel Hendrix
      ||||    |+* Re: Another example of factoring and localsS Jack
      ||||    ||`- Re: Another example of factoring and localsdxforth
      ||||    |`* Re: Another example of factoring and localsPaul Rubin
      ||||    | +* Re: Another example of factoring and localsdxforth
      ||||    | |+* Re: Another example of factoring and localsPaul Rubin
      ||||    | ||+* Re: Another example of factoring and localsDoug Hoffman
      ||||    | |||+* Re: Another example of factoring and localsPaul Rubin
      ||||    | ||||+- Re: Another example of factoring and localsnone
      ||||    | ||||`* Re: Another example of factoring and localsDoug Hoffman
      ||||    | |||| +- Re: Another example of factoring and localsminf...@arcor.de
      ||||    | |||| +- Re: Another example of factoring and localsdxforth
      ||||    | |||| `* Re: Another example of factoring and localsdxforth
      ||||    | ||||  `* Re: Another example of factoring and localsDoug Hoffman
      ||||    | ||||   `* Re: Another example of factoring and localsdxforth
      ||||    | ||||    +- Re: Another example of factoring and localsHans Bezemer
      ||||    | ||||    +- Re: Another example of factoring and localsBrian Fox
      ||||    | ||||    +* Re: Another example of factoring and localsDoug Hoffman
      ||||    | ||||    |`* Re: Another example of factoring and localsdxforth
      ||||    | ||||    | `* Re: Another example of factoring and localsPaul Rubin
      ||||    | ||||    |  `* Re: Another example of factoring and localsdxforth
      ||||    | ||||    |   `* Re: Another example of factoring and localsPaul Rubin
      ||||    | ||||    |    `* Re: Another example of factoring and localsdxforth
      ||||    | ||||    |     `* Re: Another example of factoring and localsMarcel Hendrix
      ||||    | ||||    |      `* Re: Another example of factoring and localsdxforth
      ||||    | ||||    |       `* Re: Another example of factoring and localsPaul Rubin
      ||||    | ||||    |        `* Re: Another example of factoring and localsdxforth
      ||||    | ||||    |         `* Re: Another example of factoring and localsPaul Rubin
      ||||    | ||||    |          `* Re: Another example of factoring and localsdxforth
      ||||    | ||||    |           +* Re: Another example of factoring and localsMarcel Hendrix
      ||||    | ||||    |           |+- Re: Another example of factoring and localsdxforth
      ||||    | ||||    |           |`- Re: Another example of factoring and localsdxforth
      ||||    | ||||    |           `* Re: Another example of factoring and localsPaul Rubin
      ||||    | ||||    |            +* Re: Another example of factoring and localsminf...@arcor.de
      ||||    | ||||    |            |`* Re: Another example of factoring and localsMarcel Hendrix
      ||||    | ||||    |            | +- Re: Another example of factoring and localsminf...@arcor.de
      ||||    | ||||    |            | +- Re: Another example of factoring and localsminf...@arcor.de
      ||||    | ||||    |            | `* Re: Another example of factoring and localsAnton Ertl
      ||||    | ||||    |            |  +* Re: Another example of factoring and localsPaul Rubin
      ||||    | ||||    |            |  |+* Re: Another example of factoring and localsdxforth
      ||||    | ||||    |            |  ||`* Re: Another example of factoring and localsPaul Rubin
      ||||    | ||||    |            |  || `- Re: Another example of factoring and localsdxforth
      ||||    | ||||    |            |  |`* Re: Another example of factoring and localsAnton Ertl
      ||||    | ||||    |            |  | +- Re: Another example of factoring and localsdxforth
      ||||    | ||||    |            |  | `* Re: Another example of factoring and localsHans Bezemer
      ||||    | ||||    |            |  |  `* Re: Another example of factoring and localsAnton Ertl
      ||||    | ||||    |            |  |   `* Re: Another example of factoring and localsPaul Rubin
      ||||    | ||||    |            |  |    `- Re: Another example of factoring and localsdave thompson 2
      ||||    | ||||    |            |  `* Re: Another example of factoring and localsMarcel Hendrix
      ||||    | ||||    |            |   `* Re: Another example of factoring and localsAnton Ertl
      ||||    | ||||    |            |    `* Re: Another example of factoring and localsPaul Rubin
      ||||    | ||||    |            |     +- Re: Another example of factoring and localsnone
      ||||    | ||||    |            |     `- Re: Another example of factoring and localsAnton Ertl
      ||||    | ||||    |            +* Re: Another example of factoring and localsAnton Ertl
      ||||    | ||||    |            |+- Re: Another example of factoring and localsnone
      ||||    | ||||    |            |`- Re: Another example of factoring and localsdxforth
      ||||    | ||||    |            +- Re: Another example of factoring and localsnone
      ||||    | ||||    |            +* Re: Another example of factoring and localsdxforth
      ||||    | ||||    |            |+- Re: Another example of factoring and localsminf...@arcor.de
      ||||    | ||||    |            |`* Re: Another example of factoring and localsHans Bezemer
      ||||    | ||||    |            | `* Re: Another example of factoring and localsminf...@arcor.de
      ||||    | ||||    |            |  +* Re: Another example of factoring and localsAnton Ertl
      ||||    | ||||    |            |  |`* Re: Another example of factoring and localsminf...@arcor.de
      ||||    | ||||    |            |  | +* Re: Another example of factoring and localsPaul Rubin
      ||||    | ||||    |            |  | |+- Re: Another example of factoring and localsminf...@arcor.de
      ||||    | ||||    |            |  | |`- Re: Another example of factoring and localsAnton Ertl
      ||||    | ||||    |            |  | `* Re: Another example of factoring and localsAnton Ertl
      ||||    | ||||    |            |  |  `- Re: Another example of factoring and localsminf...@arcor.de
      ||||    | ||||    |            |  `* Re: Another example of factoring and localsdxforth
      ||||    | ||||    |            |   `* Re: Another example of factoring and localsAnton Ertl
      ||||    | ||||    |            |    `* Re: Another example of factoring and localsdxforth
      ||||    | ||||    |            |     `* Re: Another example of factoring and localsAnton Ertl
      ||||    | ||||    |            |      +* Re: Another example of factoring and localsdxforth
      ||||    | ||||    |            |      |`* Re: Another example of factoring and localsAnton Ertl
      ||||    | ||||    |            |      | `* Re: Another example of factoring and localsdxforth
      ||||    | ||||    |            |      |  +* Re: Another example of factoring and localsMarcel Hendrix
      ||||    | ||||    |            |      |  |`- Re: Another example of factoring and localsdxforth
      ||||    | ||||    |            |      |  +* Re: Another example of factoring and localsAnton Ertl
      ||||    | ||||    |            |      |  |`* Re: Another example of factoring and localsdxforth
      ||||    | ||||    |            |      |  | `* Re: Another example of factoring and localsnone
      ||||    | ||||    |            |      |  |  `- Re: Another example of factoring and localsdxforth
      ||||    | ||||    |            |      |  `* Re: Another example of factoring and localsPaul Rubin
      ||||    | ||||    |            |      `* Re: Another example of factoring and localsnone
      ||||    | ||||    |            +* Re: Another example of factoring and localsLars Brinkhoff
      ||||    | ||||    |            `* Re: Another example of factoring and localsdxforth
      ||||    | ||||    +- Re: Another example of factoring and localsHans Bezemer
      ||||    | ||||    +* Re: Another example of factoring and localsMarcel Hendrix
      ||||    | ||||    +- Re: Another example of factoring and localsHans Bezemer
      ||||    | ||||    +- Re: Another example of factoring and localsP Falth
      ||||    | ||||    `- Re: Another example of factoring and localsminf...@arcor.de
      ||||    | |||`* Re: Another example of factoring and localsHans Bezemer
      ||||    | ||+- Re: Another example of factoring and localsdxforth
      ||||    | ||`* Re: Another example of factoring and localsHans Bezemer
      ||||    | |`- Re: Another example of factoring and localsnone
      ||||    | +- Re: Another example of factoring and localsStephen Pelc
      ||||    | `* Re: Another example of factoring and localsantispam
      ||||    +- Re: Another example of factoring and localsHans Bezemer
      ||||    `- Re: Another example of factoring and localsHans Bezemer
      |||`* Re: Another example of factoring and localsGerry Jackson
      ||`* Re: Another example of factoring and localsPaul Rubin
      |+- Re: Another example of factoring and localsHans Bezemer
      |`* Re: Another example of factoring and localsdxforth
      `* Re: Another example of factoring and localsHans Bezemer

Pages:123456789
Another example of factoring and locals

<2022Oct26.225153@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20908&group=comp.lang.forth#20908

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Another example of factoring and locals
Date: Wed, 26 Oct 2022 20:51:53 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 111
Message-ID: <2022Oct26.225153@mips.complang.tuwien.ac.at>
Injection-Info: reader01.eternal-september.org; posting-host="2d4370d8aad412075931e34a45c45196";
logging-data="2687463"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185grxi4P+kFFZc6XyLx0+d"
Cancel-Lock: sha1:KIMj6Di1fUKpsVQWMVE7Sx3wxjU=
X-newsreader: xrn 10.11
 by: Anton Ertl - Wed, 26 Oct 2022 20:51 UTC

Today I rewrote SEE-CODE (actually it's factor SEE-CODE-RANGE) to
display, e.g.

this instead of this
.... ...
$7F7E43202948 r> 1->1 $7F7E43202948 r> 1->1
7F7E42ECADE4: mov [r15],r8 $7F7E43202950 fill
7F7E42ECADE7: sub r15,$08 7F7E42ECADE4: mov [r15],r8
7F7E42ECADEB: mov r8,[rbx] 7F7E42ECADE7: sub r15,$08
7F7E42ECADEE: add r13,$08 7F7E42ECADEB: mov r8,[rbx]
7F7E42ECADF2: add rbx,$08 7F7E42ECADEE: add r13,$08
7F7E42ECADF6: mov rcx,-$08[r13] 7F7E42ECADF2: add rbx,$08
7F7E42ECADFA: jmp ecx 7F7E42ECADF6: mov rcx,-$08[r13]
7F7E42ECADFC: nop 7F7E42ECADFA: jmp ecx
$7F7E43202950 fill 7F7E42ECADFC: nop
$7F7E43202958 ;s 1->1 $7F7E43202958 ;s 1->1
.... ...

I had to get some additional information from the decompiler
primitive, so we now have

decompile-prim2 ( a_code -- useqlen ustart uend c_addr u ulen )

instead of

decompile-prim ( a_code -- ustart uend c_addr u ulen )

but the existing factoring also was not very amenable to the change,
so I rewrote SEE-CODE-RANGE from scratch, with the following result:

: see-code-range { addr1 addr2 -- } \ gforth
addr1 0 0 0 ['] noop case { addr nseqlen d: codeblock xt: cr? }
addr addr2 u>= ?of endof
addr @ decompile-prim2 { ulen } ulen 0< ?of
drop 2drop 2drop
cr? addr simple-see-word
addr cell+ nseqlen codeblock ['] cr contof
nseqlen 0= if codeblock discode 0 0 to codeblock ['] noop to cr? then
cr? addr see-word.addr type { nseqlen1 ustart uend } ulen if
ustart 4 spaces 0 .r ." ->" uend .
assert( codeblock nip 0= )
addr @ ulen to codeblock then
addr cell+ nseqlen nseqlen1 max 1- codeblock ['] cr
next-case
codeblock discode ;

As you can see, it uses locals heavily (the word I have written with
the most locals by far). If you want to follow what's going on on the
stack, it uses the following additional words:

simple-see-word ( addr -- )
discode ( c-addr u -- )
see-word.addr ( addr -- )

This code took me a while to write, but apart from the handling of the
CRs, it worked on the first try. The handling of the CRs is
complicated, because DISCODE outputs a CR at the start and at the end
(one might consider this a factoring mistake); we could get rid of
everything to do with CR? if DISCODE did not have this property. I
find that the flexible enhanced CASE control structure is a very
natural way for me to consider the different cases and to keep track
of what has been covered already.

For comparison, below you find the old code; it uses fewer locals, and
is factored into three words, but is it better (apart from the
functionality difference)? IMO no.

\ also uses decompile-prim ( addr1 -- addr2 )

: see-code-word { addr -- len }
addr see-word.addr addr @ decompile-prim1 dup >r -1 = if
2drop 2drop addr cell+ addr @ .word drop
else
type 4 spaces swap r@ if
0 .r ." ->" .
else
2drop then
then
r> ;

: see-code-next-inline { addr1 addr2 -- addr3 }
\ decompile starting at addr1 until an inlined primitive is found,
\ or addr2 is reached; addr3 is addr2 or the next inlined
\ primitive
addr1 begin { addr }
addr addr2 u< while
addr @ dup decompile-prim = while
addr cr simple-see-word
addr cell+
repeat then
addr ;

: see-code-range { addr1 addr2 -- } \ gforth
cr addr1 begin { a }
a see-code-word { restlen }
a cell+ addr2 see-code-next-inline { b }
a @ b addr2 u< while
( a @ ) b @ over - discode
b
repeat
\ now disassemble the remaining a @; we derive the length from
\ it's primitive
restlen discode ;
\ dup decompile-prim dup next-prim swap - discode ;

- 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: https://forth-standard.org/
EuroForth 2022: https://euro.theforth.net

Re: Another example of factoring and locals

<tjcuft$1hjp$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20910&group=comp.lang.forth#20910

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Thu, 27 Oct 2022 14:38:37 +1100
Organization: Aioe.org NNTP Server
Message-ID: <tjcuft$1hjp$1@gioia.aioe.org>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="50809"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Thu, 27 Oct 2022 03:38 UTC

On 27/10/2022 7:51 am, Anton Ertl wrote:
>
> For comparison, below you find the old code; it uses fewer locals, and
> is factored into three words, but is it better (apart from the
> functionality difference)? IMO no.

If factoring simplifies code and removes the need for strange Case words,
IMO that's a good thing.

: foo ( addr1 addr2 -- )
>r 0 swap 0 0 ['] noop begin { nseqlen addr d: codeblock xt: cr? }
addr r@ u>= not while
addr @ decompile-prim2 { ulen } ulen 0< if
drop 2drop 2drop
cr? addr simple-see-word
nseqlen
else
nseqlen 0= if codeblock discode 0 0 to codeblock ['] noop to cr? then
cr? addr see-word.addr type { nseqlen1 ustart uend } ulen if
ustart 4 spaces 0 .r ." ->" uend .
assert( codeblock nip 0= )
addr @ ulen to codeblock then
nseqlen nseqlen1 max 1-
then
addr cell+ codeblock ['] cr
repeat r> drop ;

: see-code-range ( addr1 addr2 -- ) \ gforth
foo codeblock discode ;

Re: Another example of factoring and locals

<2022Oct27.123214@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20913&group=comp.lang.forth#20913

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Thu, 27 Oct 2022 10:32:14 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 56
Message-ID: <2022Oct27.123214@mips.complang.tuwien.ac.at>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at> <tjcuft$1hjp$1@gioia.aioe.org>
Injection-Info: reader01.eternal-september.org; posting-host="575911af8f505b8f0b39788cd05d45a3";
logging-data="2897912"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fQVQKjFMtq4BGyF3KQKbX"
Cancel-Lock: sha1:SmD9V8iycxaybuq/LHjW6XJfO3U=
X-newsreader: xrn 10.11
 by: Anton Ertl - Thu, 27 Oct 2022 10:32 UTC

dxforth <dxforth@gmail.com> writes:
>On 27/10/2022 7:51 am, Anton Ertl wrote:
>If factoring simplifies code and removes the need for strange Case words,
>IMO that's a good thing.
>
>: foo ( addr1 addr2 -- )
> >r 0 swap 0 0 ['] noop begin { nseqlen addr d: codeblock xt: cr? }
> addr r@ u>= not while
> addr @ decompile-prim2 { ulen } ulen 0< if
> drop 2drop 2drop
> cr? addr simple-see-word
> nseqlen
> else
> nseqlen 0= if codeblock discode 0 0 to codeblock ['] noop to cr? then
> cr? addr see-word.addr type { nseqlen1 ustart uend } ulen if
> ustart 4 spaces 0 .r ." ->" uend .
> assert( codeblock nip 0= )
> addr @ ulen to codeblock then
> nseqlen nseqlen1 max 1-
> then
> addr cell+ codeblock ['] cr
> repeat r> drop ;
>
>: see-code-range ( addr1 addr2 -- ) \ gforth
> foo codeblock discode ;

Yes, once one has a working version, one can reorganize it, and in
this case it's relatively straightforward to replace the
CASE...NEXT-CASE with a BEGIN ... REPEAT through the introduction of
an ELSE. But it's helpful to have the additional possibilities while
creating the code, and then one can switch to the more traditional
control structures if desired.

The splitting into two words does not work that way, because CODEBLOCK
is a local. It's also unnecessary, because you can just append
"CODEBLOCK DISCODE" to FOO. And the name you chose for FOO also shows
that FOO is not a useful factor for use by other words.

Concerning the partial replacement of locals by keeping the values on
the return stack or data stack, that also can be done more easily in a
second step. But given that we use locals here anyway, I don't find
the result in any way preferable.

If performance was an issue (it is not for this word), on some systems
that might be a reason to use more data stack (not so sure about
return stack) items rather than locals; one data stack item (as used
above) is helpful on most systems, because they keep one data stack
item in a register across basic block boundaries; it's less clearcut
for return stack items or more data stack items.

- 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: https://forth-standard.org/
EuroForth 2022: https://euro.theforth.net

Re: Another example of factoring and locals

<tjdt15$1s0n$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20915&group=comp.lang.forth#20915

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Thu, 27 Oct 2022 23:19:50 +1100
Organization: Aioe.org NNTP Server
Message-ID: <tjdt15$1s0n$1@gioia.aioe.org>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at>
<tjcuft$1hjp$1@gioia.aioe.org> <2022Oct27.123214@mips.complang.tuwien.ac.at>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="61463"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Thu, 27 Oct 2022 12:19 UTC

On 27/10/2022 9:32 pm, Anton Ertl wrote:
>
> Concerning the partial replacement of locals by keeping the values on
> the return stack or data stack, that also can be done more easily in a
> second step. But given that we use locals here anyway, I don't find
> the result in any way preferable.

There it is. I don't find locals preferable in any way. It pushes
me to find whether there's another, potentially better, solution.

Re: Another example of factoring and locals

<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20919&group=comp.lang.forth#20919

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:20e2:b0:4bb:7aa5:bf0a with SMTP id 2-20020a05621420e200b004bb7aa5bf0amr16273860qvk.112.1666887067960;
Thu, 27 Oct 2022 09:11:07 -0700 (PDT)
X-Received: by 2002:a25:380d:0:b0:6c2:6c96:877a with SMTP id
f13-20020a25380d000000b006c26c96877amr46965505yba.530.1666887067783; Thu, 27
Oct 2022 09:11:07 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Thu, 27 Oct 2022 09:11:07 -0700 (PDT)
In-Reply-To: <tjdt15$1s0n$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=77.174.47.232; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 77.174.47.232
References: <2022Oct26.225153@mips.complang.tuwien.ac.at> <tjcuft$1hjp$1@gioia.aioe.org>
<2022Oct27.123214@mips.complang.tuwien.ac.at> <tjdt15$1s0n$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com>
Subject: Re: Another example of factoring and locals
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Thu, 27 Oct 2022 16:11:07 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1685
 by: Hans Bezemer - Thu, 27 Oct 2022 16:11 UTC

On Thursday, October 27, 2022 at 2:19:53 PM UTC+2, dxforth wrote:
> On 27/10/2022 9:32 pm, Anton Ertl wrote:
> There it is. I don't find locals preferable in any way. It pushes
> me to find whether there's another, potentially better, solution.
Hear, hear. I also don't like long definitions. They're a horror to maintain.
Short words make the logic comprehensible - at every level. Both the lower
level words as well as the higher level words.

Hans Bezemer

Re: Another example of factoring and locals

<2022Oct27.182441@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20920&group=comp.lang.forth#20920

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Thu, 27 Oct 2022 16:24:41 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 14
Message-ID: <2022Oct27.182441@mips.complang.tuwien.ac.at>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at> <tjcuft$1hjp$1@gioia.aioe.org> <2022Oct27.123214@mips.complang.tuwien.ac.at> <tjdt15$1s0n$1@gioia.aioe.org> <df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com>
Injection-Info: reader01.eternal-september.org; posting-host="575911af8f505b8f0b39788cd05d45a3";
logging-data="2959154"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191zO4xVOaR8ywPwjdwgNAv"
Cancel-Lock: sha1:Eo4h/5MRSXOuybs0rCfBQbVvbfA=
X-newsreader: xrn 10.11
 by: Anton Ertl - Thu, 27 Oct 2022 16:24 UTC

Hans Bezemer <the.beez.speaks@gmail.com> writes:
>I also don't like long definitions. They're a horror to maintain.
>Short words make the logic comprehensible - at every level. Both the lower
>level words as well as the higher level words.

I am awaiting you posting code for this problem to support your
claims.

- 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: https://forth-standard.org/
EuroForth 2022: https://euro.theforth.net

Re: Another example of factoring and locals

<tjg2qm$1lbd$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20926&group=comp.lang.forth#20926

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Fri, 28 Oct 2022 19:11:01 +1100
Organization: Aioe.org NNTP Server
Message-ID: <tjg2qm$1lbd$1@gioia.aioe.org>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at>
<tjcuft$1hjp$1@gioia.aioe.org> <2022Oct27.123214@mips.complang.tuwien.ac.at>
<tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com>
<2022Oct27.182441@mips.complang.tuwien.ac.at>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="54637"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Fri, 28 Oct 2022 08:11 UTC

On 28/10/2022 3:24 am, Anton Ertl wrote:
> Hans Bezemer <the.beez.speaks@gmail.com> writes:
>> I also don't like long definitions. They're a horror to maintain.
>> Short words make the logic comprehensible - at every level. Both the lower
>> level words as well as the higher level words.
>
> I am awaiting you posting code for this problem to support your
> claims.

It's not enough he doesn't use locals in his own code - he should do
your coding as well? :)

The appeal of locals in forth is the idea that somehow they're free.
Try this test. Replace the locals in your code with regular variables/
values. Now ask yourself whether you still think it's good code; for
it should make no difference to 'good code' where the variables are
located. If one isn't happy with variables external to forth words,
one shouldn't be happy with those internal to them.

Re: Another example of factoring and locals

<87bkpw73fr.fsf@nightsong.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20927&group=comp.lang.forth#20927

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: no.em...@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Fri, 28 Oct 2022 01:33:28 -0700
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <87bkpw73fr.fsf@nightsong.com>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at>
<tjcuft$1hjp$1@gioia.aioe.org>
<2022Oct27.123214@mips.complang.tuwien.ac.at>
<tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com>
<2022Oct27.182441@mips.complang.tuwien.ac.at>
<tjg2qm$1lbd$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="d2c4d2a64854efae7897a6cb5b3a9860";
logging-data="3189220"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hiPoYln3plzBr33amYIeU"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:VEEJxgPU/wZEYiAQ17rOmMEDVCw=
sha1:PqYkJuV2lLBm5mGJdrYCfqriFZs=
 by: Paul Rubin - Fri, 28 Oct 2022 08:33 UTC

dxforth <dxforth@gmail.com> writes:
> If one isn't happy with variables external to forth words, one
> shouldn't be happy with those internal to them.

1. The externals make the code harder to understand / maintain since they
persist across function calls and can be shared between functions. You can
use some naming conventions to indicate that this isn't happening, but
ugh. And you still have to re-initialize the global inside the function
on every call.

2. If the function is recursive you can't use global variables. You have to
set up a separate stack for them or something. Ugh.

3. The globals keep occupying storage even when the function is not running.
I thought Forthers liked stack allocation so that the memory would keep
getting re-used. Locals give that.

Re: Another example of factoring and locals

<30befe81-28a6-4022-a383-b118dcefc892n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20932&group=comp.lang.forth#20932

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:19cb:b0:4bb:6a28:83bc with SMTP id j11-20020a05621419cb00b004bb6a2883bcmr38747qvc.102.1666971387553;
Fri, 28 Oct 2022 08:36:27 -0700 (PDT)
X-Received: by 2002:a25:a288:0:b0:6ca:e3de:ae75 with SMTP id
c8-20020a25a288000000b006cae3deae75mr27724395ybi.391.1666971387344; Fri, 28
Oct 2022 08:36:27 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 28 Oct 2022 08:36:27 -0700 (PDT)
In-Reply-To: <87bkpw73fr.fsf@nightsong.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f14:6b16:11b3:e1be:e99d:a5a3;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f14:6b16:11b3:e1be:e99d:a5a3
References: <2022Oct26.225153@mips.complang.tuwien.ac.at> <tjcuft$1hjp$1@gioia.aioe.org>
<2022Oct27.123214@mips.complang.tuwien.ac.at> <tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com> <2022Oct27.182441@mips.complang.tuwien.ac.at>
<tjg2qm$1lbd$1@gioia.aioe.org> <87bkpw73fr.fsf@nightsong.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <30befe81-28a6-4022-a383-b118dcefc892n@googlegroups.com>
Subject: Re: Another example of factoring and locals
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Fri, 28 Oct 2022 15:36:27 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3768
 by: minf...@arcor.de - Fri, 28 Oct 2022 15:36 UTC

Paul Rubin schrieb am Freitag, 28. Oktober 2022 um 10:33:30 UTC+2:
> dxforth <dxf...@gmail.com> writes:
> > If one isn't happy with variables external to forth words, one
> > shouldn't be happy with those internal to them.
> 1. The externals make the code harder to understand / maintain since they
> persist across function calls and can be shared between functions. You can
> use some naming conventions to indicate that this isn't happening, but
> ugh. And you still have to re-initialize the global inside the function
> on every call.
>
> 2. If the function is recursive you can't use global variables. You have to
> set up a separate stack for them or something. Ugh.
>
> 3. The globals keep occupying storage even when the function is not running.
> I thought Forthers liked stack allocation so that the memory would keep
> getting re-used. Locals give that.

+1 Technical aspects and personal tastes put aside, IMO the most important
benefits of using locals is instantaneous readability of code.

The human brain is no stack machine. We think in associations IOW by tagging
names to material and non-material things and concepts.

Forth is a strange animal: by factoring we try to chop long algorithms into smallest
pieces and then try to give them meaningful names to make the code understandable.
Within those pieces we allow masochistic stack juggling and some guys even claim
to be happy.

But sometimes factorization does not come easily, see Anton's example. It is
good that we have the choice to use locals where they are appropriate.

For quick testing and prototyping I sometimes even use extended locals, in their form:
: TEST { a b .. | d e .. == f g .. } .. ;
with
a b .. standard initialized locals
d e .. standard uninitialized locals
== instead of standard --
f g output locals, non-standard
All locals can be integers, doubles, floats, complex numbers (plus arrays and structs)

So in principle FROT could be defined as
: FROT { f: a b c == b c a } ; \ no code required
with complex numbers:
: ZROT { z: a b c == b c a } ; \ no code required

While this example is close to triviality (the locals compiler is not) real-world code
with extended locals and good short locals names is VERY readable, and mostly bug
free from start.

Re: Another example of factoring and locals

<2ffe0926-3655-407f-8028-6be6540e6c28n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20933&group=comp.lang.forth#20933

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a37:f502:0:b0:6f8:c3b2:51b9 with SMTP id l2-20020a37f502000000b006f8c3b251b9mr11809758qkk.616.1666973530810;
Fri, 28 Oct 2022 09:12:10 -0700 (PDT)
X-Received: by 2002:a81:de43:0:b0:368:ee18:f9c3 with SMTP id
o3-20020a81de43000000b00368ee18f9c3mr194701ywl.322.1666973530593; Fri, 28 Oct
2022 09:12:10 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 28 Oct 2022 09:12:10 -0700 (PDT)
In-Reply-To: <87bkpw73fr.fsf@nightsong.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.174.47.232; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 77.174.47.232
References: <2022Oct26.225153@mips.complang.tuwien.ac.at> <tjcuft$1hjp$1@gioia.aioe.org>
<2022Oct27.123214@mips.complang.tuwien.ac.at> <tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com> <2022Oct27.182441@mips.complang.tuwien.ac.at>
<tjg2qm$1lbd$1@gioia.aioe.org> <87bkpw73fr.fsf@nightsong.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2ffe0926-3655-407f-8028-6be6540e6c28n@googlegroups.com>
Subject: Re: Another example of factoring and locals
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Fri, 28 Oct 2022 16:12:10 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2370
 by: Hans Bezemer - Fri, 28 Oct 2022 16:12 UTC

On Friday, October 28, 2022 at 10:33:30 AM UTC+2, Paul Rubin wrote:
> 1. The externals make the code harder to understand / maintain since they
> persist across function calls and can be shared between functions. You can
> use some naming conventions to indicate that this isn't happening, but
> ugh. And you still have to re-initialize the global inside the function
> on every call.
>
> 2. If the function is recursive you can't use global variables. You have to
> set up a separate stack for them or something. Ugh.
>
> 3. The globals keep occupying storage even when the function is not running.
> I thought Forthers liked stack allocation so that the memory would keep
> getting re-used. Locals give that.

I hope you and C become very happy. Oh dear, no! You can blow up your program
if you're incapable of balancing your malloc() - free() calls. It's much the same way
like stack balancing, you know. I hope you and Rust become very happy.

Hans Bezemer

Re: Another example of factoring and locals

<7776b1c0-48d6-45a5-b6ce-1081b1010374n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20934&group=comp.lang.forth#20934

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ad4:5762:0:b0:4bb:5f2d:68ed with SMTP id r2-20020ad45762000000b004bb5f2d68edmr166690qvx.69.1666973659140;
Fri, 28 Oct 2022 09:14:19 -0700 (PDT)
X-Received: by 2002:a81:71c6:0:b0:36a:5682:2c44 with SMTP id
m189-20020a8171c6000000b0036a56822c44mr205090ywc.308.1666973658948; Fri, 28
Oct 2022 09:14:18 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 28 Oct 2022 09:14:18 -0700 (PDT)
In-Reply-To: <tjg2qm$1lbd$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=77.174.47.232; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 77.174.47.232
References: <2022Oct26.225153@mips.complang.tuwien.ac.at> <tjcuft$1hjp$1@gioia.aioe.org>
<2022Oct27.123214@mips.complang.tuwien.ac.at> <tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com> <2022Oct27.182441@mips.complang.tuwien.ac.at>
<tjg2qm$1lbd$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7776b1c0-48d6-45a5-b6ce-1081b1010374n@googlegroups.com>
Subject: Re: Another example of factoring and locals
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Fri, 28 Oct 2022 16:14:19 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2066
 by: Hans Bezemer - Fri, 28 Oct 2022 16:14 UTC

On Friday, October 28, 2022 at 10:11:08 AM UTC+2, dxforth wrote:
> On 28/10/2022 3:24 am, Anton Ertl wrote:
> > Hans Bezemer <the.bee...@gmail.com> writes:
> >> I also don't like long definitions. They're a horror to maintain.
> >> Short words make the logic comprehensible - at every level. Both the lower
> >> level words as well as the higher level words.
> >
> > I am awaiting you posting code for this problem to support your
> > claims.
> It's not enough he doesn't use locals in his own code - he should do
> your coding as well? :)

ROFL! We're slowly becoming soulmates I think. I was contemplating my
answer along the same line of thought - before I read your post. ;-)

Hans Bezemer

Re: Another example of factoring and locals

<74d9d175-1aea-4eef-9ccd-d2417cd9950bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20935&group=comp.lang.forth#20935

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:5c0f:0:b0:39c:db4c:82af with SMTP id i15-20020ac85c0f000000b0039cdb4c82afmr261704qti.538.1666974524018;
Fri, 28 Oct 2022 09:28:44 -0700 (PDT)
X-Received: by 2002:a0d:d74d:0:b0:36b:7256:9355 with SMTP id
z74-20020a0dd74d000000b0036b72569355mr251902ywd.61.1666974523794; Fri, 28 Oct
2022 09:28:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 28 Oct 2022 09:28:43 -0700 (PDT)
In-Reply-To: <30befe81-28a6-4022-a383-b118dcefc892n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.174.47.232; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 77.174.47.232
References: <2022Oct26.225153@mips.complang.tuwien.ac.at> <tjcuft$1hjp$1@gioia.aioe.org>
<2022Oct27.123214@mips.complang.tuwien.ac.at> <tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com> <2022Oct27.182441@mips.complang.tuwien.ac.at>
<tjg2qm$1lbd$1@gioia.aioe.org> <87bkpw73fr.fsf@nightsong.com> <30befe81-28a6-4022-a383-b118dcefc892n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <74d9d175-1aea-4eef-9ccd-d2417cd9950bn@googlegroups.com>
Subject: Re: Another example of factoring and locals
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Fri, 28 Oct 2022 16:28:44 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 4549
 by: Hans Bezemer - Fri, 28 Oct 2022 16:28 UTC

On Friday, October 28, 2022 at 5:36:28 PM UTC+2, minf...@arcor.de wrote:
> Paul Rubin schrieb am Freitag, 28. Oktober 2022 um 10:33:30 UTC+2:
> > dxforth <dxf...@gmail.com> writes:
> > > If one isn't happy with variables external to forth words, one
> > > shouldn't be happy with those internal to them.
> > 1. The externals make the code harder to understand / maintain since they
> > persist across function calls and can be shared between functions. You can
> > use some naming conventions to indicate that this isn't happening, but
> > ugh. And you still have to re-initialize the global inside the function
> > on every call.
If you need a carload of variables, you've forgotten (or completely disregarded)
the first rule of "Thinking Forth", which is "STAMP OUT THE VARIABLES"!

> > 2. If the function is recursive you can't use global variables. You have to
> > set up a separate stack for them or something. Ugh.
See rule number one.

> > 3. The globals keep occupying storage even when the function is not running.
> > I thought Forthers liked stack allocation so that the memory would keep
> > getting re-used. Locals give that.
So does C. It also introduces the penalty of stack frame creation and destruction.

> +1 Technical aspects and personal tastes put aside, IMO the most important
> benefits of using locals is instantaneous readability of code.
If you need locals for that, you're not doing it correctly. Short definitions allow for
readability - not locals.

> The human brain is no stack machine. We think in associations IOW by tagging
> names to material and non-material things and concepts.
We were spoiled by Fortran, which allowed us to translate mathematical formulas
almost directly to working code. Blame mathematics for that notation.

> Forth is a strange animal: by factoring we try to chop long algorithms into smallest
> pieces and then try to give them meaningful names to make the code understandable.
> Within those pieces we allow masochistic stack juggling and some guys even claim
> to be happy.
If there is excessive stack juggling, it might be because you're (a) a totally incompetent
Forth programmer, (b) a lazy Forth programmer, who feels good translating C code
directly to Forth without studying the algorithm and (c) in some circumstances it's
not worth, needed or even desired to reduce the amount of stack juggling. My rule of
the thumb is - if I can't understand it I rewrite it.

> But sometimes factorization does not come easily, see Anton's example. It is
> good that we have the choice to use locals where they are appropriate.
Nobody says it is or should be easy! It requires thought and some tinkering. If
you just want to churn out code quickly, you should do Forth - but Python! However,
often library code is the hardest to get right IMHO. Application code - not so much.
I was able to create a 64K Forth source in 5 days. In a professional setting. It never
missed a beat in its entire lifetime - despite the excessive diagnostic code.

Hans Bezemer

Re: Another example of factoring and locals

<874jvn74e3.fsf@nightsong.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20940&group=comp.lang.forth#20940

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: no.em...@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Fri, 28 Oct 2022 19:25:08 -0700
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <874jvn74e3.fsf@nightsong.com>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at>
<tjcuft$1hjp$1@gioia.aioe.org>
<2022Oct27.123214@mips.complang.tuwien.ac.at>
<tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com>
<2022Oct27.182441@mips.complang.tuwien.ac.at>
<tjg2qm$1lbd$1@gioia.aioe.org> <87bkpw73fr.fsf@nightsong.com>
<30befe81-28a6-4022-a383-b118dcefc892n@googlegroups.com>
<74d9d175-1aea-4eef-9ccd-d2417cd9950bn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="24cfaae33053435b18522897d37aeed4";
logging-data="3516691"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19QT4B1Cz97Kqakmvbv7Mx4"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:XwjSEOQA46p4xHG4/uGK9UCTq1o=
sha1:pYio+KbvUE6sMz/SXDBV2drVe/k=
 by: Paul Rubin - Sat, 29 Oct 2022 02:25 UTC

Hans Bezemer <the.beez.speaks@gmail.com> writes:
>> > I thought Forthers liked stack allocation so that the memory would keep
>> > getting re-used. Locals give that.
> So does C. It also introduces the penalty of stack frame creation and
> destruction.

If you mean the frame pointer, you don't really need that, it just makes
debugging easier. You can pass -ffomit-frame-pointer to gcc to omit it.

>> But sometimes factorization does not come easily, see Anton's
>> example. It is good that we have the choice to use locals where they
>> are appropriate.

> Nobody says it is or should be easy! It requires thought and some
> tinkering. If you just want to churn out code quickly, you should do
> Forth - but Python!

Is there some benefit gained from that thought and tinkering and loss of
productivity? Does it make the code faster, more reliable, or anything
like that? Otherwise it sounds like masochism or some misplaced
ideological extremism, like "the stack operators cannot fail--they can
only be failed".

Here is the simplest way I can see to multiply of two complex numbers
(x=a+bi, y=c+di, z=x*y):

: z* { F: a F: b F: c F: d -- F: ac-bd F: ad+bc }
a c f* b d f* f- a d f* b c f* f+ ;

That example could use FVARIABLEs instead of locals but it would be a
lot messier imho. There are no FVALUEs in standard Forth iirc, so you
have to use @ everywhere, and then your auditing process has to make
sure nothing else uses those variables, including by having anything
aliased to the pointers in the variables, and so on. There is no
equivalent of the return stack to stash intermediate FP values, so stack
juggling becomes harder. Maybe it is still possible, but who wants to
spend the debugging effort? I can't believe it helps readability.

I have another example that uses FP locals and is recursive, so moving
them to FVARIABLEs isn't even workable. I don't see a general approach
other than an auxiliary FP stack implement in user code. Ugh.

Re: Another example of factoring and locals

<87zgdf5pn8.fsf@nightsong.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20941&group=comp.lang.forth#20941

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: no.em...@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Fri, 28 Oct 2022 19:28:59 -0700
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <87zgdf5pn8.fsf@nightsong.com>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at>
<tjcuft$1hjp$1@gioia.aioe.org>
<2022Oct27.123214@mips.complang.tuwien.ac.at>
<tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com>
<2022Oct27.182441@mips.complang.tuwien.ac.at>
<tjg2qm$1lbd$1@gioia.aioe.org> <87bkpw73fr.fsf@nightsong.com>
<30befe81-28a6-4022-a383-b118dcefc892n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="24cfaae33053435b18522897d37aeed4";
logging-data="3516691"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1oJWroVd8qt1mPr2VVn2B"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:ardrdjR5uDiW1wD8ozf7i2tSc2Y=
sha1:qFKR6sXxkrNkPGDX1zr4Xn8ifmY=
 by: Paul Rubin - Sat, 29 Oct 2022 02:28 UTC

"minf...@arcor.de" <minforth@arcor.de> writes:
> For quick testing and prototyping I sometimes even use extended
> locals, in their form:
> : TEST { a b .. | d e .. == f g .. } .. ;

That is cool, what Forth implements that? I haven't seen it before.
Just ending the word with "f g" seems like enough though:

: swap { a b } b a ;

Re: Another example of factoring and locals

<tji5tj$13t5$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20942&group=comp.lang.forth#20942

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Sat, 29 Oct 2022 14:16:03 +1100
Organization: Aioe.org NNTP Server
Message-ID: <tji5tj$13t5$1@gioia.aioe.org>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at>
<tjcuft$1hjp$1@gioia.aioe.org> <2022Oct27.123214@mips.complang.tuwien.ac.at>
<tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com>
<2022Oct27.182441@mips.complang.tuwien.ac.at> <tjg2qm$1lbd$1@gioia.aioe.org>
<87bkpw73fr.fsf@nightsong.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="36773"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Sat, 29 Oct 2022 03:16 UTC

On 28/10/2022 7:33 pm, Paul Rubin wrote:
> dxforth <dxforth@gmail.com> writes:
>> If one isn't happy with variables external to forth words, one
>> shouldn't be happy with those internal to them.
>
> 1. The externals make the code harder to understand / maintain since they
> persist across function calls and can be shared between functions. You can
> use some naming conventions to indicate that this isn't happening, but
> ugh. And you still have to re-initialize the global inside the function
> on every call.
>
> 2. If the function is recursive you can't use global variables. You have to
> set up a separate stack for them or something. Ugh.
>
> 3. The globals keep occupying storage even when the function is not running.
> I thought Forthers liked stack allocation so that the memory would keep
> getting re-used. Locals give that.

Oh, I'm not advocating variables - locals or otherwise. What I see is a lot
of promiscuous use of the former as if there were no cost. Here's an example
of using extra locals - not out of necessity - but 'style':

https://gforth.org/manual/Locals-programming-style.html

In C, locals are unavoidable - it's not a matter of style or choice. In Forth,
locals are all about style. The more the better so we're told. Unfortunately
Forth was never designed for it. Compared to data stack, the return stack is
the smaller - intended only to hold return addresses and the occasional temp.
Nested definitions using locals will quickly eat it up. You decide whether
style is worth the cost.

Re: Another example of factoring and locals

<tjic8e$qbm$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20943&group=comp.lang.forth#20943

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Sat, 29 Oct 2022 16:04:14 +1100
Organization: Aioe.org NNTP Server
Message-ID: <tjic8e$qbm$1@gioia.aioe.org>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at>
<tjcuft$1hjp$1@gioia.aioe.org> <2022Oct27.123214@mips.complang.tuwien.ac.at>
<tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com>
<2022Oct27.182441@mips.complang.tuwien.ac.at> <tjg2qm$1lbd$1@gioia.aioe.org>
<87bkpw73fr.fsf@nightsong.com>
<30befe81-28a6-4022-a383-b118dcefc892n@googlegroups.com>
<74d9d175-1aea-4eef-9ccd-d2417cd9950bn@googlegroups.com>
<874jvn74e3.fsf@nightsong.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="26998"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Sat, 29 Oct 2022 05:04 UTC

On 29/10/2022 1:25 pm, Paul Rubin wrote:
> ...
> Here is the simplest way I can see to multiply of two complex numbers
> (x=a+bi, y=c+di, z=x*y):
>
> : z* { F: a F: b F: c F: d -- F: ac-bd F: ad+bc }
> a c f* b d f* f- a d f* b c f* f+ ;
>
> That example could use FVARIABLEs instead of locals but it would be a
> lot messier imho. There are no FVALUEs in standard Forth iirc, so you
> have to use @ everywhere, and then your auditing process has to make
> sure nothing else uses those variables, including by having anything
> aliased to the pointers in the variables, and so on. There is no
> equivalent of the return stack to stash intermediate FP values, so stack
> juggling becomes harder. Maybe it is still possible, but who wants to
> spend the debugging effort? I can't believe it helps readability.

How many times will you code Z* ? FWIW FSLIB already has it.

> I have another example that uses FP locals and is recursive, so moving
> them to FVARIABLEs isn't even workable. I don't see a general approach
> other than an auxiliary FP stack implement in user code. Ugh.

FP locals isn't supported by any standard. Some folks have suggested
there should be a F>R R>F which would allow recursive f/p variables.
IIRC Wil Baden had a scheme that used memory at HERE as f/p locals.
The situations you present as requiring locals are obscure enough that
there is almost always another way. But you have to want to find it.

Re: Another example of factoring and locals

<tjid63$12c9$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20944&group=comp.lang.forth#20944

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Sat, 29 Oct 2022 16:20:03 +1100
Organization: Aioe.org NNTP Server
Message-ID: <tjid63$12c9$1@gioia.aioe.org>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at>
<tjcuft$1hjp$1@gioia.aioe.org> <2022Oct27.123214@mips.complang.tuwien.ac.at>
<tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com>
<2022Oct27.182441@mips.complang.tuwien.ac.at> <tjg2qm$1lbd$1@gioia.aioe.org>
<7776b1c0-48d6-45a5-b6ce-1081b1010374n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="35209"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Sat, 29 Oct 2022 05:20 UTC

On 29/10/2022 3:14 am, Hans Bezemer wrote:
> On Friday, October 28, 2022 at 10:11:08 AM UTC+2, dxforth wrote:
>> On 28/10/2022 3:24 am, Anton Ertl wrote:
>>> Hans Bezemer <the.bee...@gmail.com> writes:
>>>> I also don't like long definitions. They're a horror to maintain.
>>>> Short words make the logic comprehensible - at every level. Both the lower
>>>> level words as well as the higher level words.
>>>
>>> I am awaiting you posting code for this problem to support your
>>> claims.
>> It's not enough he doesn't use locals in his own code - he should do
>> your coding as well? :)
>
> ROFL! We're slowly becoming soulmates I think. I was contemplating my
> answer along the same line of thought - before I read your post. ;-)

It's not as if we hadn't been here before and don't know the answers :)

Re: Another example of factoring and locals

<f9599299-94f9-4c92-bbca-a734dc9b6ab8n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20945&group=comp.lang.forth#20945

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:5807:0:b0:3a4:f4dc:b316 with SMTP id g7-20020ac85807000000b003a4f4dcb316mr2518692qtg.139.1667025975554;
Fri, 28 Oct 2022 23:46:15 -0700 (PDT)
X-Received: by 2002:a25:b851:0:b0:6ca:2b0b:d334 with SMTP id
b17-20020a25b851000000b006ca2b0bd334mr2711417ybm.104.1667025975325; Fri, 28
Oct 2022 23:46:15 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 28 Oct 2022 23:46:15 -0700 (PDT)
In-Reply-To: <87zgdf5pn8.fsf@nightsong.com>
Injection-Info: google-groups.googlegroups.com; posting-host=87.157.106.215; posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 87.157.106.215
References: <2022Oct26.225153@mips.complang.tuwien.ac.at> <tjcuft$1hjp$1@gioia.aioe.org>
<2022Oct27.123214@mips.complang.tuwien.ac.at> <tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com> <2022Oct27.182441@mips.complang.tuwien.ac.at>
<tjg2qm$1lbd$1@gioia.aioe.org> <87bkpw73fr.fsf@nightsong.com>
<30befe81-28a6-4022-a383-b118dcefc892n@googlegroups.com> <87zgdf5pn8.fsf@nightsong.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f9599299-94f9-4c92-bbca-a734dc9b6ab8n@googlegroups.com>
Subject: Re: Another example of factoring and locals
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Sat, 29 Oct 2022 06:46:15 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3697
 by: minf...@arcor.de - Sat, 29 Oct 2022 06:46 UTC

Paul Rubin schrieb am Samstag, 29. Oktober 2022 um 04:29:03 UTC+2:
> "minf...@arcor.de" <minf...@arcor.de> writes:
> > For quick testing and prototyping I sometimes even use extended
> > locals, in their form:
> > : TEST { a b .. | d e .. == f g .. } .. ;
> That is cool, what Forth implements that? I haven't seen it before.
> Just ending the word with "f g" seems like enough though:
>
> : swap { a b } b a ;

This would be a SWAP defined in standard Forth with single braces à la gforth.
For such extremely short definitions there is no benefit from output locals..

But consider complicated algorithms (in my case signal processing math).
There it helps when the compiler does the stack juggling for you by parsing
the stack comment COMPLETELY. Standard Forth stops halfway in the process
by ignoring everything after -- . But sometimes it is a waste of programmer's time
when he has to keep track of the machine state/stacks instead of concentrating
on the algorithm.

F.ex.
: DEARCHMEAN { tagname tstart tend f: factor | sum == rec: tagrec f: mval n: flag }
< algorithm > ;
extracts the the archived signal 'tagname' between points of time tstart to tend and
calculates the mean signal value mval using the fp-locals factor and sum. The extracted
time series record tagrec and and a flag are returned as well. The "living stack comment"
says it all. Your eyes don't have to scan the following algo code to find out where/when
final results are put on the stack, moved into the correct order, and intermediate
calculations are cleared/dropped away. Let the compiler do this for you. The algo's
code becomes uncluttered, more readable, and shorter.

Some smart guys think that this smells too much of Python. But they ignore that this is
still Forth, ultra-compact for embedding, and fast enough in 98% of all cases.

And there is a second advantage: when the compiler knows the outputs of a word, it
can raise a warning when it is connected to a word with non-matching input characteristic.
This compile-time I/O matching can be very helpful, but not always.

Re: Another example of factoring and locals

<tjilf4$3d93q$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20946&group=comp.lang.forth#20946

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: do-not-...@swldwa.uk (Gerry Jackson)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Sat, 29 Oct 2022 08:41:25 +0100
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <tjilf4$3d93q$1@dont-email.me>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at>
<tjcuft$1hjp$1@gioia.aioe.org> <2022Oct27.123214@mips.complang.tuwien.ac.at>
<tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com>
<2022Oct27.182441@mips.complang.tuwien.ac.at> <tjg2qm$1lbd$1@gioia.aioe.org>
<87bkpw73fr.fsf@nightsong.com>
<30befe81-28a6-4022-a383-b118dcefc892n@googlegroups.com>
<74d9d175-1aea-4eef-9ccd-d2417cd9950bn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 29 Oct 2022 07:41:24 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="59c4021fd2569cff5eeaa3f7c5797899";
logging-data="3581050"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+d7hjWxw134N5e6HTAEHY+2cgn14Ky85A="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.0
Cancel-Lock: sha1:M4OsncBLcvcVaNPA64xK9BSEMJA=
In-Reply-To: <74d9d175-1aea-4eef-9ccd-d2417cd9950bn@googlegroups.com>
 by: Gerry Jackson - Sat, 29 Oct 2022 07:41 UTC

On 28/10/2022 17:28, Hans Bezemer wrote:
> On Friday, October 28, 2022 at 5:36:28 PM UTC+2,minf...@arcor.de wrote:
>> Paul Rubin schrieb am Freitag, 28. Oktober 2022 um 10:33:30 UTC+2:
>>> dxforth<dxf...@gmail.com> writes:
>>>> If one isn't happy with variables external to forth words, one
>>>> shouldn't be happy with those internal to them.
>>> 1. The externals make the code harder to understand / maintain since they
>>> persist across function calls and can be shared between functions. You can
>>> use some naming conventions to indicate that this isn't happening, but
>>> ugh. And you still have to re-initialize the global inside the function
>>> on every call.
> If you need a carload of variables, you've forgotten (or completely disregarded)
> the first rule of "Thinking Forth", which is "STAMP OUT THE VARIABLES"!
>

You don't seem to practice what you preach e.g.

\ -----------------------------------------------------------
\ 4tH library - string CONCAT - Copyright 2012 J.L. Bezemer
\ You can redistribute this file and/or modify it under
\ the terms of the GNU General Public License

[UNDEFINED] concat [IF]
variable __concat \ destination address

: concat ( a1 n1 .. ai ni i a2 -- a2 n2)
__concat ! 1- dup \ save destination, setup counter
begin dup while rot >r rot >r 1- repeat drop >r __concat @ place r>
begin dup while r> r> __concat @ +place 1- repeat drop __concat @ count
; \ first transfer to Rstack, then append
\ ----------------------------------------------------------

Seems a bit of a dog's breakfast to me: unnecesssary use of a variable,
lengthy definition and unnecessary call to PLACE, crashes if i=0,
incorrect & misleading stack comment. Compare with:

: concat ( ca1 u1 .. can un n ca -- ca+1 u )
0 over c! swap
[: ?dup if 2swap 2>r 1- recurse dup 2r> rot +place then ;]
execute count
;

--
Gerry

Re: Another example of factoring and locals

<21bfb08d-2c13-40d1-a8fb-cdec1676667dn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20947&group=comp.lang.forth#20947

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:622a:170c:b0:39c:c8c4:71f5 with SMTP id h12-20020a05622a170c00b0039cc8c471f5mr2701390qtk.595.1667030740428;
Sat, 29 Oct 2022 01:05:40 -0700 (PDT)
X-Received: by 2002:a81:1bcc:0:b0:35b:8faf:9bbd with SMTP id
b195-20020a811bcc000000b0035b8faf9bbdmr3110628ywb.166.1667030740232; Sat, 29
Oct 2022 01:05:40 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 29 Oct 2022 01:05:40 -0700 (PDT)
In-Reply-To: <tjilf4$3d93q$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:1c05:2f14:600:84ee:b4aa:90c1:c86;
posting-account=-JQ2RQoAAAB6B5tcBTSdvOqrD1HpT_Rk
NNTP-Posting-Host: 2001:1c05:2f14:600:84ee:b4aa:90c1:c86
References: <2022Oct26.225153@mips.complang.tuwien.ac.at> <tjcuft$1hjp$1@gioia.aioe.org>
<2022Oct27.123214@mips.complang.tuwien.ac.at> <tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com> <2022Oct27.182441@mips.complang.tuwien.ac.at>
<tjg2qm$1lbd$1@gioia.aioe.org> <87bkpw73fr.fsf@nightsong.com>
<30befe81-28a6-4022-a383-b118dcefc892n@googlegroups.com> <74d9d175-1aea-4eef-9ccd-d2417cd9950bn@googlegroups.com>
<tjilf4$3d93q$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <21bfb08d-2c13-40d1-a8fb-cdec1676667dn@googlegroups.com>
Subject: Re: Another example of factoring and locals
From: mhx...@iae.nl (Marcel Hendrix)
Injection-Date: Sat, 29 Oct 2022 08:05:40 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2181
 by: Marcel Hendrix - Sat, 29 Oct 2022 08:05 UTC

On Saturday, October 29, 2022 at 9:41:27 AM UTC+2, Gerry Jackson wrote:
[..]
> Seems a bit of a dog's breakfast to me: unnecesssary use of a variable,
> lengthy definition and unnecessary call to PLACE, crashes if i=0,
> incorrect & misleading stack comment. Compare with:
>
> : concat ( ca1 u1 .. can un n ca -- ca+1 u )
> 0 over c! swap
> [: ?dup if 2swap 2>r 1- recurse dup 2r> rot +place then ;]
> execute count
> ;

FORTH> : concats ( ca1 u1 .. can un n -- ca u ) 1- 0 max 0 ?DO $+ LOOP ;
FORTH> S" Hello" S" , " S" world" S" !" 4 concats
[2]FORTH> type Hello, world! ok
-marcel

Re: Another example of factoring and locals

<3bc29ff6-65ed-4638-8681-9f79ab28aaabn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20954&group=comp.lang.forth#20954

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:7d42:0:b0:39c:dd3f:b74d with SMTP id h2-20020ac87d42000000b0039cdd3fb74dmr3396863qtb.279.1667047551012;
Sat, 29 Oct 2022 05:45:51 -0700 (PDT)
X-Received: by 2002:a0d:f446:0:b0:34d:4deb:1155 with SMTP id
d67-20020a0df446000000b0034d4deb1155mr3885227ywf.245.1667047550764; Sat, 29
Oct 2022 05:45:50 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 29 Oct 2022 05:45:50 -0700 (PDT)
In-Reply-To: <tjilf4$3d93q$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=77.174.47.232; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 77.174.47.232
References: <2022Oct26.225153@mips.complang.tuwien.ac.at> <tjcuft$1hjp$1@gioia.aioe.org>
<2022Oct27.123214@mips.complang.tuwien.ac.at> <tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com> <2022Oct27.182441@mips.complang.tuwien.ac.at>
<tjg2qm$1lbd$1@gioia.aioe.org> <87bkpw73fr.fsf@nightsong.com>
<30befe81-28a6-4022-a383-b118dcefc892n@googlegroups.com> <74d9d175-1aea-4eef-9ccd-d2417cd9950bn@googlegroups.com>
<tjilf4$3d93q$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3bc29ff6-65ed-4638-8681-9f79ab28aaabn@googlegroups.com>
Subject: Re: Another example of factoring and locals
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Sat, 29 Oct 2022 12:45:51 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2213
 by: Hans Bezemer - Sat, 29 Oct 2022 12:45 UTC

On Saturday, October 29, 2022 at 9:41:27 AM UTC+2, Gerry Jackson wrote:
> > If you need a carload of variables, you've forgotten (or completely disregarded)
> > the first rule of "Thinking Forth", which is "STAMP OUT THE VARIABLES"!
> >
> You don't seem to practice what you preach e.g.
Well, the only lesson one could take from it is "there is always someone more clever
than you" - which IMHO is just a fact of life. You will probably find more examples in
the 500+ libraries I wrote - if you dig really well.

However, if this is the only example you found in 75 KLOC of 4tH, I think I'm not doing
too bad. BTW, it's a clever piece of code. Kudos!

Hans Bezemer

Re: Another example of factoring and locals

<b913a769-dfc6-463a-ad06-70a989b844cdn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20955&group=comp.lang.forth#20955

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:622a:144a:b0:39c:c974:9522 with SMTP id v10-20020a05622a144a00b0039cc9749522mr3573072qtx.338.1667049294463;
Sat, 29 Oct 2022 06:14:54 -0700 (PDT)
X-Received: by 2002:a81:6554:0:b0:349:8e3:a882 with SMTP id
z81-20020a816554000000b0034908e3a882mr4091141ywb.388.1667049294213; Sat, 29
Oct 2022 06:14:54 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 29 Oct 2022 06:14:53 -0700 (PDT)
In-Reply-To: <tjilf4$3d93q$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=77.174.47.232; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 77.174.47.232
References: <2022Oct26.225153@mips.complang.tuwien.ac.at> <tjcuft$1hjp$1@gioia.aioe.org>
<2022Oct27.123214@mips.complang.tuwien.ac.at> <tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com> <2022Oct27.182441@mips.complang.tuwien.ac.at>
<tjg2qm$1lbd$1@gioia.aioe.org> <87bkpw73fr.fsf@nightsong.com>
<30befe81-28a6-4022-a383-b118dcefc892n@googlegroups.com> <74d9d175-1aea-4eef-9ccd-d2417cd9950bn@googlegroups.com>
<tjilf4$3d93q$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b913a769-dfc6-463a-ad06-70a989b844cdn@googlegroups.com>
Subject: Re: Another example of factoring and locals
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Sat, 29 Oct 2022 13:14:54 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1996
 by: Hans Bezemer - Sat, 29 Oct 2022 13:14 UTC

On Saturday, October 29, 2022 at 9:41:27 AM UTC+2, Gerry Jackson wrote:
> incorrect & misleading stack comment.
I now see where your comment about "misleading stack comment" comes
from. In 4tH ASCIIZ strings are used - and a2 is actually the address that is
returned.

That your code works is because the first line effectively terminates
the target string - and the abstraction of +PLACE does the heavy lifting.

But I forgive you ;-)

Hans Bezemer

Re: Another example of factoring and locals

<2022Oct29.153432@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20956&group=comp.lang.forth#20956

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Sat, 29 Oct 2022 13:34:32 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 31
Message-ID: <2022Oct29.153432@mips.complang.tuwien.ac.at>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at> <tjcuft$1hjp$1@gioia.aioe.org> <2022Oct27.123214@mips.complang.tuwien.ac.at> <tjdt15$1s0n$1@gioia.aioe.org> <df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com> <2022Oct27.182441@mips.complang.tuwien.ac.at> <tjg2qm$1lbd$1@gioia.aioe.org> <7776b1c0-48d6-45a5-b6ce-1081b1010374n@googlegroups.com>
Injection-Info: reader01.eternal-september.org; posting-host="bdae180b60de63888d6a616a679968dd";
logging-data="3683029"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iINlym+8F029R6FozJtOA"
Cancel-Lock: sha1:oUJOGg4q/l1oJgBzbPTndsYniX8=
X-newsreader: xrn 10.11
 by: Anton Ertl - Sat, 29 Oct 2022 13:34 UTC

Hans Bezemer <the.beez.speaks@gmail.com> writes:
>On Friday, October 28, 2022 at 10:11:08 AM UTC+2, dxforth wrote:
>> On 28/10/2022 3:24 am, Anton Ertl wrote:
>> > Hans Bezemer <the.bee...@gmail.com> writes:
>> >> I also don't like long definitions. They're a horror to maintain.
>> >> Short words make the logic comprehensible - at every level. Both the lower
>> >> level words as well as the higher level words.
>> >
>> > I am awaiting you posting code for this problem to support your
>> > claims.
>> It's not enough he doesn't use locals in his own code - he should do
>> your coding as well? :)

I did do my own coding. Hans Bezemer just made general claims, so I
called him to show that there is substance to his words (and it's
about long definitions, not locals).

>ROFL! We're slowly becoming soulmates I think. I was contemplating my
>answer along the same line of thought - before I read your post. ;-)

Apparently there is no substance to your words. As for being
soulmates, dxforth has posted code to demonstrate a part of his
positions (and his code actually inspired me to transform the control
structure in the way he suggested).

- 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: https://forth-standard.org/
EuroForth 2022: https://euro.theforth.net

Re: Another example of factoring and locals

<tjjihh$1hj1$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20959&group=comp.lang.forth#20959

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Another example of factoring and locals
Date: Sun, 30 Oct 2022 02:57:39 +1100
Organization: Aioe.org NNTP Server
Message-ID: <tjjihh$1hj1$1@gioia.aioe.org>
References: <2022Oct26.225153@mips.complang.tuwien.ac.at>
<tjcuft$1hjp$1@gioia.aioe.org> <2022Oct27.123214@mips.complang.tuwien.ac.at>
<tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com>
<2022Oct27.182441@mips.complang.tuwien.ac.at> <tjg2qm$1lbd$1@gioia.aioe.org>
<87bkpw73fr.fsf@nightsong.com>
<30befe81-28a6-4022-a383-b118dcefc892n@googlegroups.com>
<74d9d175-1aea-4eef-9ccd-d2417cd9950bn@googlegroups.com>
<tjilf4$3d93q$1@dont-email.me>
<21bfb08d-2c13-40d1-a8fb-cdec1676667dn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="50785"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Sat, 29 Oct 2022 15:57 UTC

On 29/10/2022 7:05 pm, Marcel Hendrix wrote:
>
> FORTH> : concats ( ca1 u1 .. can un n -- ca u ) 1- 0 max 0 ?DO $+ LOOP ;
> FORTH> S" Hello" S" , " S" world" S" !" 4 concats
> [2]FORTH> type Hello, world! ok

: concats <# 0 ?do holds loop 0 0 #> ;

s" Hello" s" , " s" world" s" !" 4 concats type Hello, world! ok

Re: Another example of factoring and locals

<bca7babc-2160-486a-80aa-a11625fe4ea3n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20963&group=comp.lang.forth#20963

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a0c:f84b:0:b0:4bb:92b0:3860 with SMTP id g11-20020a0cf84b000000b004bb92b03860mr4578061qvo.61.1667066977865;
Sat, 29 Oct 2022 11:09:37 -0700 (PDT)
X-Received: by 2002:a05:690c:802:b0:36b:adba:8ff with SMTP id
bx2-20020a05690c080200b0036badba08ffmr4880513ywb.237.1667066977593; Sat, 29
Oct 2022 11:09:37 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 29 Oct 2022 11:09:37 -0700 (PDT)
In-Reply-To: <2022Oct29.153432@mips.complang.tuwien.ac.at>
Injection-Info: google-groups.googlegroups.com; posting-host=77.174.47.232; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 77.174.47.232
References: <2022Oct26.225153@mips.complang.tuwien.ac.at> <tjcuft$1hjp$1@gioia.aioe.org>
<2022Oct27.123214@mips.complang.tuwien.ac.at> <tjdt15$1s0n$1@gioia.aioe.org>
<df3724de-f372-4c24-8bf4-059962363089n@googlegroups.com> <2022Oct27.182441@mips.complang.tuwien.ac.at>
<tjg2qm$1lbd$1@gioia.aioe.org> <7776b1c0-48d6-45a5-b6ce-1081b1010374n@googlegroups.com>
<2022Oct29.153432@mips.complang.tuwien.ac.at>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bca7babc-2160-486a-80aa-a11625fe4ea3n@googlegroups.com>
Subject: Re: Another example of factoring and locals
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Sat, 29 Oct 2022 18:09:37 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2000
 by: Hans Bezemer - Sat, 29 Oct 2022 18:09 UTC

On Saturday, October 29, 2022 at 3:41:08 PM UTC+2, Anton Ertl wrote:
> I did do my own coding.
What can I say. It shows. LOL!

> Apparently there is no substance to your words. As for being
> soulmates, dxforth has posted code to demonstrate a part of his
> positions (and his code actually inspired me to transform the control
> structure in the way he suggested).
C'mon. Do you know how old I am? Do you really expect me to dance to
your tune? That's how kids challenge each other in kindergarten!

Hans Bezemer

Pages:123456789
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor