How to create an array
  Home FAQ Contact Sign in
comp.lang.forth only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.forth Profile…
 Up
How to create an array         


Author: Duke Normandin
Date: Mar 6, 2008 16:57

Hello! I'm back at it...

I've found 2 references online for the creation of arrays:

#1 variable my_array 9 cells allot

#2 create my_array 9 cells allot

They both work on Gforth. However, I'm wondering if one declaration _more_
correct than the other? Or are they equivalent in every way? TIA...
--
Duke Normandin
dukeofperl@ml1.net
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
62 Comments
Re: How to create an array         


Author: Coos Haak
Date: Mar 6, 2008 17:20

Op Fri, 07 Mar 2008 00:57:32 GMT schreef Duke Normandin:
> Hello! I'm back at it...
>
> I've found 2 references online for the creation of arrays:
>
> #1 variable my_array 9 cells allot
>
> #2 create my_array 9 cells allot
If you want equally long arrays, use '10 cells allot' here, because
(implementation dependent) variable allocates already one cell.
>
> They both work on Gforth. However, I'm wondering if one declaration _more_
> correct than the other? Or are they equivalent in every way? TIA...
Be warned, the data cell of the variable need not be contiguous to the data
acquired by allot !

--
Coos

CHForth, 16 bit DOS applications
http://home.hccnet.nl/j.j.haak/forth.html
no comments
Re: How to create an array         


Author: Neal Bridges
Date: Mar 6, 2008 17:28

Duke Normandin wrote:
> Hello! I'm back at it...
>
> I've found 2 references online for the creation of arrays:
>
> #1 variable my_array 9 cells allot
>
> #2 create my_array 9 cells allot
>
> They both work on Gforth. However, I'm wondering if one declaration _more_
> correct than the other? Or are they equivalent in every way? TIA...

#1 is implementation-dependent, and may not work in some
implementations. #2 is the preferred approach.

--
Neal
no comments
Re: How to create an array         


Author: Elizabeth D Rather
Date: Mar 6, 2008 18:14

Neal Bridges wrote:
> Duke Normandin wrote:
>> Hello! I'm back at it...
>>
>> I've found 2 references online for the creation of arrays:
>>
>> #1 variable my_array 9 cells allot
>>
>> #2 create my_array 9 cells allot
>>
>> They both work on Gforth. However, I'm wondering if one declaration _more_
>> correct than the other? Or are they equivalent in every way? TIA...
>
> #1 is implementation-dependent, and may not work in some
> implementations. #2 is the preferred approach.

To amplify a bit:

VARIABLE allots one cell, as Coos notes, whereas CREATE doesn't allot
any space. So, to get an equivalent amount of data space, you should
allot less space if you start with VARIABLE.
Show full article (1.56Kb)
no comments
Re: How to create an array         


Author: Jerry Avins
Date: Mar 6, 2008 19:04

Elizabeth D Rather wrote:
> Neal Bridges wrote:
>> Duke Normandin wrote:
>>> Hello! I'm back at it...
>>>
>>> I've found 2 references online for the creation of arrays:
>>>
>>> #1 variable my_array 9 cells allot
>>>
>>> #2 create my_array 9 cells allot
>>>
>>> They both work on Gforth. However, I'm wondering if one declaration
>>> _more_
>>> correct than the other? Or are they equivalent in every way? TIA...
>>
>> #1 is implementation-dependent, and may not work in some
>> implementations. #2 is the preferred approach.
>
> To amplify a bit:
> ...
Show full article (1.64Kb)
no comments
Re: How to create an array         


Author: Duke Normandin
Date: Mar 6, 2008 19:19

On Thu, 6 Mar 2008, Elizabeth D Rather wrote:
>
> Neal Bridges wrote:
>> Duke Normandin wrote:
>>> Hello! I'm back at it...
>>>
>>> I've found 2 references online for the creation of arrays:
>>>
>>> #1 variable my_array 9 cells allot
...
Show full article (1.54Kb)
no comments
Re: How to create an array         


Author: Jonah Thomas
Date: Mar 7, 2008 03:44

Duke Normandin ml1.net> wrote:
>
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?

You post that here? ;)
no comments
Re: How to create an array         


Author: Duke Normandin
Date: Mar 7, 2008 04:54

On Fri, 7 Mar 2008, Jonah Thomas wrote:
>
>
> Duke Normandin ml1.net> wrote:
>>
>> A: Because it messes up the order in which people normally read text.
>> Q: Why is top-posting such a bad thing?
>
> You post that here? ;)
>

Now that you mention it, it sure makes a person step back and think,
especially a newbie to Forth like me. Bottom-posting has been the standard
on Usenet for so long for various valid reasons IMO.
--
Duke Normandin
dukeofperl@ml1.net
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
no comments
Re: How to create an array         


Author: Brad Eckert
Date: Mar 7, 2008 05:41

On Mar 6, 8:19 pm, Duke Normandin ml1.net> wrote:
> Thank you, Elizabeth! and Coos and Neal! It'll be VARIABLE for variables,
> and CREATE / ALLOT for arrays.

Some Forths provide BUFFER: which you can define yourself as
[undefined] buffer: [if]
: BUFFER: ( n -- ) CREATE ALLOT ;
[then]

This defines an uninitialized array. If your Forth has BUFFER: it may
have a little less overhead than CREATE because it doesn't need to be
patchable by DOES>. BUFFER: is also cleaner to use because it
explicitly allocates uninitialized data whereas in some systems you
have to specify what kind of data (UDATA, IDATA or CDATA) CREATE is
allocating.

If you have a bunch of large arrays and you don't want to waste
dictionary space on them (or they won't fit) then you can make BUFFER:
a little smarter:

variable bufferlist 0 bufferlist ! \ empty list of buffers
Show full article (1.63Kb)
no comments
Re: How to create an array         


Author: Krishna Myneni
Date: Mar 7, 2008 07:14

Duke Normandin wrote:
> Hello! I'm back at it...
>
> I've found 2 references online for the creation of arrays:
>
> #1 variable my_array 9 cells allot
>
> #2 create my_array 9 cells allot
>
> They both work on Gforth. However, I'm wondering if one declaration _more_
> correct than the other? Or are they equivalent in every way? TIA...

If you need a higher level set of words for working with arrays, rather than
writing your own, you may want to try the array words (and matrix words)
provided in the Forth Scientific Library. By including the auxiliary file
fsl-util.fs (for gforth) you may do the following:

20 integer array my_array{

\ store elements like this
Show full article (1.49Kb)
no comments

RELATED THREADS
SubjectArticles qty Group
Re: Helper to create multi-dimensional arrayscomp.lang.ruby ·
1 2 3 4 5 6 7