Thread View: comp.lang.forth
6 messages
6 total messages
Started by albert
Mon, 30 Nov 2026 11:21
Braindamaged strings
Author: albert
Date: Mon, 30 Nov 2026 11:21
Date: Mon, 30 Nov 2026 11:21
22 lines
1519 bytes
1519 bytes
In this day and age it is time to terminate the use of characters to store a string count. With great pleasure I see that Gforth has adopted the use of a cell to store the count of a string, officially. $@ replaces COUNT. For places where COUNT is indeed use to fetch a string I propose to ALIAS COUNT as `` $@-BD '' . $! has no equivalent in brain damaged strings that is widely adopted. Certainly the pair $@ $! makes a lot of sense. Finally you could stop pondering of a PLACE-SOMESUCH words has anything to do with strings, and what the stack effect could be. "Happy Christmas" PAD $! PAD $@ TYPE Happy Christmas OK Groetjes Albert -- The Chinese government is satisfied with its military superiority over USA. The next 5 year plan has as primary goal to advance life expectancy over 80 years, like Western Europe.
$trings (was: Braindamaged strings)
Author: Anton Ertl
Date: Tue, 01 Dec 2026 08:09
Date: Tue, 01 Dec 2026 08:09
57 lines
3405 bytes
3405 bytes
albert@spenarnc.xs4all.nl writes:
>In this day and age it is time to terminate the use of characters
>to store a string count.
Forthunately, the designers of Forth-94 already recognized this over
three decades ago, and focussed on the c-addr u representation, with
only a few words existing for dealing with the counted-string legacy.
>With great pleasure I see that Gforth has adopted the use of a cell
>to store the count of a string, officially.
>$@ replaces COUNT.
Not really, as explained below.
>$! has no equivalent in brain damaged strings
Exactly.
The $tring implementation differs from COUNTed strings in more than
just the count size.
The single-cell $tring representation does not point to the count cell
(as it would, if $trings were just COUNTed strings with bigger
counts).
Instead, what you have on the stack is the address of a cell (e.g., it
may come from a variable). E.g., here's how you use it:
variable mystring \ 0 mystring ! \ automatic for variables in Gforth
s" bla" mystring $!
mystring $@ type
What's remarkable here is that you do not have to allocate space for
the string data explicitly, allocating a cell is enough. $! ALLOCATEs
space for the string data and its length, and stores the address of
that memory in the given cell.
When the cell is overwritten by another $-word, e.g., by another
$tring, the old string that the cell points to is freed. So it is
important to initialize these cells to 0 at the beginning, and then
only work on them with $-words. It's also important that any c-addr u
pairs derived from the cell have been consumed at that point (they
will become invalid once the string data has been freed).
When you keep this discipline, the reward is that the storage
allocation of strings becomes much easier: You only need to allocate a
cell for any string you want to manage, and do not have to worry about
the length of the string. You also do not need a string stack, the
data stack holds the addresses of the cells just fine (but OTOH, you
need to deal with those cells).
- 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
Re: Braindamaged strings
Author: dxf
Date: Tue, 01 Dec 2026 08:52
Date: Tue, 01 Dec 2026 08:52
20 lines
1521 bytes
1521 bytes
On 30/11/2026 10:21 pm, albert@spenarnc.xs4all.nl wrote: > In this day and age it is time to terminate the use of characters > to store a string count. > > With great pleasure I see that Gforth has adopted the use of a cell > to store the count of a string, officially. > $@ replaces COUNT. For places where COUNT is indeed use to fetch > a string I propose to ALIAS COUNT as `` $@-BD '' . > $! has no equivalent in brain damaged strings that is widely adopted. > Certainly the pair $@ $! makes a lot of sense. Finally you could stop > pondering of a PLACE-SOMESUCH words has anything to do with strings, and > what the stack effect could be. > > "Happy Christmas" PAD $! > PAD $@ TYPE > > Happy Christmas OK Someone should tell SwiftForth and VFX (2500+ instances of COUNT) :)
Re: $trings (was: Braindamaged strings)
Author: albert
Date: Tue, 01 Dec 2026 12:07
Date: Tue, 01 Dec 2026 12:07
133 lines
6073 bytes
6073 bytes
In article <2026Dec1.090920@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>albert@spenarnc.xs4all.nl writes:
>>In this day and age it is time to terminate the use of characters
>>to store a string count.
>
>Forthunately, the designers of Forth-94 already recognized this over
>three decades ago, and focussed on the c-addr u representation, with
>only a few words existing for dealing with the counted-string legacy.
>
>>With great pleasure I see that Gforth has adopted the use of a cell
>>to store the count of a string, officially.
>>$@ replaces COUNT.
>
>Not really, as explained below.
It think functionally it is.
>
>>$! has no equivalent in brain damaged strings
>
>Exactly.
>
>The $tring implementation differs from COUNTed strings in more than
>just the count size.
>
>The single-cell $tring representation does not point to the count cell
>(as it would, if $trings were just COUNTed strings with bigger
>counts).
>
>Instead, what you have on the stack is the address of a cell (e.g., it
>may come from a variable). E.g., here's how you use it:
>
>variable mystring \ 0 mystring ! \ automatic for variables in Gforth
>s" bla" mystring $!
>mystring $@ type
>
>What's remarkable here is that you do not have to allocate space for
>the string data explicitly, allocating a cell is enough. $! ALLOCATEs
>space for the string data and its length, and stores the address of
>that memory in the given cell.
>
>When the cell is overwritten by another $-word, e.g., by another
>$tring, the old string that the cell points to is freed. So it is
>important to initialize these cells to 0 at the beginning, and then
>only work on them with $-words. It's also important that any c-addr u
>pairs derived from the cell have been consumed at that point (they
>will become invalid once the string data has been freed).
>
That is an implementation issue!
>When you keep this discipline, the reward is that the storage
>allocation of strings becomes much easier: You only need to allocate a
>cell for any string you want to manage, and do not have to worry about
>the length of the string. You also do not need a string stack, the
>data stack holds the addresses of the cells just fine (but OTOH, you
>need to deal with those cells).
In advanced systems you reap this benefit.
It is strangely compatible with what I do with fig-Forth on CP/M
and till this day in ciforth.
The difference is that in my forths the address of a string is a buffer
that accommodates the largest string that you will put there.
So you can use $@ $! portable between gforth and ciforth, more or less.
This design doesn't require ALLOCATE. The disadvantage is that you have
to ALLOT space, but this isn't actually a great disadvantage as my 45
years practical experience for this setup shows.
$! and $@ can be defined such that the actually storage provided
is "system defined".
ciforth follows 1, gforth follows 2.
1 (addr len addr1 -- ) require a buffer at addr1 to accomodate a string of
len Obviously the prior content of the string as addr1 is lost.
2. (addr len addr -- ) require a variable at addr to accomodate a handle
and storage is allocated automatically for the string.
The previous content of the handle is lost, and the storage allocated is
freed.
Requiring ALLOCATE is a great burden on small systems.
I have redefined $! $@ on occasion to ALLOCATE the string.
The program will runs as before, but from then on you don't have
to worry of overwriting buffers.
An example of straight use of $! $@ .
This program converts a dump like
-D000 AF 66 23 89 89
to a bin and and a dump where also ascii is show.
Never mind the detail, the binary data is collected into `buf.
\ --------------------------------------------------------
WANT DUMP REALLOT
DATA buf
1,000,000 ALLOT \ Can be avoided
\ From string put all hex characters into `buf .
: to-buf BEGIN BL $/ EVALUATE buf $C+ DUP 0= UNTIL 2DROP ;
\ Get a line from file , drop first word, leave remainder of file.
: read-line ^J $/ BL $/ 2DROP to-buf ;
\ Convert file passed as argument1, dump it, and leave a binary in
\ a file as argument 2.
: doit 1 ARG[] GET-FILE HEX ONLY
\ 'buf OVER REALLOT \ *****************
0 buf !
BEGIN read-line DUP 0= UNTIL 2DROP
buf $@ DUMP
buf $@ 2 ARG[] PUT-FILE ;
\---------------------------------------------------
Used as: appledump apple.1 apple.bin
As shown the size of a turnkey is at least one megabyte caused by buf.
This is surely enough and serves for a throw away program.
But the buffer can be increased by REALLOT during runtime and the
allocating during compile time can be avoided.
The size needed is certainly not greater than the initial file:
`` OVER REALLOT '' works.
Now the program is 70 kbyte and no restrictions.
Note that it is a great hassle to have to accomodate ALLOCATE in
turnkey programs.
>
>- anton
Groetjes Albert
--
The Chinese government is satisfied with its military superiority over USA.
The next 5 year plan has as primary goal to advance life expectancy
over 80 years, like Western Europe.
Re: Braindamaged strings
Author: albert
Date: Tue, 01 Dec 2026 12:15
Date: Tue, 01 Dec 2026 12:15
39 lines
2215 bytes
2215 bytes
In article <6b0e8ac5$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote: >On 30/11/2026 10:21 pm, albert@spenarnc.xs4all.nl wrote: >> In this day and age it is time to terminate the use of characters >> to store a string count. >> >> With great pleasure I see that Gforth has adopted the use of a cell >> to store the count of a string, officially. >> $@ replaces COUNT. For places where COUNT is indeed use to fetch >> a string I propose to ALIAS COUNT as `` $@-BD '' . >> $! has no equivalent in brain damaged strings that is widely adopted. >> Certainly the pair $@ $! makes a lot of sense. Finally you could stop >> pondering of a PLACE-SOMESUCH words has anything to do with strings, and >> what the stack effect could be. >> >> "Happy Christmas" PAD $! >> PAD $@ TYPE >> >> Happy Christmas OK > >Someone should tell SwiftForth and VFX (2500+ instances of COUNT) :) Never mind the internal uses of COUNT. They can stay. In library code every time you use COUNT, you have placed somethin there with a non standard word. Replace these instances with $!-BD . This is a great improvement. One you're done replace COUNT by $@ and $!-BD by $!. Now you're not bitten with url's that run more than 256 bytes. Groetjes Albert. > -- The Chinese government is satisfied with its military superiority over USA. The next 5 year plan has as primary goal to advance life expectancy over 80 years, like Western Europe.
Re: Braindamaged strings
Author: dxf
Date: Wed, 02 Dec 2026 02:39
Date: Wed, 02 Dec 2026 02:39
38 lines
2589 bytes
2589 bytes
On 1/12/2026 11:15 pm, albert@spenarnc.xs4all.nl wrote: > In article <6b0e8ac5$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote: >> On 30/11/2026 10:21 pm, albert@spenarnc.xs4all.nl wrote: >>> In this day and age it is time to terminate the use of characters >>> to store a string count. >>> >>> With great pleasure I see that Gforth has adopted the use of a cell >>> to store the count of a string, officially. >>> $@ replaces COUNT. For places where COUNT is indeed use to fetch >>> a string I propose to ALIAS COUNT as `` $@-BD '' . >>> $! has no equivalent in brain damaged strings that is widely adopted. >>> Certainly the pair $@ $! makes a lot of sense. Finally you could stop >>> pondering of a PLACE-SOMESUCH words has anything to do with strings, and >>> what the stack effect could be. >>> >>> "Happy Christmas" PAD $! >>> PAD $@ TYPE >>> >>> Happy Christmas OK >> >> Someone should tell SwiftForth and VFX (2500+ instances of COUNT) :) > > Never mind the internal uses of COUNT. They can stay. > > In library code every time you use COUNT, you have placed somethin there > with a non standard word. Replace these instances with $!-BD . > This is a great improvement. > One you're done replace COUNT by $@ and $!-BD by $!. > > Now you're not bitten with url's that run more than 256 bytes. Who has been bitten - particularly in forth which encourages programmers to be mindful in all they do? You mentioned Gforth. Gforth has described itself as an 'educational forth'. It certainly seems aimed at beginners as it has 'features' that drove me crazy. If that audience gets bitten, I say well and good. If they're anything like what forth needs, they'll blame themselves and not the language.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads