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


Groups > comp.lang.forth > #43085

Re: Questions about strings

Path csiph.com!news.swapon.de!aioe.org!.POSTED!not-for-mail
From "Rod Pemberton" <boo@fasdfrewar.cdm>
Newsgroups comp.lang.forth
Subject Re: Questions about strings
Date Mon, 02 Nov 2015 02:34:51 -0500
Organization Aioe.org NNTP Server
Lines 57
Message-ID <op.x7gp0ddsyfako5@localhost> (permalink)
References <a094319a-c257-452a-8009-e5d55ab1cdf6@googlegroups.com> <281b9816-848c-4abd-b62e-02cb7d0181a3@googlegroups.com>
NNTP-Posting-Host n4wpt9zq8xR26Ttf9mo2BA.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=iso-8859-1; format=flowed; delsp=yes
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Opera Mail/12.16 (Linux)
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.lang.forth:43085

Show key headers only | View raw


On Sat, 31 Oct 2015 13:48:36 -0400, Chris Curl <ccurl609@gmail.com> wrote:

> I have decided that in my own personal Forth, strings will be both
> counted and NULL terminated. The count is in the first BYTE and does
> NOT include the NULL terminator.
>
> So "ABC" would use 5 bytes and look like this:
>
> 3 65 66 67 0
>
> This makes it easy to work with the strings using either approach.
> And I find that some activities are more straightforward when
> stopping at NULL as opposed to keeping a count and stopping when
> that count exceeds the count byte.
>
> If it turns out that I have a need to deal with longer strings in
> the future, then I will cross that bridge when I get to it.

BTW, NULL is used by C for a pointer to non-C-object area,
but NUL is a character of all bits zero for ASCII and EBCDIC,
probably Unicode too.  Or, NUL is a C-sized byte of all bits
zero for C where C's byte may be larger than the character
size in bits.

Some issues you might run into is which one to use and
what to do if the length of the nul terminated string
exceeds the ability to store the length in the byte.

I implemented null terminated strings in my Forth, as have
some others here.  I've not noticed any serious issues yet.

IIRC, you only need to change one Forth word to work
slightly differently than intended by the specifications,
but isn't in violation of them.

I had planned to insert a byte for the count since null
terminated strings won't pass Hayes Core tests as they're
currently implemented, but I have yet to do so as it will
require reformatting my dictionary code.

Having programmed heavily in both C and PL/1 (a PL/I variant),
one which uses nul-terminated strings and the other counted
strings, I'm of the strong opinion that nul terminated strings
is the better solution.  However, saying so seems to consistently
incite some flames here.

As Ms. Rather noted, some of Forth's string words are
typically implemented as primitives, many of which almost
map directly onto various C string functions.

CMOVE strncpy()
ENCLOSE strchr() or strpbrk()
COMPARE strcmp()
COUNT strlen()


Rod Pemberton

