Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

It's not really a rule--it's more like a trend. -- Larry Wall in <199710221721.KAA24321@wall.org>


devel / comp.lang.forth / Inefficiency of FSL matrices

SubjectAuthor
* Inefficiency of FSL matricesKrishna Myneni
+* Re: Inefficiency of FSL matricesminforth
|`* Re: Inefficiency of FSL matricesKrishna Myneni
| `* Re: Inefficiency of FSL matricesKrishna Myneni
|  `* Re: Inefficiency of FSL matricesminforth
|   `* Re: Inefficiency of FSL matricesmhx
|    `* Re: Inefficiency of FSL matricesminforth
|     `* Re: Inefficiency of FSL matricesmhx
|      +* Re: Inefficiency of FSL matricesdxf
|      |`* locals (was: Inefficiency of FSL matrices)Anton Ertl
|      | +* Re: locals (was: Inefficiency of FSL matrices)none
|      | |+* Re: localsmhx
|      | ||`- Re: localsnone
|      | |`- Re: localsPaul Rubin
|      | +* Re: localsdxf
|      | |`* Re: localsPaul Rubin
|      | | `- Re: localsdxf
|      | `* Re: localsdxf
|      |  +- Re: localsnone
|      |  `* Re: localsBernd Linsel
|      |   `- Re: localsdxf
|      `* Re: Inefficiency of FSL matricesminforth
|       `* Re: Inefficiency of FSL matricesmhx
|        `* Re: Inefficiency of FSL matricesminforth
|         `* Re: Inefficiency of FSL matricesmhx
|          `* Re: Inefficiency of FSL matricesminforth
|           `* Re: Inefficiency of FSL matricesminforth
|            +- Re: Inefficiency of FSL matricesminforth
|            `- Re: Inefficiency of FSL matricesmhx
+* Re: Inefficiency of FSL matricesKrishna Myneni
|+* Re: Inefficiency of FSL matricesKrishna Myneni
||`- Re: Inefficiency of FSL matricesKrishna Myneni
|`* Re: Inefficiency of FSL matricesKrishna Myneni
| `* Re: Inefficiency of FSL matricesminforth
|  `* Re: Inefficiency of FSL matricesKrishna Myneni
|   +* Re: Inefficiency of FSL matricesminforth
|   |`- Re: Inefficiency of FSL matricesKrishna Myneni
|   +* Re: Inefficiency of FSL matricesKrishna Myneni
|   |`* Re: Inefficiency of FSL matricesKrishna Myneni
|   | `* Re: Inefficiency of FSL matricesKrishna Myneni
|   |  `- Re: Inefficiency of FSL matricesminforth
|   `* Re: Inefficiency of FSL matricesAnton Ertl
|    `* Re: Inefficiency of FSL matricesKrishna Myneni
|     +* Re: Inefficiency of FSL matricesPMF
|     |`* Re: Inefficiency of FSL matricesKrishna Myneni
|     | +* Re: Inefficiency of FSL matricesminforth
|     | |`* Re: Inefficiency of FSL matricesKrishna Myneni
|     | | +- Re: Inefficiency of FSL matricesnone
|     | | `* Re: Inefficiency of FSL matricesminforth
|     | |  `* Re: Inefficiency of FSL matricesKrishna Myneni
|     | |   `* Re: Inefficiency of FSL matricesminforth
|     | |    `- Re: Inefficiency of FSL matricesKrishna Myneni
|     | `* Re: Inefficiency of FSL matricesAnton Ertl
|     |  `- Re: Inefficiency of FSL matricesKrishna Myneni
|     `* Re: Inefficiency of FSL matricesAnton Ertl
|      `* Re: Inefficiency of FSL matricesKrishna Myneni
|       `* SET-OPTIMIZER etc. (was: Inefficiency of FSL matrices)Anton Ertl
|        +* Re: SET-OPTIMIZER etc. (was: Inefficiency of FSL matrices)Krishna Myneni
|        |`- Re: SET-OPTIMIZER etc.dxf
|        `* Re: SET-OPTIMIZER etc.minforth
|         `* Re: SET-OPTIMIZER etc.Anton Ertl
|          `* Re: SET-OPTIMIZER etc.dxf
|           `* Re: SET-OPTIMIZER etc.Anton Ertl
|            `* Re: SET-OPTIMIZER etc.dxf
|             +- Re: SET-OPTIMIZER etc.none
|             +* Re: SET-OPTIMIZER etc.sjack
|             |`- Re: SET-OPTIMIZER etc.dxf
|             `* Re: SET-OPTIMIZER etc.Anton Ertl
|              `- Re: SET-OPTIMIZER etc.dxf
`- Re: Inefficiency of FSL matricesKrishna Myneni

Pages:123
Inefficiency of FSL matrices

<uldipg$12lpv$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25615&group=comp.lang.forth#25615

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Inefficiency of FSL matrices
Date: Wed, 13 Dec 2023 18:38:06 -0600
Organization: A noiseless patient Spider
Lines: 98
Message-ID: <uldipg$12lpv$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 14 Dec 2023 00:38:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3e229c8a608e138341d408fad912793e";
logging-data="1136447"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OTtGcn98CeGMlOrYGf/hv"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:c5NiJuhHwUlTdAjv5TZADAYqG8I=
Content-Language: en-US
 by: Krishna Myneni - Thu, 14 Dec 2023 00:38 UTC

The array and matrix definitions given in the FSL utilities source,

fsl-util.x
or
fsl_util.x.

The arrays are quite nice for their flexibility in making arrays out of
any type of data, and are useful in many instances. However, the source
definitions are slow on non-optimizing Forth systems.

I believe the design of the arrays and matrices traces back to Julian
Noble's, "Scientific Forth." A 1-D array is named with a trailing left
brace "{" while 2-D matrices have a trailing double left brace, "{{".
This allows a convenient notation

a{ I } \ resolves to address of array element I
m{{ J I }} \ resolves to address of matrix element at row J, col I

