Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #42677 > unrolled thread
| Started by | Chris Curl <ccurl609@gmail.com> |
|---|---|
| First post | 2015-10-17 06:46 -0700 |
| Last post | 2015-11-02 02:34 -0500 |
| Articles | 20 on this page of 54 — 13 participants |
Back to article view | Back to comp.lang.forth
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
Page 1 of 3 [1] 2 3 Next page →
| From | Chris Curl <ccurl609@gmail.com> |
|---|---|
| Date | 2015-10-17 06:46 -0700 |
| Subject | Questions about strings |
| Message-ID | <a094319a-c257-452a-8009-e5d55ab1cdf6@googlegroups.com> |
Assuming that the count is at the beginning of a string, is the count the same size as the characters in the string? And are the characters "wide" (16 bits), or are they 8-bit entities? In other words, to get the length of a string, would I use C@ or @? I know I could use COUNT NIP, but I want to understand what is going on behind the scenes so that my implementation behaves like others would. Perhaps I should go rogue and implement them as standard BSTRs ... http://bytecomb.com/vba-internals-string-variables-and-pointers-in-depth/
[toc] | [next] | [standalone]
| From | rickman <gnuarm@gmail.com> |
|---|---|
| Date | 2015-10-17 11:25 -0400 |
| Message-ID | <mvtp55$o2q$1@dont-email.me> |
| In reply to | #42677 |
On 10/17/2015 9:46 AM, Chris Curl wrote: > Assuming that the count is at the beginning of a string, is the count the same size as the characters in the string? > > And are the characters "wide" (16 bits), or are they 8-bit entities? > > In other words, to get the length of a string, would I use C@ or @? > > I know I could use COUNT NIP, but I want to understand what is going on behind the scenes so that my implementation behaves like others would. > > Perhaps I should go rogue and implement them as standard BSTRs ... > > http://bytecomb.com/vba-internals-string-variables-and-pointers-in-depth/ Do you read the ANS Forth spec? "3.1.3.4 Counted strings A counted string in memory is identified by the address (c-addr) of its length character. The length character of a counted string shall contain a binary representation of the number of data characters, between zero and the implementation-defined maximum length for a counted string. The maximum length of a counted string shall be at least 255." Does that answer your question? -- Rick
[toc] | [prev] | [next] | [standalone]
| From | Chris Curl <ccurl609@gmail.com> |
|---|---|
| Date | 2015-10-17 10:43 -0700 |
| Message-ID | <b80998ae-fed3-4d58-8de1-ab4627b8eed3@googlegroups.com> |
| In reply to | #42678 |
On Saturday, October 17, 2015 at 11:25:26 AM UTC-4, rickman wrote: > On 10/17/2015 9:46 AM, Chris Curl wrote: > > Assuming that the count is at the beginning of a string, is the count the same size as the characters in the string? > > > > And are the characters "wide" (16 bits), or are they 8-bit entities? > > > > In other words, to get the length of a string, would I use C@ or @? > > > > I know I could use COUNT NIP, but I want to understand what is going on behind the scenes so that my implementation behaves like others would. > > > > Perhaps I should go rogue and implement them as standard BSTRs ... > > > > http://bytecomb.com/vba-internals-string-variables-and-pointers-in-depth/ > > Do you read the ANS Forth spec? > > "3.1.3.4 Counted strings > A counted string in memory is identified by the address (c-addr) of its > length character. The length character of a counted string shall > contain a binary representation of the number of data characters, > between zero and the implementation-defined maximum length for a counted > string. The maximum length of a counted string shall be at least 255." > > Does that answer your question? > > -- > > Rick yes, thanks. is there a downloadable version of the spec somewhere? then it would be easier looking for stuff in it.
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2015-10-17 17:52 +0000 |
| Message-ID | <2015Oct17.195207@mips.complang.tuwien.ac.at> |
| In reply to | #42684 |
Chris Curl <ccurl609@gmail.com> writes:
>yes, thanks. is there a downloadable version of the spec somewhere?
http://www.forth200x.org/documents/forth-2012.pdf
For easy online lookup, you can go for
http://forth-standard.org/standard/words
- 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: http://www.forth200x.org/forth200x.html
EuroForth 2015: http://www.rigwit.co.uk/EuroForth2015/
[toc] | [prev] | [next] | [standalone]
| From | "Elizabeth D. Rather" <erather@forth.com> |
|---|---|
| Date | 2015-10-17 07:56 -1000 |
| Message-ID | <J6udnSmzC4JDFr_LnZ2dnUU7-IudnZ2d@supernews.com> |
| In reply to | #42684 |
On 10/17/15 7:43 AM, Chris Curl wrote: > On Saturday, October 17, 2015 at 11:25:26 AM UTC-4, rickman wrote: >> On 10/17/2015 9:46 AM, Chris Curl wrote: >>> Assuming that the count is at the beginning of a string, is the count the same size as the characters in the string? >>> >>> And are the characters "wide" (16 bits), or are they 8-bit entities? >>> >>> In other words, to get the length of a string, would I use C@ or @? >>> >>> I know I could use COUNT NIP, but I want to understand what is going on behind the scenes so that my implementation behaves like others would. >>> >>> Perhaps I should go rogue and implement them as standard BSTRs ... >>> >>> http://bytecomb.com/vba-internals-string-variables-and-pointers-in-depth/ >> >> Do you read the ANS Forth spec? >> >> "3.1.3.4 Counted strings >> A counted string in memory is identified by the address (c-addr) of its >> length character. The length character of a counted string shall >> contain a binary representation of the number of data characters, >> between zero and the implementation-defined maximum length for a counted >> string. The maximum length of a counted string shall be at least 255." >> >> Does that answer your question? >> >> -- >> >> Rick > > yes, thanks. is there a downloadable version of the spec somewhere? then it would be easier looking for stuff in it. > A link to the Forth2012 Release Candidate and other useful Forth links may be found http://www.forth.com/resources/ as well as other places. Cheers, Elizabeth -- ================================================== Elizabeth D. Rather (US & Canada) 800-55-FORTH FORTH Inc. +1 310.999.6784 5959 West Century Blvd. Suite 700 Los Angeles, CA 90045 http://www.forth.com "Forth-based products and Services for real-time applications since 1973." ==================================================
[toc] | [prev] | [next] | [standalone]
| From | rickman <gnuarm@gmail.com> |
|---|---|
| Date | 2015-10-17 14:07 -0400 |
| Message-ID | <mvu2kl$sdr$1@dont-email.me> |
| In reply to | #42684 |
On 10/17/2015 1:43 PM, Chris Curl wrote: > On Saturday, October 17, 2015 at 11:25:26 AM UTC-4, rickman wrote: >> On 10/17/2015 9:46 AM, Chris Curl wrote: >>> Assuming that the count is at the beginning of a string, is the count the same size as the characters in the string? >>> >>> And are the characters "wide" (16 bits), or are they 8-bit entities? >>> >>> In other words, to get the length of a string, would I use C@ or @? >>> >>> I know I could use COUNT NIP, but I want to understand what is going on behind the scenes so that my implementation behaves like others would. >>> >>> Perhaps I should go rogue and implement them as standard BSTRs ... >>> >>> http://bytecomb.com/vba-internals-string-variables-and-pointers-in-depth/ >> >> Do you read the ANS Forth spec? >> >> "3.1.3.4 Counted strings >> A counted string in memory is identified by the address (c-addr) of its >> length character. The length character of a counted string shall >> contain a binary representation of the number of data characters, >> between zero and the implementation-defined maximum length for a counted >> string. The maximum length of a counted string shall be at least 255." >> >> Does that answer your question? >> >> -- >> >> Rick > > yes, thanks. is there a downloadable version of the spec somewhere? then it would be easier looking for stuff in it. Unlike many specs (VHDL is nearly impossible to read) the Forth spec is not too bad. The level 1 stuff is pretty clear most of the time. The deeper stuff is harder to pull out, but that may be simply because it is harder to understand by definition. I know I never fully follow many conversations here about things like what a system should do with ' if . But it has lots of useful info in the appendix. Just adopt a positive attitude and look for the info. It is usually there. -- Rick
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2015-10-18 12:50 +1000 |
| Message-ID | <mvutua$vn9$1@speranza.aioe.org> |
| In reply to | #42684 |
Chris Curl wrote: > > is there a downloadable version of the spec somewhere? then it would be > easier looking for stuff in it. For ANS-Forth (aka Forth-94) there's a html version I like using: ftp://ftp.taygeta.com/pub/Forth/Literature/dpans6v3_3.zip Brad Eckert wrote a handy 'word index' for it: ftp://ftp.lab.unb.br/pub/hardware/opencores/cd16/Doc/AnsDraft/quick.htm
[toc] | [prev] | [next] | [standalone]
| From | Ron Aaron <rambamist@gmail.com> |
|---|---|
| Date | 2015-10-17 19:30 +0300 |
| Message-ID | <mvtsvg$6r3$1@dont-email.me> |
| In reply to | #42677 |
On 10/17/15 16:46, Chris Curl wrote: > Assuming that the count is at the beginning of a string, is the count the same size as the characters in the string? > > And are the characters "wide" (16 bits), or are they 8-bit entities? > > In other words, to get the length of a string, would I use C@ or @? I'll just interject with an 8th answer. In 8th, a string contains its length (but not in the same byte buffer as the text), and all strings are UTF-8. That means that the character length of a string and its byte-count are not necessarily the same. Therefore there are two words: "s:len", which gives the number of *characters*, and "s:size" which gives the number of *bytes*
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2015-10-17 17:10 +0000 |
| Message-ID | <2015Oct17.191057@mips.complang.tuwien.ac.at> |
| In reply to | #42677 |
Chris Curl <ccurl609@gmail.com> writes:
>Assuming that the count is at the beginning of a string, is the count the same size as the characters in the string?
If you use a COUNTed string, the count is a character. Most words
dealing with strings take and produce strings represented as c-addr u,
where u specifies the length in characters, and c-addr points to the
first character.
>And are the characters "wide" (16 bits), or are they 8-bit entities?
In practice, 8-bit entities on byte-addressed machines.
>In other words, to get the length of a string, would I use C@ or @?
Most of the time, you would use NIP.
- 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: http://www.forth200x.org/forth200x.html
EuroForth 2015: http://www.rigwit.co.uk/EuroForth2015/
[toc] | [prev] | [next] | [standalone]
| From | Jason Damisch <jasondamisch@yahoo.com> |
|---|---|
| Date | 2015-10-17 10:41 -0700 |
| Message-ID | <61e17390-0d18-4555-976b-f4346ae6599b@googlegroups.com> |
| In reply to | #42677 |
On Saturday, October 17, 2015 at 6:47:05 AM UTC-7, Chris Curl wrote: > Assuming that the count is at the beginning of a string, > is the count the same size as the characters in the string? You have a command line at your disposal, I suggest that you poke around with it. Its ok to fail at first to later succeed. Don't be afraid of making mistakes. But, I'll answer. In regular Forth the strings have a byte count and that first byte can be reached with C@. The strings can therefore not be longer than 255 characters long. The regular Forth strings just use ASCII. Try using C@ and EMIT to play around with some Forth strings. Also S" Jason
[toc] | [prev] | [next] | [standalone]
| From | foxaudioresearch@gmail.com |
|---|---|
| Date | 2015-10-17 21:41 -0700 |
| Message-ID | <46e6915b-aecb-4f6c-99ef-d4769c8748ba@googlegroups.com> |
| In reply to | #42683 |
On Saturday, October 17, 2015 at 1:41:43 PM UTC-4, Jason Damisch wrote:
> On Saturday, October 17, 2015 at 6:47:05 AM UTC-7, Chris Curl wrote:
> > Assuming that the count is at the beginning of a string,
> > is the count the same size as the characters in the string?
>
> You have a command line at your disposal, I suggest that you poke
> around with it. Its ok to fail at first to later succeed. Don't
> be afraid of making mistakes.
>
> But, I'll answer. In regular Forth the strings have a byte count
> and that first byte can be reached with C@. The strings can
> therefore not be longer than 255 characters long. The regular
> Forth strings just use ASCII. Try using C@ and EMIT to play
> around with some Forth strings. Also S"
>
> Jason
I am all for that approach as well. Explore.
To show a very old example of what could be done, with counted strings,
this is very old code that I ported to Gforth6 a decade ago for my own
amusement.
Play with it but build something much better please.
\ STRINGS.FS provides re-entrant string functions for GForth6 BFox
\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ Change History
\ Original TIForth: Brian Fox London Ontario Canada 08Oct87
\ Ported to HSForth 14Sep88
\ Ported to Win32Forth & sped up string stack 09Oct04
\ Test under VFX to compare speed 30Oct04
\ Ported to Gforth v6 15Feb05
\
\ Explanation
\ This file extends Forth to create counted strings. The original
\ objective was to demostrate string handling in Forth could be as easy as BASIC
\ I believe the objective was met.
\
\ The principal is simple. All string functions that potentially alter a string
\ move their output to a string stack and return the address of that new string.
\ The String stack is created in temporary space above PAD in a location called
\ TOP$. By creating intermediate output strings each function can be
\ "strung together" until the final result is obtained. The final result can be
\ stored back to another string or printed. Printing or storing a string
\ collapses the string stack automatically.
\ General Naming Convention: (some exceptions)
\ 1. WORDs that end in '$' leave results on stack in TOP$
\ 2. WORDs that start with $ expect a string argument on the stack
\
\ Features Include:
\ Compile time size checking. ( for novice users, can be commented out )
\ MaxLen byte compiled each into string for run time overflow checks.
\ String stack of fixed width for speed
\ TOP$ is the top of a stack of "PADs" for multiple string operations
\ Normal "BASIC" functions are re-entrant (LEFT$ RIGHT$ MID$)
\ $. and $! collapse the string stack on completion.
\ +$ allows multiple concatenation with run time size checking
\ :=" for easy assignment of string literals at compile time
\ :="" for string clear routine.
\ $POS finds position of a character within a string.
\ MAXLEN returns the maximum capacity of the string
\ $.R prints flush right text with leading blanks
\ $.LEFT prints flush left text with trailing blanks
\ -trailing$ reomves trailing spaces
\ -leading$ removes leading spaces
\ push$ pushes a string onto the stack (allocates space first)
\ -----------------------------------------------------------------------------
\ string stack lexicon
HEX
pad value top$ \ contains address of top of string stack
100 constant ss-width \ string stack width
ss-width 1- constant max$len \ biggest string we handle
: +ssp \ incr. string stack pointer
top$ ss-width + to top$ ;
: clrssp
pad to top$ ; \ reset top of string stack to pad
: ($!) ( $addr1 $addr2 -- ) \ no size checking!! be careful
>r dup c@ 1+ r> swap cmove ;
: $clip ( $addr n -- $addr n )
max over c@ min ;
: ?stringsize ( n -- )
max$len > abort" string too big" ;
: new.top$ ( -- top$ ) \ create a new string on the string stack of maximum length
+ssp \ create the space
top$
0FF over 1- ! ; \ set length to 0, maxlen to 255
: >top$ ( str -- ) new.top$ ($!) ; \ push str onto string stack
\ primitives ( some of these come from concepts in PYTHON)
\ return the address of of the nth char in a string
: ]$ ( adr$ n -- adr$[n] ) 1+ + ; \ usage: A$ 5 ]$ C@ returns 5th char
: chr$ ( ascii# -- top$ ) \ convert ascii char to $
new.top$ 0 ]$ c! \ store the ascii# at NEW top$[0]
1 top$ c! \ set the char count to 1
top$ ;
: push$ ( str -- top$) \ push str onto the string stack
>top$ top$ ; \ found this phrase was used a lot.
decimal
\ string variable size byte for error checking
\ this version also uses compile time size checking with an abort.
: $variable ( #bytes -- )
create dup ?stringsize \ remove if you don't like compile time check
dup c, 0 c, allot
does> 1+ ;
\ string primitive operations
: len ( adr$ - n ) c@ ;
: maxlen ( str -- maximum length ) 1- len ;
: pack$ ( adr cnt -- $ ) over 1- c! 1- ;
: !len ( n adr -- adr ) swap over c! ;
\ String constant control characters
HEX
1 $variable cr$ 0d01 cr$ !
1 $variable eof$ 1a01 eof$ !
1 $variable "$ 2201 "$ !
1 $variable bl$ 2001 bl$ !
1 $variable tab$ 0901 tab$ !
1 $variable null$ 0 null$ !
DECIMAL
: chr$ ( ascii# -- str ) 256 * 1+ top$ ! top$ ;
: asc ( adr$ -- ascii# ) 1+ c@ ;
\ $TEXT is like text but much handier since you can get multiple
\ inputs that simple stack up automatically. ( BL $TEXT BL $TEXT etc...)
: $TEXT ( delimit-char -- ) WORD push$ ;
\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ STRING I/O WORDS:
\ $! $. I refer to as string I/O words. This type of word
\ must clear the string stack when complete. Since these operators always
\ DO something with end product string this does not pose much restriction
\ to the FORTH programmer and abstracts the details allowing the Forth
\ programmer to write complex phrases of string language with less concern
\ about the mechanism at work.
: $! ( $adr1 $adr2 -- ) ($!) clrssp ;
\ useful if you need error checking
: $move ( $adr1 , $adr2 -- )
2dup maxlen swap len < abort" string to big"
$! ;
: $. ( $adr -- ) count type clrssp ; \ $. clears string stack after printing.
: $.left ( $adr,n -- ) \ prints str, n chars wide
over $. \ print the string
swap c@ - 0 max spaces ; \ print len(str)-n spaces
: $.r ( $adr,n -- ) over len - 0 max spaces $. ; \ print right justified
: .top$ ( $adr -- ) top$ count type ; \ view top$ but do not collapse the string stack
\ these are syntax candy
: :=" ( $addr -- <text> ) [char] " word swap $! ; \ usage: name :=" Brian Fox"
: :="" ( $addr -- ) dup maxlen 0 fill ; \ usage: name :=""
: $xchg ( $adr1,$adr2 -- ) \ does run time size checking
dup >top$
over swap ($!) ( don't collapse the stack. we still need it)
top$ swap $move ;
: +$ ( $adr1,$adr2 -- top$ )
2dup swap ( $adr1) >top$
( $adr2) count top$ count + swap cmove
len swap len + dup ?stringsize
top$ !len ;
: left$ ( adr$ #char -- top$ )
swap >top$ top$ !len ;
: right$ ( adr$ #char -- top$ )
+ssp
0 $clip >r count r@ - + r@ top$ c!
top$ 1+ r> cmove top$ ;
: mid$ ( adr$ start #char -- top$ )
+ssp
0 max >r 1 $clip
2dup swap c@ - negate 1+ r> min
top$ c! + top$ 1+ top$ c@ cmove top$ ;
: str$ ( n -- top$ )
+ssp 0 <# #s #> dup top$ c!
top$ 1+ swap cmove top$ ;
: $val ( adr$ - n ) \ can't accept commas or periods
number? 0=
if
abort" val cannot convert the string to a number"
then
drop drop ;
: -trailing$ ( $ -- $ ) \ removes trailing blanks, results in Top$
push$ count -trailing ( adr cnt ) pack$ ;
: -LEADING ( adr cnt -- adr cnt ) \ dank je wel Albert Van der Horst
BEGIN
over c@ bl = over 0= 0= and
WHILE
1- SWAP 1+ SWAP
REPEAT ;
: -leading$ ( $ -- $ ) push$ count -leading ( adr cnt ) pack$ ;
: clean$ ( $ -- $ ) -leading$ -trailing$ ;
: $compare ( adr$1 adr$2 -- -n:0:n ) count rot count compare ;
: $< ( adr$1 adr$2 -- ? ) $compare 1 = ;
: $> ( adr$1 adr$2 -- ? ) $compare -1 = ;
: $= ( adr$1 adr$2 -- ? ) $compare 0= ;
: $pos ( addr$ char -- position ) \ returns 0 if not found
over >r
>r dup count
r> scan drop swap -
r> c@
over <=
if drop 0 then ;
true [if]
decimal
\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ String test suite
\ test strings
255 $variable q q :=" 12345678901234567890123456789012345678901234567890 "
255 $variable w w :=" ABCDEFGHIJKLMNOPQRSTUVWXY:abcdefghijklmnopqrstuvwxy "
100 $variable x x :=" string X" ( smaller to check for errors)
255 $variable y y :=" string Y"
32 $variable anumber$
200 $variable cut$
: stringmuncher
clrssp
w clean$ q clean$ +$ y $!
y 100 left$ 60 right$ 2 50 mid$ x $!
9999 str$ anumber$ $!
\ Delimit the string w at the ":" position
w clean$ dup [char] : $POS left$ cut$ $! ( "abcdefghijklmnopqrstuvwxy:")
;
: $DEMO
page
cr ." Testing 1,000,000 iterations of Stringmuncher ..."
cr ." Input strings"
cr ." Q = " q $.
cr ." W = " w $.
cr ." X = " x $.
cr ." Y = " y $.
cr
100 0 do [char] . emit
10000 0 do
stringmuncher
loop
loop
cr
cr ." Results:"
cr ." X = " x $.
cr ." Y = " y $.
cr ." anumber$=" anumber$ $.
cr ." CUT$ = " cut$ $.
cr ." *COMPLETE*" ;
[then]
[toc] | [prev] | [next] | [standalone]
| From | Johan Kotlinski <kotlinski@gmail.com> |
|---|---|
| Date | 2015-10-18 15:40 -0700 |
| Message-ID | <92b1ba9c-88b2-436d-ba26-1eebd008e8f3@googlegroups.com> |
| In reply to | #42683 |
On Saturday, October 17, 2015 at 7:41:43 PM UTC+2, Jason Damisch wrote: > But, I'll answer. In regular Forth the strings have a byte count > and that first byte can be reached with C@. The strings can > therefore not be longer than 255 characters long. Hi! It happened to me that I hit the limit, that s" was given too many characters. Does anyone have nice tricks or workarounds for that problem? What I want in the end is c-addr u representation, so the exact intermediate storage form is not important. Cheers Johan
[toc] | [prev] | [next] | [standalone]
| From | "Elizabeth D. Rather" <erather@forth.com> |
|---|---|
| Date | 2015-10-18 13:41 -1000 |
| Message-ID | <Bu2dnRrdeJyJs7nLnZ2dnUU7-amdnZ2d@supernews.com> |
| In reply to | #42697 |
On 10/18/15 12:40 PM, Johan Kotlinski wrote: > On Saturday, October 17, 2015 at 7:41:43 PM UTC+2, Jason Damisch wrote: >> But, I'll answer. In regular Forth the strings have a byte count >> and that first byte can be reached with C@. The strings can >> therefore not be longer than 255 characters long. > > Hi! > It happened to me that I hit the limit, that s" was given too many characters. Does anyone have nice tricks or workarounds for that problem? > > What I want in the end is c-addr u representation, so the exact intermediate storage form is not important. Whether you need long strings depends entirely on the application. A simple approach would be to simply modify your programs to use a cell instead of a byte for the count, and use @ instead of C@ to get it. You can keep the standard counted strings for standard words that depend on them such as ." and use other strategies for your long strings. Words that take c-addr u arguments (MOVE, ERASE, etc.) will work fine with both, the only difference being how you fetch and store the lengths. That is why the arguments are specified as c-addr u instead of c-addr c. Cheers, Elizabeth -- ================================================== Elizabeth D. Rather (US & Canada) 800-55-FORTH FORTH Inc. +1 310.999.6784 5959 West Century Blvd. Suite 700 Los Angeles, CA 90045 http://www.forth.com "Forth-based products and Services for real-time applications since 1973." ==================================================
[toc] | [prev] | [next] | [standalone]
| From | Johan Kotlinski <kotlinski@gmail.com> |
|---|---|
| Date | 2015-10-19 07:58 -0700 |
| Message-ID | <f7a61f96-0813-47e6-a075-4161bcb1b3fe@googlegroups.com> |
| In reply to | #42698 |
On Monday, October 19, 2015 at 1:41:10 AM UTC+2, Elizabeth D. Rather wrote: > Whether you need long strings depends entirely on the application. A > simple approach would be to simply modify your programs to use a cell > instead of a byte for the count, and use @ instead of C@ to get it. Hi Elizabeth! Thanks for your answer. What made me wonder is the "simply". To me it doesn't seem simple to write a new s", actually it feels a bit complicated. Is there maybe some good trick I don't know about that would make it simple? All the best, Johan
[toc] | [prev] | [next] | [standalone]
| From | "Elizabeth D. Rather" <erather@forth.com> |
|---|---|
| Date | 2015-10-19 08:36 -1000 |
| Message-ID | <bIKdncbqItHWpbjLnZ2dnUU7-cmdnZ2d@supernews.com> |
| In reply to | #42705 |
On 10/19/15 4:58 AM, Johan Kotlinski wrote:
> On Monday, October 19, 2015 at 1:41:10 AM UTC+2, Elizabeth D. Rather wrote:
>> Whether you need long strings depends entirely on the application. A
>> simple approach would be to simply modify your programs to use a cell
>> instead of a byte for the count, and use @ instead of C@ to get it.
>
>
> Hi Elizabeth!
> Thanks for your answer.
>
> What made me wonder is the "simply". To me it doesn't seem simple to write a new s", actually it feels a bit complicated. Is there maybe some good trick I don't know about that would make it simple?
These are all very short, simple definitions. Look at the current
definitions of ." S" and similar. They may involve some
implementation-dependent words (that know how your dictionary and data
space is managed). Some examples:
: STRING ( char -- ) PARSE STRING, ;
: SLITERAL ( c-addr1 u -- ) ( -- c-addr1 u )
POSTPONE (S") STRING, ; IMMEDIATE
: ," ( -- ) [CHAR] " STRING ;
: S" ( "ccc"<"> -- )
STATE @ IF POSTPONE (S") ," EXIT THEN
[CHAR] " PARSE >QPAD COUNT ; IMMEDIATE
In the above definitions, STRING, compiles a string into data space, and
>QPAD is a buffer. Those are the only system-dependent words, and are
themselves pretty simple.
I'm not convinced, however, that S" and ," are the best way to handle
really long strings. I would consider different data structures whose
design would depend on how the strings are being acquired and what needs
to be done with them.
Cheers,
Elizabeth
--
==================================================
Elizabeth D. Rather (US & Canada) 800-55-FORTH
FORTH Inc. +1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com
"Forth-based products and Services for real-time
applications since 1973."
==================================================
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2015-10-23 00:08 +1000 |
| Message-ID | <n0an5n$akv$1@speranza.aioe.org> |
| In reply to | #42705 |
Johan Kotlinski wrote: > On Monday, October 19, 2015 at 1:41:10 AM UTC+2, Elizabeth D. Rather wrote: > > Whether you need long strings depends entirely on the application. A > > simple approach would be to simply modify your programs to use a cell > > instead of a byte for the count, and use @ instead of C@ to get it. > > > Hi Elizabeth! > Thanks for your answer. > > What made me wonder is the "simply". To me it doesn't seem simple to write a new s", > actually it feels a bit complicated. Is there maybe some good trick I don't know about > that would make it simple? > > All the best, > Johan If named strings don't present a problem you can use PARSE. : $" ( " ccc<"> name ) [char] " parse here swap dup chars allot 2dup 2constant cmove ; $" imagine this is a very long string" msg1
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2015-10-19 07:15 +0000 |
| Message-ID | <2015Oct19.091512@mips.complang.tuwien.ac.at> |
| In reply to | #42697 |
Johan Kotlinski <kotlinski@gmail.com> writes:
>On Saturday, October 17, 2015 at 7:41:43 PM UTC+2, Jason Damisch wrote:
>> But, I'll answer. In regular Forth the strings have a byte count
>> and that first byte can be reached with C@. The strings can
>> therefore not be longer than 255 characters long.
>
>Hi!
>It happened to me that I hit the limit, that s" was given too many characters. Does anyone have nice tricks or workarounds for that problem?
You mean that S" was limited by using a COUNTed string for internal
storage? In that case, get a better Forth system. E.g., Gforth has
no such limit. The user input device input buffer is limited to 1024
bytes, but you can have longer input lines in files (I just tried it
with an S" containing 5402 bytes).
Or you can tell your system implementor that his system is lacking and
that other systems do it better. Otherwise they'll continue to say
things along the lines of: "Counted strings are a great representation
for storing strings. Longer strings are not needed: Our users have
not complained about the limited length."
- 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: http://www.forth200x.org/forth200x.html
EuroForth 2015: http://www.rigwit.co.uk/EuroForth2015/
[toc] | [prev] | [next] | [standalone]
| From | Chris Curl <ccurl609@gmail.com> |
|---|---|
| Date | 2015-10-19 05:03 -0700 |
| Message-ID | <b3c541a7-26ed-4d04-98f4-be3eaa917b1b@googlegroups.com> |
| In reply to | #42700 |
Re using the command line, I suppose could that ... if I had a Forth system installed. I have instead chosen to implement my own. But that is a good suggestion ... I assume there is a free version of Forth out there to play with, and it is good advice to use that for reference.
[toc] | [prev] | [next] | [standalone]
| From | "Elizabeth D. Rather" <erather@forth.com> |
|---|---|
| Date | 2015-10-19 08:38 -1000 |
| Message-ID | <bIKdncHqItE7pbjLnZ2dnUU7-ckAAAAA@supernews.com> |
| In reply to | #42703 |
On 10/19/15 2:03 AM, Chris Curl wrote: > Re using the command line, I suppose could that ... if I had a Forth system installed. I have instead chosen to implement my own. But that is a good suggestion ... I assume there is a free version of Forth out there to play with, and it is good advice to use that for reference. > There are many free Forths, including free evaluation versions of SwiftForth and VFX. You really should be learning to use Forth before setting out to write one. It will make it a lot easier for you. Cheers, Elizabeth -- ================================================== Elizabeth D. Rather (US & Canada) 800-55-FORTH FORTH Inc. +1 310.999.6784 5959 West Century Blvd. Suite 700 Los Angeles, CA 90045 http://www.forth.com "Forth-based products and Services for real-time applications since 1973." ==================================================
[toc] | [prev] | [next] | [standalone]
| From | Chris Curl <ccurl609@gmail.com> |
|---|---|
| Date | 2015-10-19 14:28 -0700 |
| Message-ID | <091acd83-d640-48d3-99bd-6a1280031ae6@googlegroups.com> |
| In reply to | #42708 |
On Monday, October 19, 2015 at 2:38:31 PM UTC-4, Elizabeth D. Rather wrote: > On 10/19/15 2:03 AM, Chris Curl wrote: > > Re using the command line, I suppose could that ... if I had a Forth system installed. I have instead chosen to implement my own. But that is a good suggestion ... I assume there is a free version of Forth out there to play with, and it is good advice to use that for reference. > > > > There are many free Forths, including free evaluation versions of > SwiftForth and VFX. You really should be learning to use Forth before > setting out to write one. It will make it a lot easier for you. > > Cheers, > Elizabeth > > -- > ================================================== > Elizabeth D. Rather (US & Canada) 800-55-FORTH > FORTH Inc. +1 310.999.6784 > 5959 West Century Blvd. Suite 700 > Los Angeles, CA 90045 > http://www.forth.com > > "Forth-based products and Services for real-time > applications since 1973." > ================================================== I will install the SwiftForth eval version tonight and start playing with it.
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.forth
csiph-web