🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.forth
Article #277

Re: $trings (was: Braindamaged strings)

#277
From: albert
Date: Wed, 02 Dec 2026 14:19
68 lines
3511 bytes
In article <nnd$4e0788dc$2509a962@4cdc5d002eb391eb>,
 <albert@spenarnc.xs4all.nl> wrote:
 <SNIP>
>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
> CREATE buf
>  1,000,000 ALLOT
>\ 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
>    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.

Anton has responded to this example that you can easily do that
handling single characters. The point is actually that the low level
abstraction $@ $! $/ $\ $^ $C+ makes handling string so much easier.
Especially $/ :
$/ (stringconstant c -- stringconstant1 strinconstant2 )
Find the first c in the string constant sc and split it at that
address. Return the strings after and before c into sc1 and sc2
respectively. If the character is not present sc1 is a null string
(its address is zero) and sc2 is the original string. Both sc1 and sc2
may be empty strings (i.e. their count is zero), if c is the last or
first character in sc .

The argument that is "easily" done, it is not. That is the point of
low level abstractions, to make life easier.
So I put it as a challenge.

As stringconstant is a (addr,len) pair. not that a null string and an
empty string are different.

>>- 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.
-- 
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.
Technical Details
Message-ID: <nnd$4af18030$768ad6ee@19e8590063cdfc1f>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!abo004.abavia.com!feed.abavia.com!abr004.abavia.com!abp002.abavia.com!reseller!not-for-mail
References: <nnd$2790af4d$71f56696@06eb3ea8c34cc53c> <2026Dec1.090920@mips.complang.tuwien.ac.at> <nnd$4e0788dc$2509a962@4cdc5d002eb391eb>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.forth
References: <nnd$2790af4d$71f56696@06eb3ea8c34cc53c> <2026Dec1.090920@mips.complang.tuwien.ac.at> <nnd$4e0788dc$2509a962@4cdc5d002eb391eb>
From: albert@spenarnc.xs4all.nl
Subject: Re: $trings (was: Braindamaged strings)
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$4af18030$768ad6ee@19e8590063cdfc1f>
Organization: www.abavia.com
Date: Wed, 02 Dec 2026 15:19:07 +0100
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!abo004.abavia.com!feed.abavia.com!abr004.abavia.com!abp002.abavia.com!reseller!not-for-mail
Lines: 69
Injection-Date: Wed, 02 Dec 2026 15:19:07 +0100
Injection-Info: reseller; mail-complaints-to="abuse@abavia.com"