The indices are 0-origin, so the first element of the array named a{ is
stored at address

a{ 0 }

and the top left element of the matrix named m{{ is stored at address

m{{ 0 0 }}

Creation of fixed size arrays and matrices is performed with the parsing
words

ARRAY
MATRIX

and the size of each element is one of the arguments on the stack, so,
typically, we can write

36 FLOAT ARRAY a{ \ create array named "a{" with 36 elements of size
FLOAT (a constant, usually 8 bytes)

120 48 INTEGER MATRIX m{{ \ create matrix named "m{{" with 120 rows and
48 columns of size INTEGER (a cell size in bytes)

There are provisions for creating dynamically allocated arrays as well.

The operators "}" and "}}" resolve the adress of the indexed element of
the specified array, and this is where the inefficiency lies. I've been
tempted to make "}" and "}}" machine code primitives for these words to
increase their speed in kForth. It seems unlikely though that the words
"}" and "}}" would be generally adopted as common use words, so I have
not made them built-in words.

To give you an idea of the efficiency hit from using these words versus
custom arrays of fixed size elements, I tested numerically intensive
code using a custom matrix of double precision floats, with index and
fetch, and index and store words:
]]F@
]]F!
The code and definitions for the two words above are found in the
program, pde1.4th, at the link provided.

Next, I created a version of pde1.4th which used FSL matrices and no
extra optimizations, with the notation described earlier e.g. for a
floating point matrix,

m{{ J I }} F@ and m{{ J I }} F!

Some typical execution times with the custom matrix fetch and store
words versus the typical FSL matrix word usage are,

Custom matrices: 9656 ms
FSL matrices: 20474 ms

The above timings use kForth-64 to time the word SOLVE for the
RECTangular boundary value problem, with a specified tolerance of 1E-16.

kforth32 has similar timings (kforth32-fast performs much faster).

Some optimization is clearly needed on the FSL array and matrix definitions.

The FSL definitions of ARRAY and MATRIX in kForth may be found in its
fsl-util.4th file at the link given below.

--
Krishna Myneni

Links to code mentioned above:

https://github.com/mynenik/kForth-64/blob/master/forth-src/pde1.4th

https://github.com/mynenik/kForth-64/blob/master/forth-src/fsl/fsl-util.4th

Re: Inefficiency of FSL matrices

<2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25616&group=comp.lang.forth#25616

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!.POSTED!not-for-mail
From: minforth@gmx.net (minforth)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Thu, 14 Dec 2023 12:44:32 +0000
Organization: novaBBS
Message-ID: <2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com>
References: <uldipg$12lpv$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="4088342"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Posting-User: 0d6d33dbe0e2e1ff58b82acfc1a8a32ac3b1cb72
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on novalink.us
X-Rslight-Site: $2y$10$IClkup.kvisipQySW79nF.bt.3yzSk00LPOeb5xHl3jC5xeFbNg8W
 by: minforth - Thu, 14 Dec 2023 12:44 UTC

Interesting, but the performance gain is not surprising
if you use matrix-adapted primitives.

Just for comparison:
I use different internal representations for vectors and
matrices. Vectors are simple fp-number fields. Matrices
in the heap are fat data and have a header for dimension,
numeric type and reference count. Matrices can only be
referenced via matrix-values (or matrix-stack elements).

The compiler automatically generates the correct and
therefore performant type-dependent code for
<indices> } -> matrix element
<indices> }^ -> address of the element
<indices> }! -> write matrix element

This is of course not FSL syntax, but more readable IMO.
There are also slices, but that is not the topic here.

Re: Inefficiency of FSL matrices

<ulf8ai$1el02$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25618&group=comp.lang.forth#25618

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!news.niel.me!news.gegeweb.eu!gegeweb.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Thu, 14 Dec 2023 09:51:44 -0600
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <ulf8ai$1el02$1@dont-email.me>
References: <uldipg$12lpv$1@dont-email.me>
<2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 14 Dec 2023 15:51:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3e229c8a608e138341d408fad912793e";
logging-data="1528834"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wHIglDdabXG3u6C2y3DFq"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:dqtTAr6w5kFMHtGT1bWXkpDsQDA=
Content-Language: en-US
In-Reply-To: <2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com>
 by: Krishna Myneni - Thu, 14 Dec 2023 15:51 UTC

On 12/14/23 06:44, minforth wrote:
> Interesting, but the performance gain is not surprising
> if you use matrix-adapted primitives.
>
> Just for comparison:
> I use different internal representations for vectors and
> matrices. Vectors are simple fp-number fields. Matrices
> in the heap are fat data and have a header for dimension,
> numeric type and reference count. Matrices can only be
> referenced via matrix-values (or matrix-stack elements).
>
How do you implement vectors of different types other than fp-numbers?
Do you use a full-blown matrix then?

> The compiler automatically generates the correct and
> therefore performant type-dependent code for

In the FSL, this can be done for statically alloted arrays and matrices,
when the "}" and "}}" words can determine the element size (+number of
columns for a matrix) at compile-time, by making them IMMEDIATE words.

I don't see how the element-size-specific reference can be done for
dynamic arrays and matrices at compile-time, when the element size and
number of columns are not known.

Another drawback would be having to make "}" and "}}" state-dependent
words (on single-xt systems).

> <indices> } -> matrix element
> <indices> }^ -> address of the element
> <indices> }!  -> write matrix element
>
> This is of course not FSL syntax, but more readable IMO.
> There are also slices, but that is not the topic here.

I prefer the symmetry of the FSL syntax. If you used }@ it would be more
symmetric but you might not like the added visual noise. Again, it would
not be possible for }@ to compile an element-size-specific reference on
dynamically declared matrices.

--
Krishna

Re: Inefficiency of FSL matrices

<ulfad7$1eto4$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25619&group=comp.lang.forth#25619

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!news.furie.org.uk!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Thu, 14 Dec 2023 10:27:19 -0600
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <ulfad7$1eto4$1@dont-email.me>
References: <uldipg$12lpv$1@dont-email.me>
<2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com>
<ulf8ai$1el02$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 14 Dec 2023 16:27:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3e229c8a608e138341d408fad912793e";
logging-data="1537796"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191iM6lTKw2AF8qKM2JjcCw"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:I/1E4qBwJpQh4N70CDFdzFnlb3M=
Content-Language: en-US
In-Reply-To: <ulf8ai$1el02$1@dont-email.me>
 by: Krishna Myneni - Thu, 14 Dec 2023 16:27 UTC

On 12/14/23 09:51, Krishna Myneni wrote:
> On 12/14/23 06:44, minforth wrote:
....
>> The compiler automatically generates the correct and
>> therefore performant type-dependent code for
>
> In the FSL, this can be done for statically alloted arrays and matrices,
> when the "}" and "}}" words can determine the element size (+number of
> columns for a matrix) at compile-time, by making them IMMEDIATE words.
>
> I don't see how the element-size-specific reference can be done for
> dynamic arrays and matrices at compile-time, when the element size and
> number of columns are not known.
>

Correction: For FSL dynamic arrays and matrices the element size is
known at compile time. For FSL dynamic matrices the number of columns is
not known at compile time, so it would always have to retrieved at run-time.

--
Krishna

Re: Inefficiency of FSL matrices

<4fedc3d9476633a3edb0300c21a4eb35@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25622&group=comp.lang.forth#25622

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!.POSTED!not-for-mail
From: minforth@gmx.net (minforth)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Fri, 15 Dec 2023 08:50:38 +0000
Organization: novaBBS
Message-ID: <4fedc3d9476633a3edb0300c21a4eb35@news.novabbs.com>
References: <uldipg$12lpv$1@dont-email.me> <2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com> <ulf8ai$1el02$1@dont-email.me> <ulfad7$1eto4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="4172970"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Posting-User: 0d6d33dbe0e2e1ff58b82acfc1a8a32ac3b1cb72
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on novalink.us
X-Rslight-Site: $2y$10$kBjgi3DNXUy/SpXVwhN9ae4Rkyt3zaAcNGr8WsJJedmZLqKoS.LUC
 by: minforth - Fri, 15 Dec 2023 08:50 UTC

