In article <580c7df3$0$339$
1472...@news.sunsite.dk>,
Doug Hoffman <
glid...@gmail.com> wrote:
>On 10/22/16 9:55 AM, lehs wrote:
>> In GForth S, is implemented with an final align
>>
>> see s,
>> : S,
>> here noop 1+ allot place align ; ok
>>
>> Suppose you want to store several counted strings in the same array,
>> then there would be an easy way to recall the i:th string in the
>> array by
>>
>> : nextword \ ad -- ad'
>> dup c@ + 1+ ;
>>
>> : word# \ array i -- ad n
>> over @ mod 0
>> rot cell+ -rot
>> ?do nextword loop count ;
>>
>> if the strings would have been stored without trailing blanks.
>> So why this ALIGN?
>
>In the Gforth 0.7.3 that I have S, is defined a bit differently.
>Regardless, by modifying that to return the address of the string one
>could simply store those addresses in a cell-based array.
>
>: s, ( caddr len -- addr )
> here dup >r over char+ allot place align r> ;
A word like this is indispensible to implement a Forth kernel,
so probably every Forth has it. In ciforth it is called $, .
However all strings in ciforth have a cell count.
Using bytes really restrict the usability.
>
>\ example use:
>
>5 array a
>s" Hello" s, 0 a !
>s" foo" s, 1 a !
>s" hello world" s, 2 a !
>
>0 a @ count type \ => Hello
>etc.
With denotations (recognizers) I don't think it useful to have
volatile strings. So then you have
"Hello" 0 a 2!
(And if your strings are bd it isn't even visible)
>
>Or some variation of the above to do exactly what you want.
>
>-Doug
Groetjes Albert
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&
c.xs4all.nl &=n
http://home.hccnet.nl/a.w.m.van.der.horst