Back to comp.lang.forth | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Questions about strings Chris Curl <ccurl609@gmail.com> - 2015-10-17 06:46 -0700
  Re: Questions about strings rickman <gnuarm@gmail.com> - 2015-10-17 11:25 -0400
    Re: Questions about strings Chris Curl <ccurl609@gmail.com> - 2015-10-17 10:43 -0700
      Re: Questions about strings anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-10-17 17:52 +0000
      Re: Questions about strings "Elizabeth D. Rather" <erather@forth.com> - 2015-10-17 07:56 -1000
      Re: Questions about strings rickman <gnuarm@gmail.com> - 2015-10-17 14:07 -0400
      Re: Questions about strings "HAA" <someone@microsoft.com> - 2015-10-18 12:50 +1000
  Re: Questions about strings Ron Aaron <rambamist@gmail.com> - 2015-10-17 19:30 +0300
  Re: Questions about strings anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-10-17 17:10 +0000
  Re: Questions about strings Jason Damisch <jasondamisch@yahoo.com> - 2015-10-17 10:41 -0700
    Re: Questions about strings foxaudioresearch@gmail.com - 2015-10-17 21:41 -0700
    Re: Questions about strings Johan Kotlinski <kotlinski@gmail.com> - 2015-10-18 15:40 -0700
      Re: Questions about strings "Elizabeth D. Rather" <erather@forth.com> - 2015-10-18 13:41 -1000
        Re: Questions about strings Johan Kotlinski <kotlinski@gmail.com> - 2015-10-19 07:58 -0700
          Re: Questions about strings "Elizabeth D. Rather" <erather@forth.com> - 2015-10-19 08:36 -1000
          Re: Questions about strings "HAA" <someone@microsoft.com> - 2015-10-23 00:08 +1000
      Re: Questions about strings anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-10-19 07:15 +0000
        Re: Questions about strings Chris Curl <ccurl609@gmail.com> - 2015-10-19 05:03 -0700
          Re: Questions about strings "Elizabeth D. Rather" <erather@forth.com> - 2015-10-19 08:38 -1000
            Re: Questions about strings Chris Curl <ccurl609@gmail.com> - 2015-10-19 14:28 -0700
            Re: Questions about strings Alfred Singlestone <vitonis@gmail.com> - 2015-10-21 16:21 -0700
              Re: Questions about strings "HAA" <someone@microsoft.com> - 2015-10-22 11:07 +1000
                Re: Questions about strings Lars Brinkhoff <lars.spam@nocrew.org> - 2015-10-27 11:29 +0100
                Re: Questions about strings Chris Curl <ccurl609@gmail.com> - 2015-10-27 06:14 -0700
                Re: Questions about strings Lars Brinkhoff <lars.spam@nocrew.org> - 2015-10-27 15:04 +0100
                Re: Questions about strings Chris Curl <ccurl609@gmail.com> - 2015-10-27 07:01 -0700
                Re: Questions about strings Lars Brinkhoff <lars.spam@nocrew.org> - 2015-10-27 15:04 +0100
                Re: Questions about strings Chris Curl <ccurl609@gmail.com> - 2015-10-27 14:26 -0700
                Re: Questions about strings "Elizabeth D. Rather" <erather@forth.com> - 2015-10-27 11:45 -1000
                Re: Questions about strings Lars Brinkhoff <lars.spam@nocrew.org> - 2015-10-28 07:43 +0100
        Re: Questions about strings "HAA" <someone@microsoft.com> - 2015-10-19 23:25 +1000
      Re: Questions about strings rickman <gnuarm@gmail.com> - 2015-10-20 14:47 -0400
        Re: Questions about strings "Elizabeth D. Rather" <erather@forth.com> - 2015-10-20 09:48 -1000
          Re: Questions about strings rickman <gnuarm@gmail.com> - 2015-10-20 23:25 -0400
            Re: Questions about strings "HAA" <someone@microsoft.com> - 2015-10-21 15:11 +1000
              Re: Questions about strings "HAA" <someone@microsoft.com> - 2015-10-22 11:21 +1000
                Re: Questions about strings "Elizabeth D. Rather" <erather@forth.com> - 2015-10-21 18:31 -1000
                Re: Questions about strings anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-10-22 05:51 +0000
                Re: Questions about strings "HAA" <someone@microsoft.com> - 2015-10-24 12:44 +1000
                Re: Questions about strings anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-10-25 10:17 +0000
                Re: Questions about strings "HAA" <someone@microsoft.com> - 2015-10-26 15:14 +1100
                Re: Questions about strings anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-10-26 11:20 +0000
                Re: Questions about strings "HAA" <someone@microsoft.com> - 2015-10-31 00:20 +1100
                Re: Questions about strings "Elizabeth D. Rather" <erather@forth.com> - 2015-10-30 19:06 -1000
                Re: Questions about strings Paul Rubin <no.email@nospam.invalid> - 2015-10-30 23:27 -0700
                Re: Questions about strings "Elizabeth D. Rather" <erather@forth.com> - 2015-10-30 21:28 -1000
                Re: Questions about strings Paul Rubin <no.email@nospam.invalid> - 2015-10-31 00:37 -0700
                Re: Questions about strings "Elizabeth D. Rather" <erather@forth.com> - 2015-10-30 21:48 -1000
          Re: Questions about strings anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-10-21 06:10 +0000
  Re: Questions about strings Chris Curl <ccurl609@gmail.com> - 2015-10-31 10:48 -0700
    Re: Questions about strings "Elizabeth D. Rather" <erather@forth.com> - 2015-10-31 09:57 -1000
      Re: Questions about strings Chris Curl <ccurl609@gmail.com> - 2015-10-31 13:34 -0700
        Re: Questions about strings "Elizabeth D. Rather" <erather@forth.com> - 2015-10-31 12:06 -1000
    Re: Questions about strings "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-11-02 02:34 -0500

csiph-web