The details of the implementation would go too far here. Essentially,
my matrices are objects with methods for reading and writing cells
(and slices). There is a matrix stack with pointers to a pre-allocated
pool of empty matrix objects in the heap at the start of the programme.
Other frequently used global matrix values are also predefined.
This allows a lot of early-binding during compilation.

In Forth jargon, the matrices do not have single cell execution tokens,
but structs that carry type information (and other states). It is
therefore not a standard Forth. Available primitive data types are
integers, float24, float32, float64 (and compound types with companion bits).

As visual syntax example an older PLU factorisation (today primitive):

: MPLU ( m: m -- m: l p u ) PLU factorization
?square mrows meye mswap mrows dup mzeros mswap ( p l u ) mrows
FOR n n mcpivot v0~ IF -408 throw THEN
dup n = IF drop ELSE mrot dup n mrswap mrot dup n mrswap mrot n mrswap THEN
m[ n n ] 1. m'[ n n ]! mrows n 1+
?DO m[ i n ]^ dup v@ fover f/ fdup i n mrmulsub 0. v! m'[ i n ]!
LOOP fdrop
NEXT ;

(M[ means the top, M'[ the second matrix matrix on the matrix stack, and
as you can see, floats have been assumed here)

Re: Inefficiency of FSL matrices

<60741e632ae54e48027caaaec2751b66@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25623&group=comp.lang.forth#25623

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!.POSTED!not-for-mail
From: mhx@iae.nl (mhx)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Fri, 15 Dec 2023 10:47:21 +0000
Organization: novaBBS
Message-ID: <60741e632ae54e48027caaaec2751b66@news.novabbs.com>
References: <uldipg$12lpv$1@dont-email.me> <2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com> <ulf8ai$1el02$1@dont-email.me> <ulfad7$1eto4$1@dont-email.me> <4fedc3d9476633a3edb0300c21a4eb35@news.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="4182238"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$eruxdGCL3SsdBaYzy/9sP..oaJsmEJGJcVGBEzbEb4X80Yu1AU9Zi
X-Rslight-Posting-User: 463cbf1a76c808942982a163321348c75477c065
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on novalink.us
 by: mhx - Fri, 15 Dec 2023 10:47 UTC

minforth wrote:

> The details of the implementation would go too far here. Essentially,
> my matrices are objects with methods for reading and writing cells
> (and slices). There is a matrix stack with pointers to a pre-allocated
> pool of empty matrix objects in the heap at the start of the programme.
> Other frequently used global matrix values are also predefined.
> This allows a lot of early-binding during compilation.

This is also the approach I have chosen for iForth. However, there I have
no need for a matrix stack (the parameter stack is perfectly well
suited to handle the matrix/array struct pointers).
I also have a pool of "local" matrix objects. It is possible to write
words for e.g. matrix inversion that work independent of type (byte,
word, cell, sfloat, dfloat, float, xfloat, ddouble, complex, arbitrary
precision ...)

I kept the FSL notation A{{ }} B{ } but there are new words to
access the struct fields: A{{ DIMS , B{ DADDR C{{ DSIZE etc..

-marcel

Re: Inefficiency of FSL matrices

<a3af4cd21357d8a1ce502533d21c5545@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25625&group=comp.lang.forth#25625

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!.POSTED!not-for-mail
From: minforth@gmx.net (minforth)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Fri, 15 Dec 2023 11:19:04 +0000
Organization: novaBBS
Message-ID: <a3af4cd21357d8a1ce502533d21c5545@news.novabbs.com>
References: <uldipg$12lpv$1@dont-email.me> <2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com> <ulf8ai$1el02$1@dont-email.me> <ulfad7$1eto4$1@dont-email.me> <4fedc3d9476633a3edb0300c21a4eb35@news.novabbs.com> <60741e632ae54e48027caaaec2751b66@news.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="4184662"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Posting-User: 0d6d33dbe0e2e1ff58b82acfc1a8a32ac3b1cb72
X-Rslight-Site: $2y$10$GD1XiQuyJGVMv0Iwph4VROIEwsscdaqbilXsbD4VO0zGmCwiBZQQm
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on novalink.us
 by: minforth - Fri, 15 Dec 2023 11:19 UTC

mhx wrote:

> minforth wrote:

>> The details of the implementation would go too far here. Essentially,
>> my matrices are objects with methods for reading and writing cells
>> (and slices). There is a matrix stack with pointers to a pre-allocated
>> pool of empty matrix objects in the heap at the start of the programme.
>> Other frequently used global matrix values are also predefined.
>> This allows a lot of early-binding during compilation.

> This is also the approach I have chosen for iForth. However, there I have
> no need for a matrix stack (the parameter stack is perfectly well
> suited to handle the matrix/array struct pointers).

Yes, that works. The mstack is also there for historical reasons, because
matrix pointers used to be fat pointers. With the introduction of copy-on-write,
this was no longer suitable. In addition, the normal integer and fp data stacks
are full enough with other things, so the mstack is also useful for clearer code.

Re: Inefficiency of FSL matrices

<a9a8dae485cad3607fcfde86b93330eb@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25627&group=comp.lang.forth#25627

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!.POSTED!not-for-mail
From: mhx@iae.nl (mhx)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Fri, 15 Dec 2023 11:28:46 +0000
Organization: novaBBS
Message-ID: <a9a8dae485cad3607fcfde86b93330eb@news.novabbs.com>
References: <uldipg$12lpv$1@dont-email.me> <2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com> <ulf8ai$1el02$1@dont-email.me> <ulfad7$1eto4$1@dont-email.me> <4fedc3d9476633a3edb0300c21a4eb35@news.novabbs.com> <60741e632ae54e48027caaaec2751b66@news.novabbs.com> <a3af4cd21357d8a1ce502533d21c5545@news.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="4185461"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Posting-User: 463cbf1a76c808942982a163321348c75477c065
X-Rslight-Site: $2y$10$SnC5EgXTu5GZo8Fm3yax4uwAm3xkwymPck5ZE2GJnhuBXoFXZzWGu
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on novalink.us
 by: mhx - Fri, 15 Dec 2023 11:28 UTC

minforth wrote:
[..]
> In addition, the normal integer and fp data stacks
> are full enough with other things, so the mstack is also useful for clearer code.

It probably comes as no surprise that I find locals to be a perfect solution
for that.

-marcel

Re: Inefficiency of FSL matrices

<ulhpd7$1uifl$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25628&group=comp.lang.forth#25628

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Fri, 15 Dec 2023 08:55:33 -0600
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <ulhpd7$1uifl$1@dont-email.me>
References: <uldipg$12lpv$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 15 Dec 2023 14:55:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5ddefc9e511c8d78373df678c29cf6a4";
logging-data="2050549"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+aXGACBISlSyRSUjBE904Y"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:UBdJu7GIisZ5TqsSyKZvKwdrVxE=
Content-Language: en-US
In-Reply-To: <uldipg$12lpv$1@dont-email.me>
 by: Krishna Myneni - Fri, 15 Dec 2023 14:55 UTC

On 12/13/23 18:38, Krishna Myneni wrote:
....
> The operators "}" and "}}" resolve the adress of the indexed element of
> the specified array, and this is where the inefficiency lies. I've been
> tempted to make "}" and "}}" machine code primitives for these words to
> increase their speed in kForth. It seems unlikely though that the words
> "}" and "}}" would be generally adopted as common use words, so I have
> not made them built-in words.
>

I think the best approach forward for me, in kForth, is to include
efficient primitives in Forth system,

FSL_ARRAY_EL_REF ( a_arr nidx -- )
FSL_MATRIX_EL_REF ( a_mat nidx midx -- )

Then, in fsl-util.4th, "}" and "}}" may be declared to be synonyms for
these primitives, or something else if the user prefers a different
implementation of arrays and matrices.

--
Krishna

Re: Inefficiency of FSL matrices

<uliunj$24g19$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25631&group=comp.lang.forth#25631

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dxforth@gmail.com (dxf)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Sat, 16 Dec 2023 12:32:36 +1100
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <uliunj$24g19$1@dont-email.me>
References: <uldipg$12lpv$1@dont-email.me>
<2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com>
<ulf8ai$1el02$1@dont-email.me> <ulfad7$1eto4$1@dont-email.me>
<4fedc3d9476633a3edb0300c21a4eb35@news.novabbs.com>
<60741e632ae54e48027caaaec2751b66@news.novabbs.com>
<a3af4cd21357d8a1ce502533d21c5545@news.novabbs.com>
<a9a8dae485cad3607fcfde86b93330eb@news.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 16 Dec 2023 01:32:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="74537a2c5f872cef6ded09846e64a083";
logging-data="2244649"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Yf/49UTpgxw2Xe9SUzYyU"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Bz+nlVkQ+iKcKkwPxBahVqKctVE=
Content-Language: en-GB
In-Reply-To: <a9a8dae485cad3607fcfde86b93330eb@news.novabbs.com>
 by: dxf - Sat, 16 Dec 2023 01:32 UTC

On 15/12/2023 10:28 pm, mhx wrote:
> minforth wrote:
> [..]
>> In addition, the normal integer and fp data stacks
>> are full enough with other things, so the mstack is also useful for clearer code.
>
> It probably comes as no surprise that I find locals to be a perfect solution
> for that.

Nor the only one. But as Jeff Fox explains:

"Forth is about words. Words have names. The choice of the names of the words
in Forth is certainly one of the most important things. And given that humans
have limited minds there should be a focus on what words are important. That's
why it was considered important in the design of Forth to put emphasis on not
having to name every temporary storage location. It has a name. It is a called
a stack. The point being here that you don't have to name items on a stack.
If you think you want to name the temporary items on the stack you are missing
the most important design features of the language."

https://groups.google.com/g/comp.lang.forth/c/ef7xV5y6ddg/m/wGI0Q4D69GMJ

One of the few things in Google's c.l.f. archive actually worth bookmarking ...
though it wouldn't be needed were it uppermost in every forther's thinking.

locals (was: Inefficiency of FSL matrices)

<2023Dec16.084551@mips.complang.tuwien.ac.at>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25632&group=comp.lang.forth#25632

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: locals (was: Inefficiency of FSL matrices)
Date: Sat, 16 Dec 2023 07:45:51 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 24
Message-ID: <2023Dec16.084551@mips.complang.tuwien.ac.at>
References: <uldipg$12lpv$1@dont-email.me> <2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com> <ulf8ai$1el02$1@dont-email.me> <ulfad7$1eto4$1@dont-email.me> <4fedc3d9476633a3edb0300c21a4eb35@news.novabbs.com> <60741e632ae54e48027caaaec2751b66@news.novabbs.com> <a3af4cd21357d8a1ce502533d21c5545@news.novabbs.com> <a9a8dae485cad3607fcfde86b93330eb@news.novabbs.com> <uliunj$24g19$1@dont-email.me>
Injection-Info: dont-email.me; posting-host="93a45da3cc58c9ae8f2434f1f769d1a4";
logging-data="2467460"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197+gDxDlYYEEbO09rzIukE"
Cancel-Lock: sha1:d5HXnpTh2bWbobooGGAUxlpEfw4=
X-newsreader: xrn 10.11
 by: Anton Ertl - Sat, 16 Dec 2023 07:45 UTC

dxf <dxforth@gmail.com> writes:
>But as Jeff Fox explains:
>
>"Forth is about words. Words have names. The choice of the names of the words
> in Forth is certainly one of the most important things. And given that humans
> have limited minds there should be a focus on what words are important. That's
> why it was considered important in the design of Forth to put emphasis on not
> having to name every temporary storage location. It has a name. It is a called
> a stack. The point being here that you don't have to name items on a stack.
> If you think you want to name the temporary items on the stack you are missing
> the most important design features of the language."

I don't see how the last sentence follows from the stuff he wrote
before.

And Chuck Moore and others who do not use locals do not practice what
Jeff Fox preached. They just use VARIABLEs instead of locals.

- 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 2023: https://euro.theforth.net/2023

Re: locals (was: Inefficiency of FSL matrices)

<nnd$71287211$64afbf8a@f32971eeaf24f233>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25633&group=comp.lang.forth#25633

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
Subject: Re: locals (was: Inefficiency of FSL matrices)
References: <uldipg$12lpv$1@dont-email.me> <a9a8dae485cad3607fcfde86b93330eb@news.novabbs.com> <uliunj$24g19$1@dont-email.me> <2023Dec16.084551@mips.complang.tuwien.ac.at>
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$71287211$64afbf8a@f32971eeaf24f233>
Organization: KPN B.V.
Date: Sat, 16 Dec 2023 11:17:54 +0100
Path: i2pn2.org!i2pn.org!news.swapon.de!news.in-chemnitz.de!3.eu.feeder.erje.net!feeder.erje.net!feed.abavia.com!abe004.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 29
Injection-Date: Sat, 16 Dec 2023 11:17:54 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: none - Sat, 16 Dec 2023 10:17 UTC

In article <2023Dec16.084551@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>
>I don't see how the last sentence follows from the stuff he wrote
>before.
>
>And Chuck Moore and others who do not use locals do not practice what
>Jeff Fox preached. They just use VARIABLEs instead of locals.

If I want named local storage I use VARIABLE's. There is a
reentrant and a information hiding aspect to LOCAL's.
I forego the reentrant aspect and attain information hiding if needed
with other means with VARIABLE's or whatever other data structure.

It is not a good to duplicate VARIABLE's with LOCAL's
DVARIABLE's with DLOCAL's FVARIABLE's with DLOCAL's etc.
Parsing with TO is an abuse of the powers of Forth.

Agree to disagree. Should be in the FAQ.

>- anton

Albert van der Horst
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: locals

<cbdb4357523903a4fbdf42e68ac9690e@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25635&group=comp.lang.forth#25635

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!.POSTED!not-for-mail
From: mhx@iae.nl (mhx)
Newsgroups: comp.lang.forth
Subject: Re: locals
Date: Sat, 16 Dec 2023 12:27:43 +0000
Organization: novaBBS
Message-ID: <cbdb4357523903a4fbdf42e68ac9690e@news.novabbs.com>
References: <uldipg$12lpv$1@dont-email.me> <a9a8dae485cad3607fcfde86b93330eb@news.novabbs.com> <uliunj$24g19$1@dont-email.me> <2023Dec16.084551@mips.complang.tuwien.ac.at> <nnd$71287211$64afbf8a@f32971eeaf24f233>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="104313"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Posting-User: 463cbf1a76c808942982a163321348c75477c065
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on novalink.us
X-Rslight-Site: $2y$10$M9/K9rr5smH4BSuMt5B3Q.BGF2ddPzCQl0c6fTrv0pW2h2m9VvJ6O
 by: mhx - Sat, 16 Dec 2023 12:27 UTC

none wrote:

> It is not a good to duplicate VARIABLE's with LOCAL's
> DVARIABLE's with DLOCAL's FVARIABLE's with DLOCAL's etc.

I don't understand why it should be a discussion. Even if
Forth didn't have a LOCAL concept, users could add it.

[ BTW, it's not just classical re-entrancy. If a word is
used from more than one location in a bigger program,
its variables have to be duplicated. Where do you
put the copies? ]

> Parsing with TO is an abuse of the powers of Forth.

Are we preachers or engineers?

-marcel

Re: locals

<nnd$730fc28a$479b9c12@47d9a5c011e39ac1>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25636&group=comp.lang.forth#25636

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
Subject: Re: locals
References: <uldipg$12lpv$1@dont-email.me> <2023Dec16.084551@mips.complang.tuwien.ac.at> <nnd$71287211$64afbf8a@f32971eeaf24f233> <cbdb4357523903a4fbdf42e68ac9690e@news.novabbs.com>
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$730fc28a$479b9c12@47d9a5c011e39ac1>
Organization: KPN B.V.
Date: Sat, 16 Dec 2023 14:05:21 +0100
Path: i2pn2.org!i2pn.org!nntp.comgw.net!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe006.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 20
Injection-Date: Sat, 16 Dec 2023 14:05:21 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 1572
 by: none - Sat, 16 Dec 2023 13:05 UTC

In article <cbdb4357523903a4fbdf42e68ac9690e@news.novabbs.com>,
mhx <mhx@iae.nl> wrote:
>none wrote:
<SNIP>
>[ BTW, it's not just classical re-entrancy. If a word is
> used from more than one location in a bigger program,
> its variables have to be duplicated. Where do you
> put the copies? ]
They are local variables, so they don't need duplicates.
You're entrenched in LOCAl such that you don't understand
any more what local variables as a concept are.

>
>-marcel
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: locals

<87ttohuy4k.fsf@nightsong.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25637&group=comp.lang.forth#25637

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.forth
Subject: Re: locals
Date: Sat, 16 Dec 2023 22:44:11 -0800
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <87ttohuy4k.fsf@nightsong.com>
References: <uldipg$12lpv$1@dont-email.me>
<a9a8dae485cad3607fcfde86b93330eb@news.novabbs.com>
<uliunj$24g19$1@dont-email.me>
<2023Dec16.084551@mips.complang.tuwien.ac.at>
<nnd$71287211$64afbf8a@f32971eeaf24f233>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="3cd737f07836f1e9e12369641304040b";
logging-data="2969788"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18s/DMZDW/s9FusS5F5XgEA"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:oAFw71z+K7NdAHmOyizKIje0BJU=
sha1:aG2tlXJMoR37ztGXqq7XMaEam5Q=
 by: Paul Rubin - Sun, 17 Dec 2023 06:44 UTC

albert@cherry.(none) (albert) writes:
> DVARIABLE's with DLOCAL's FVARIABLE's with DLOCAL's etc.
> Parsing with TO is an abuse of the powers of Forth.

Whatever problems might result from TO are completely separate from
whatever problems might result from locals.

Re: locals

<ulm715$2q4ge$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25638&group=comp.lang.forth#25638

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dxforth@gmail.com (dxf)
Newsgroups: comp.lang.forth
Subject: Re: locals
Date: Sun, 17 Dec 2023 18:12:37 +1100
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <ulm715$2q4ge$1@dont-email.me>
References: <uldipg$12lpv$1@dont-email.me>
<2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com>
<ulf8ai$1el02$1@dont-email.me> <ulfad7$1eto4$1@dont-email.me>
<4fedc3d9476633a3edb0300c21a4eb35@news.novabbs.com>
<60741e632ae54e48027caaaec2751b66@news.novabbs.com>
<a3af4cd21357d8a1ce502533d21c5545@news.novabbs.com>
<a9a8dae485cad3607fcfde86b93330eb@news.novabbs.com>
<uliunj$24g19$1@dont-email.me> <2023Dec16.084551@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 17 Dec 2023 07:12:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c8d4e87445c04bba09085eafec09c64e";
logging-data="2953742"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OABp3Zq6BLfqLhVkX3QK1"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:OZeD88YO/EHOSNbkVwf9OOtoNGw=
Content-Language: en-GB
In-Reply-To: <2023Dec16.084551@mips.complang.tuwien.ac.at>
 by: dxf - Sun, 17 Dec 2023 07:12 UTC

On 16/12/2023 6:45 pm, Anton Ertl wrote:
> dxf <dxforth@gmail.com> writes:
>> But as Jeff Fox explains:
>>
>> "Forth is about words. Words have names. The choice of the names of the words
>> in Forth is certainly one of the most important things. And given that humans
>> have limited minds there should be a focus on what words are important. That's
>> why it was considered important in the design of Forth to put emphasis on not
>> having to name every temporary storage location. It has a name. It is a called
>> a stack. The point being here that you don't have to name items on a stack.
>> If you think you want to name the temporary items on the stack you are missing
>> the most important design features of the language."
>
> I don't see how the last sentence follows from the stuff he wrote
> before.

I saw it as a summation.

> And Chuck Moore and others who do not use locals do not practice what
> Jeff Fox preached. They just use VARIABLEs instead of locals.

If I use VARIABLEs as locals it is admission I was beaten. I try to keep
that to a minimum :)

Re: locals

<87plz5uvha.fsf@nightsong.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25639&group=comp.lang.forth#25639

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.forth
Subject: Re: locals
Date: Sat, 16 Dec 2023 23:41:21 -0800
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <87plz5uvha.fsf@nightsong.com>
References: <uldipg$12lpv$1@dont-email.me>
<2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com>
<ulf8ai$1el02$1@dont-email.me> <ulfad7$1eto4$1@dont-email.me>
<4fedc3d9476633a3edb0300c21a4eb35@news.novabbs.com>
<60741e632ae54e48027caaaec2751b66@news.novabbs.com>
<a3af4cd21357d8a1ce502533d21c5545@news.novabbs.com>
<a9a8dae485cad3607fcfde86b93330eb@news.novabbs.com>
<uliunj$24g19$1@dont-email.me>
<2023Dec16.084551@mips.complang.tuwien.ac.at>
<ulm715$2q4ge$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="3cd737f07836f1e9e12369641304040b";
logging-data="2986293"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+QD4R3df2giD6E08zhpZhd"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:f+LcGtw7390dKPdJftp5dMeVio8=
sha1:c5yIIDxwQi3yE97qNhWVsxlcTdI=
 by: Paul Rubin - Sun, 17 Dec 2023 07:41 UTC

dxf <dxforth@gmail.com> writes:
> If I use VARIABLEs as locals it is admission I was beaten. I try to keep
> that to a minimum :)

I can't think of Forth as a HLL if users are supposed to do what amounts
to pipeline scheduling and register allocation in their head, planning
out the stack juggling and so on.

Re: locals

<ulmbti$2q4ge$2@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25640&group=comp.lang.forth#25640

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dxforth@gmail.com (dxf)
Newsgroups: comp.lang.forth
Subject: Re: locals
Date: Sun, 17 Dec 2023 19:36:02 +1100
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <ulmbti$2q4ge$2@dont-email.me>
References: <uldipg$12lpv$1@dont-email.me>
<2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com>
<ulf8ai$1el02$1@dont-email.me> <ulfad7$1eto4$1@dont-email.me>
<4fedc3d9476633a3edb0300c21a4eb35@news.novabbs.com>
<60741e632ae54e48027caaaec2751b66@news.novabbs.com>
<a3af4cd21357d8a1ce502533d21c5545@news.novabbs.com>
<a9a8dae485cad3607fcfde86b93330eb@news.novabbs.com>
<uliunj$24g19$1@dont-email.me> <2023Dec16.084551@mips.complang.tuwien.ac.at>
<ulm715$2q4ge$1@dont-email.me> <87plz5uvha.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 17 Dec 2023 08:36:02 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c8d4e87445c04bba09085eafec09c64e";
logging-data="2953742"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18SCRJoSOP9nNyX9og3v7Oc"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:9a02KOxnzZW0RrF/grCo12VrAbs=
Content-Language: en-GB
In-Reply-To: <87plz5uvha.fsf@nightsong.com>
 by: dxf - Sun, 17 Dec 2023 08:36 UTC

On 17/12/2023 6:41 pm, Paul Rubin wrote:
> dxf <dxforth@gmail.com> writes:
>> If I use VARIABLEs as locals it is admission I was beaten. I try to keep
>> that to a minimum :)
>
> I can't think of Forth as a HLL if users are supposed to do what amounts
> to pipeline scheduling and register allocation in their head, planning
> out the stack juggling and so on.

I can't think of using Forth over an HLL - unless I believe I can do better
and have the means. Otherwise I'm just coding C in RPN and who needs that.

Re: Inefficiency of FSL matrices

<ulnnh1$343kn$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25648&group=comp.lang.forth#25648

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Sun, 17 Dec 2023 15:00:16 -0600
Organization: A noiseless patient Spider
Lines: 116
Message-ID: <ulnnh1$343kn$1@dont-email.me>
References: <uldipg$12lpv$1@dont-email.me> <ulhpd7$1uifl$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 17 Dec 2023 21:00:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6fc1becd8d49913de5a539bf36eb5ff0";
logging-data="3280535"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xsQPhQLPlFtD2FWqefNaS"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:eKQl2ZhiPdz/3GXglAR4vDGxP0Q=
Content-Language: en-US
In-Reply-To: <ulhpd7$1uifl$1@dont-email.me>
 by: Krishna Myneni - Sun, 17 Dec 2023 21:00 UTC

On 12/15/23 08:55, Krishna Myneni wrote:
> On 12/13/23 18:38, Krishna Myneni wrote:
> ...
>> The operators "}" and "}}" resolve the adress of the indexed element
>> of the specified array, and this is where the inefficiency lies. I've
>> been tempted to make "}" and "}}" machine code primitives for these
>> words to increase their speed in kForth. It seems unlikely though that
>> the words "}" and "}}" would be generally adopted as common use words,
>> so I have not made them built-in words.
>>
>
> I think the best approach forward for me, in kForth, is to include
> efficient primitives in Forth system,
>
> FSL_ARRAY_EL_REF    ( a_arr nidx -- )
> FSL_MATRIX_EL_REF   ( a_mat nidx midx -- )
>
....

I'm implementing "}}" as an intrinsic word in kForth, for use with FSL
matrices. In order to test new implementations and benchmark them
against different versions including the original source code version
from the kForth fsl-util.4th file, I wrote a benchmark program which
also performs elementary tests on "}}". The existing source code version
of "}}" for FSL-style, row-ordered matrices, is

: }} ( addr i j -- addr[i][j] )
>R >R
DUP [ 2 CELLS ] LITERAL - 2@ \ &a[0][0] size m
R> * R> + * + ;

In addition to the automated tests on the implementation of "}}", the
benchmark program generates a random 256x256 floating point matrix and
can perform a specified number of fetches from random row and column
locations -- a typical number would be 1,000,000 random accesses from
the matrix.

--- example use ---
include bench-fsl-matrix

FSL-UTIL V1.3c 11 Sep 2021 EFC, KM

TESTING }}

