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


Groups > comp.lang.forth > #52115 > unrolled thread

The implementation of S, in GForth

Started bylehs <skydda.barnen@gmail.com>
First post2016-10-22 06:55 -0700
Last post2016-10-25 05:59 -0700
Articles 7 — 4 participants

Back to article view | Back to comp.lang.forth


Contents

  The implementation of S, in GForth lehs <skydda.barnen@gmail.com> - 2016-10-22 06:55 -0700
    Re: The implementation of S, in GForth "HAA" <someone@microsoft.com> - 2016-10-23 16:44 +1000
    Re: The implementation of S, in GForth Doug Hoffman <glidedog@gmail.com> - 2016-10-23 05:08 -0400
      Re: The implementation of S, in GForth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-10-23 18:03 +0200
    Re: The implementation of S, in GForth lehs <skydda.barnen@gmail.com> - 2016-10-24 02:10 -0700
      Re: The implementation of S, in GForth "HAA" <someone@microsoft.com> - 2016-10-25 21:39 +1000
        Re: The implementation of S, in GForth lehs <skydda.barnen@gmail.com> - 2016-10-25 05:59 -0700

#52115 — The implementation of S, in GForth

Fromlehs <skydda.barnen@gmail.com>
Date2016-10-22 06:55 -0700
SubjectThe implementation of S, in GForth
Message-ID<06a5cb83-da91-4b38-a0ea-e38508ed8aee@googlegroups.com>
In GForth  S,  is implemented with an final align

see s,
: S, 
  here noop 1+ allot place align ; ok

that seems unnecessary. 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?

[toc] | [next] | [standalone]


#52126

From"HAA" <someone@microsoft.com>
Date2016-10-23 16:44 +1000
Message-ID<nuhipq$14va$1@gioia.aioe.org>
In reply to#52115
lehs wrote:
> In GForth  S,  is implemented with an final align
>
> see s,
> : S,
>   here noop 1+ allot place align ; ok
>
> that seems unnecessary. 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?

If it's any comfort VFX, SWF, Win32F all have their own variations on this.



[toc] | [prev] | [next] | [standalone]


#52129

FromDoug Hoffman <glidedog@gmail.com>
Date2016-10-23 05:08 -0400
Message-ID<580c7df3$0$339$14726298@news.sunsite.dk>
In reply to#52115
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> ;

\ 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.

Or some variation of the above to do exactly what you want.

-Doug

[toc] | [prev] | [next] | [standalone]


#52134

Fromalbert@cherry.spenarnc.xs4all.nl (Albert van der Horst)
Date2016-10-23 18:03 +0200
Message-ID<nuin07$15l$1@cherry.spenarnc.xs4all.nl>
In reply to#52129
In article <580c7df3$0$339$14726298@news.sunsite.dk>,
Doug Hoffman  <glidedog@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

[toc] | [prev] | [next] | [standalone]


#52144

Fromlehs <skydda.barnen@gmail.com>
Date2016-10-24 02:10 -0700
Message-ID<591d2ca6-3a18-447f-b372-2ee207f9883f@googlegroups.com>
In reply to#52115
If you want an align you could put it there after, it's more convenient.

[toc] | [prev] | [next] | [standalone]


#52188

From"HAA" <someone@microsoft.com>
Date2016-10-25 21:39 +1000
Message-ID<nuncr2$1pb0$1@gioia.aioe.org>
In reply to#52144
lehs wrote:
> If you want an align you could put it there after, it's more convenient.

If your system's S, aligns do the same in your address calculation:

: nextword \ ad -- ad'
  dup c@ + 1+ ALIGNED ;



[toc] | [prev] | [next] | [standalone]


#52189

Fromlehs <skydda.barnen@gmail.com>
Date2016-10-25 05:59 -0700
Message-ID<8c37996c-69b3-4cb5-9469-57769a3aa7d3@googlegroups.com>
In reply to#52188
Den tisdag 25 oktober 2016 kl. 12:40:37 UTC+2 skrev HAA:
> lehs wrote:
> > If you want an align you could put it there after, it's more convenient.
> 
> If your system's S, aligns do the same in your address calculation:
> 
> : nextword \ ad -- ad'
>   dup c@ + 1+ ALIGNED ;

Yes that's also a solution. Thanks!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web