Filling 256x256 floating point matrix with random values ...
Benchmark: "ms@ 1000000 random-matrix-access ms@ swap - ." ok
ok

ms@ 1000000 random-matrix-access ms@ swap - .
454 ok
--- end of example ---

The testing and benchmark program is given below.

--- start of program ---
\ bench-fsl-matrix.4th
\ \ Benchmark the implementation of }}
\ \ Krishna Myneni, 2023-12-17

include ans-words
include random
include ttester
include fsl/fsl-util

\ Basic tests on }}
4 constant NROWS
16 constant NCOLS
NROWS NCOLS float matrix b{{
cr
TESTING }}
t{ b{{ b{{ 0 0 }} = -> true }t
t{ b{{ float+ b{{ 0 1 }} = -> true }t
t{ b{{ NCOLS floats + b{{ 1 0 }} = -> true }t
t{ b{{ NROWS NCOLS * 1- floats + b{{ NROWS 1- NCOLS 1- }} = -> true }t

\ Benchmarking matrix is 256x256
256 constant NROWS
NROWS constant NCOLS
NROWS NCOLS float matrix m{{

ms@ seed ! \ seed random number gen

: gen-random-float ( F: -- r)
random2p s>f
random2p 7 and negate s>f
falog f* ;

: fill-matrix ( -- )
NROWS 0 DO
NCOLS 0 DO
gen-random-float m{{ J I }} f!
LOOP
LOOP ;

\ Generate random row and column numbers
: random-row-col ( -- urow ucol )
random2p 255 and \ row
random2p 255 and \ col
;

: random-matrix-access ( -- )
0 ?DO m{{ random-row-col }} drop LOOP ;

cr
cr .( Filling 256x256 floating point matrix with random values ... )
fill-matrix
cr .( Benchmark: "ms@ 1000000 random-matrix-access ms@ swap - ." )

--- end of program --

--
Krishna Myneni

Re: locals

<ulo1bt$351qd$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25649&group=comp.lang.forth#25649

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dxforth@gmail.com (dxf)
Newsgroups: comp.lang.forth
Subject: Re: locals
Date: Mon, 18 Dec 2023 10:48:15 +1100
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <ulo1bt$351qd$1@dont-email.me>
References: <uldipg$12lpv$1@dont-email.me>
<2b60c95af1d221b694325f6acf7b45ab@news.novabbs.com>
<ulf8ai$1el02$1@dont-email.me> <ulfad7$1eto4$1@dont-email.me>
<4fedc3d9476633a3edb0300c21a4eb35@news.novabbs.com>
<60741e632ae54e48027caaaec2751b66@news.novabbs.com>
<a3af4cd21357d8a1ce502533d21c5545@news.novabbs.com>
<a9a8dae485cad3607fcfde86b93330eb@news.novabbs.com>
<uliunj$24g19$1@dont-email.me> <2023Dec16.084551@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 17 Dec 2023 23:48:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ec7170d1fb7f006ee0ba20f9834d63d0";
logging-data="3311437"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+WIjNXnx8SGBlkO/3dNogw"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:r6M5eK8e2cxGPCX8fjxKjgENvaM=
Content-Language: en-GB
In-Reply-To: <2023Dec16.084551@mips.complang.tuwien.ac.at>
 by: dxf - Sun, 17 Dec 2023 23:48 UTC

On 16/12/2023 6:45 pm, Anton Ertl wrote:
> ...
> And Chuck Moore and others who do not use locals do not practice what
> Jeff Fox preached. They just use VARIABLEs instead of locals.

Moore has said:

"Don't use local variables [...] It's bad. It's wrong."

<https://www.ultratechnology.com/1xforth.htm>

If he's merely using VARIABLEs where locals would otherwise be used that's
worth investigating. Unfortunately I'm not aware of any substantive code
by Moore in the public domain to test the proposition.

As one of the "others who do not use locals" I offer the following sample.
Readers may decide whether such use of VARIABLEs and VALUEs amounts to locals
in the usual meaning of the word. ISTM the more factored the code, the more
difficult it is to apply the term 'local'.

variable #DIGIT \ #digits entered

: /FIELD ( n -- 0 )
drop #digit @ begin dup while
<bs> emit space <bs> emit 1-
repeat decimal #digit off ;

: .VIS ( c -- )
dup visible? if emit 1 #digit +! end drop ;

: ?$ ( n c -- n' c' )
[char] $ of /field hex [char] $ .vis key then ;

: +DIGIT ( u c -- u' err )
base @ >digit if swap base @ * + dup 255 u> end
drop true ;

: BUILD# ( c -- n c2 ) \ CR or BL exits
decimal #digit off
0 swap begin dup bl <> over <cr> <> and while
?$ upcase dup .vis +digit if beep /field then key
repeat decimal ;

: GET# ( -- n ) key build# drop ;

variable LEN 0 value MAXCHR

: ROOM? ( -- f ) len @ maxchr < ;

: +CHR ( c -- ) ibuf len @ + c! 1 len +! ;

: DO-NUM ( c -- ) \ CR or BL BL exits
begin room? while
build# swap #digit @ if +chr else drop then
<cr> = if end space key bl of <cr> then
repeat drop ;

: DO-ASC ( c -- )
begin dup <cr> - room? and while
dup .chr +chr key
repeat drop ;

: DIGIT? ( c -- f )
dup [char] $ = swap [char] 0 [char] 9 between or ;

: GET$ ( maxlen -- adr len )
to maxchr len off
key dup digit? if do-num else do-asc then
ibuf len @ ;

Re: Inefficiency of FSL matrices

<uloenj$3b2tg$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25650&group=comp.lang.forth#25650

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Sun, 17 Dec 2023 21:36:18 -0600
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <uloenj$3b2tg$1@dont-email.me>
References: <uldipg$12lpv$1@dont-email.me> <ulhpd7$1uifl$1@dont-email.me>
<ulnnh1$343kn$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 18 Dec 2023 03:36:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c47178353e31953d0d0189bf59ee2982";
logging-data="3509168"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+lmg/5JyREeKRGqPhAFKvx"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:9QT+5fHRZTU7h6RjVh/gKMXtiZk=
Content-Language: en-US
In-Reply-To: <ulnnh1$343kn$1@dont-email.me>
 by: Krishna Myneni - Mon, 18 Dec 2023 03:36 UTC

On 12/17/23 15:00, Krishna Myneni wrote:
....
>
> : random-matrix-access ( -- )
>     0 ?DO  m{{ random-row-col }} drop LOOP ;
>
....
This doesn't measure what I thought it was measuring. The benchmarking
of RANDOM-MATRIX-ACCESS measures the efficiency of RANDOM-ROW-COL rather
than measuring the efficiency of "}}". Using fixed row and column
numbers as indices gives a more accurate benchmark of "}}" which
computes the address of the specified element.

-- KM

Re: Inefficiency of FSL matrices

<ulog1e$3bbc1$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25651&group=comp.lang.forth#25651

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Sun, 17 Dec 2023 21:58:37 -0600
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <ulog1e$3bbc1$1@dont-email.me>
References: <uldipg$12lpv$1@dont-email.me> <ulhpd7$1uifl$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Dec 2023 03:58:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c47178353e31953d0d0189bf59ee2982";
logging-data="3517825"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+aZ8ilsk9D+0Pygr4BB3lF"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:3sQl2ONWV/LkDhp5ozwdcKqI6r0=
Content-Language: en-US
In-Reply-To: <ulhpd7$1uifl$1@dont-email.me>
 by: Krishna Myneni - Mon, 18 Dec 2023 03:58 UTC

On 12/15/23 08:55, Krishna Myneni wrote:
> On 12/13/23 18:38, Krishna Myneni wrote:
> ...
>> The operators "}" and "}}" resolve the adress of the indexed element
>> of the specified array, and this is where the inefficiency lies. I've
>> been tempted to make "}" and "}}" machine code primitives for these
>> words to increase their speed in kForth. ...
>
> I think the best approach forward for me, in kForth, is to include
> efficient primitives in Forth system,
>
....
Experimenting with an assembly language implementation of "}}" I find
that the following code in kforth64's vm64.s gives me a factor of 2x
speedup over the Forth source code for double-precision fp matrices.
This factor of 2 increase should not depend on the size of the matrix
element e.g., it should hold even if each matrix element was a
quad-precision floating point number (16 bytes) or a larger data
structure -- I still have to test this speedup under such conditions.

--
KM

L_fsl_mat_addr:
LDSP
INC_DSP
mov (%rbx), %rcx # rcx = j (column index)
INC_DSP
STSP
mov (%rbx), %rdx # rdx = i (row index)
mov WSIZE(%rbx), %rax # adress of first element
sub $2*WSIZE, %rax # rax = a - 2 cells
mov %rax, %rdi
mov (%rax), %rax # rax = ncols
imulq %rdx # rax = i*ncols
add %rax, %rcx # rcx = i*ncols + j
mov %rdi, %rax
add $WSIZE, %rax
mov (%rax), %rax # rax = size
imulq %rcx # rax = size*(i*ncols + j)
add %rax, WSIZE(%rbx) # TOS = a + rax
INC2_DTSP
xor %rax, %rax
NEXT

vs

: }} ( addr i j -- addr[i][j] )
>R >R
DUP [ 2 CELLS ] LITERAL - 2@ \ &a[0][0] size m
R> * R> + * + ;

In the experimental kforth64, the code L_fsl_mat_addr maps to the
built-in word, "}}".

Re: Inefficiency of FSL matrices

<76dbb68b1eed8a9242ebab77e2f362d9@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25652&group=comp.lang.forth#25652

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!.POSTED!not-for-mail
From: minforth@gmx.net (minforth)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Mon, 18 Dec 2023 09:35:25 +0000
Organization: novaBBS
Message-ID: <76dbb68b1eed8a9242ebab77e2f362d9@news.novabbs.com>
References: <uldipg$12lpv$1@dont-email.me> <ulhpd7$1uifl$1@dont-email.me> <ulog1e$3bbc1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="303531"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on novalink.us
X-Rslight-Site: $2y$10$nGRMGMyYvCZpLLe22lr4m.92V5KNb6M7wGQcFa2be1X9YFXhSwKzq
X-Rslight-Posting-User: 0d6d33dbe0e2e1ff58b82acfc1a8a32ac3b1cb72
 by: minforth - Mon, 18 Dec 2023 09:35 UTC

Looks good for existing FSL code. it might even be faster if you
introduced type-specific and thus shorter address computations
like }}F }}SF }}I and }F }SF }I.

Re: Inefficiency of FSL matrices

<ulpg1t$3gktg$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25653&group=comp.lang.forth#25653

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Inefficiency of FSL matrices
Date: Mon, 18 Dec 2023 07:05:01 -0600
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <ulpg1t$3gktg$1@dont-email.me>
References: <uldipg$12lpv$1@dont-email.me> <ulhpd7$1uifl$1@dont-email.me>
<ulog1e$3bbc1$1@dont-email.me>
<76dbb68b1eed8a9242ebab77e2f362d9@news.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Dec 2023 13:05:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c47178353e31953d0d0189bf59ee2982";
logging-data="3691440"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183sdFyqM5Zs2fsXpiX20yg"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:tiuGS5PmgDwzHnGh1S4uOfJF8zg=
In-Reply-To: <76dbb68b1eed8a9242ebab77e2f362d9@news.novabbs.com>
Content-Language: en-US
 by: Krishna Myneni - Mon, 18 Dec 2023 13:05 UTC

On 12/18/23 03:35, minforth wrote:
> Looks good for existing FSL code. it might even be faster if you
> introduced type-specific and thus shorter address computations
> like }}F }}SF }}I and }F }SF }I.

Yes, I expect I might gain an additional 2x speedup for type-specific
versions. But, I want }} to do the size-specific compilation,
eventually. To do that properly, I want to go to a dual-xt system and
avoid explicit STATE-dependence (which has other benefits we've
discussed in the past). That's a bigger project for later.

--
Krishna

Re: locals

<nnd$2e73ad70$74f7fc12@874e9786c940dd7c>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25654&group=comp.lang.forth#25654

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
References: <uldipg$12lpv$1@dont-email.me> <uliunj$24g19$1@dont-email.me> <2023Dec16.084551@mips.complang.tuwien.ac.at> <ulo1bt$351qd$1@dont-email.me>
Subject: Re: locals
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$2e73ad70$74f7fc12@874e9786c940dd7c>
Organization: KPN B.V.
Date: Mon, 18 Dec 2023 14:07:02 +0100
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 102
Injection-Date: Mon, 18 Dec 2023 14:07:02 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 4375
 by: none - Mon, 18 Dec 2023 13:07 UTC

In article <ulo1bt$351qd$1@dont-email.me>, dxf <dxforth@gmail.com> wrote:
>On 16/12/2023 6:45 pm, Anton Ertl wrote:
>> ...
>> And Chuck Moore and others who do not use locals do not practice what
>> Jeff Fox preached. They just use VARIABLEs instead of locals.
>
>Moore has said:
>
>"Don't use local variables [...] It's bad. It's wrong."
>
><https://www.ultratechnology.com/1xforth.htm>
>
>If he's merely using VARIABLEs where locals would otherwise be used that's
>worth investigating. Unfortunately I'm not aware of any substantive code
>by Moore in the public domain to test the proposition.
>
>As one of the "others who do not use locals" I offer the following sample.
>Readers may decide whether such use of VARIABLEs and VALUEs amounts to locals
>in the usual meaning of the word. ISTM the more factored the code, the more
>difficult it is to apply the term 'local'.
>
>variable #DIGIT \ #digits entered
>
>: /FIELD ( n -- 0 )
> drop #digit @ begin dup while
> <bs> emit space <bs> emit 1-
> repeat decimal #digit off ;
>
>: .VIS ( c -- )
> dup visible? if emit 1 #digit +! end drop ;
>
>: ?$ ( n c -- n' c' )
> [char] $ of /field hex [char] $ .vis key then ;
>
>: +DIGIT ( u c -- u' err )
> base @ >digit if swap base @ * + dup 255 u> end
> drop true ;
>
>: BUILD# ( c -- n c2 ) \ CR or BL exits
> decimal #digit off
> 0 swap begin dup bl <> over <cr> <> and while
> ?$ upcase dup .vis +digit if beep /field then key
> repeat decimal ;
>
>: GET# ( -- n ) key build# drop ;
>
>variable LEN 0 value MAXCHR
>
>: ROOM? ( -- f ) len @ maxchr < ;
>
>: +CHR ( c -- ) ibuf len @ + c! 1 len +! ;
>
>: DO-NUM ( c -- ) \ CR or BL BL exits
> begin room? while
> build# swap #digit @ if +chr else drop then
> <cr> = if end space key bl of <cr> then
> repeat drop ;
>
>: DO-ASC ( c -- )
> begin dup <cr> - room? and while
> dup .chr +chr key
> repeat drop ;
>
>: DIGIT? ( c -- f )
> dup [char] $ = swap [char] 0 [char] 9 between or ;
>
>: GET$ ( maxlen -- adr len )
> to maxchr len off
> key dup digit? if do-num else do-asc then
> ibuf len @ ;
>

An excellent example.

Another excellent example is the <# # #> wordset.
They are superbly factored, by virtue of the "global"
HLD a (user) variable. It is actually more of a
"package-local" variable. Who are in the habit
of using LOCAL's as a first resort, are blocked to think
in this direction.
In the 2500 lines of the manx package (plays musical score
simultaneously on midi keyboard and mechanical instruments) you see
no LOCAL and merely half a dozen VARIABLE or VALUE.
Some of this are hard (or impossible) to replace by LOCAL,
e.g. SHIFTER and TICKS-PER-SECOND. They are set by
a calibration word in the initialisation, then are needed all
over the place, mostly by words that need not address them directly.
They convert the system dependant tick rate to real time.

Then you have the assembler/disassembler ciasdis.
This implements a "blackboard design pattern" for a
kind of state machine.
It is hard to imagine that some one scribbles something on a blackboard,
and then no one is ever to read it.

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Pages:123
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor