April 25, 2024, 07:00:46 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Arrays with more than 3 dimensions

Started by paravantis, December 07, 2006, 06:42:52 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ionic Wind Support Team

It is for compatibility with string functions of other basics.  And they are character positions, not indexes, when you are dealing with strings.  When you think of a unicode string the 3rd character position isn't the 3rd byte, or even the 6th byte depending on the character itself.
Ionic Wind Support Team

Ionic Wind Support Team

I am just about finished modifying the parser to allow 5 dimensions.  After that it's up to you ;)
Ionic Wind Support Team

John S

Quote from: Paul Turley on December 08, 2006, 09:36:33 PM
I am just about finished modifying the parser to allow 5 dimensions.  After that it's up to you ;)

What about Aurora?
John Siino, Advanced Engineering Services and Software

Ionic Wind Support Team

Of course all of these changes will be in Aurora too.
Ionic Wind Support Team

Ionic Wind Support Team

OK it is done and will be in the next update.  This now compiles and works as expected.


int a[5,5,5,5,5]
count = 0
for i = 0 to 4
for j = 0 to 4
for k = 0 to 4
for l = 0 to 4
for m = 0 to 4
a[i,j,k,l,m] = count
count+=1
next m
next l
next k
next j
next i

for i = 4 to 0 step -1
for j = 4 to 0 step -1
for k = 4 to 0 step -1
for l = 4 to 0 step -1
for m = 4 to 0 step -1
print a[i,j,k,l,m],
next m
next l
next k
next j
next i

do:until inkey$ <> ""
Ionic Wind Support Team

Mike Stefanik

Quote from: Barney on December 08, 2006, 03:51:26 AM
However, having said that I'd like to add that it would be nice to have something more powerful than a simple option base. For example if we are using years in our calculations we could use:

DIM aYears[1914:1918]

and later in the program we can access the array like this:

xyzzy=aYears[1915]

Pretty neat and easy to understand what the code does when we look at it few months later. I know this can be done fairly easily by creating an appropriate indexing function but I prefer the compiler to take care of such calculations.

I would argue that an associative array would be much more appropriate for something like that. It would be nice to have that integrated into the language, rather than using functions as it is now. In other words, something like:


Def strAddress[] As String Array

strAddress["John Doe"] = "john@bigcorp.com"
strAddress["Jane Doe"] = "jane@bigcorp.com"

ForEach strKey, strValue In strAddress
  Print strKey, strValue
Next

Mike Stefanik
www.catalyst.com
Catalyst Development Corporation

Steven Picard


J B Wood (Zumwalt)

December 11, 2006, 09:00:40 PM #32 Last Edit: December 11, 2006, 09:18:17 PM by Jonathan (zumwalt) Wood
You just need hashtables.
Otherwise, the cheat to hashtables is simply an array of structures.

Call me lazy...

Here is a structure with 2x2 dimensional arrays with 4 elements each.
This structure is party to a 2 dimensional array with 64 elements, each element is the structure.
Confusing?
Not really. Its a basic hashtable in the generic of terms.
Compile this as console and see the results.

edit: updated to make it the tower of numbers :)


OPENCONSOLE

type myStuff
def numbers[2,2] as int
def ages[2,2] as int
endtype

def array[8,8] As myStuff
def a,b,c,d as int

for a = 0 to 1
for b = 0 to 1
for c = 0 to 7
for d = 0 to 7
array[c,d].numbers[a,b]=rand(1,20)
array[c,d].ages[a,b]=rand(1,10)
next d
next c
next b
next a

print "Arrays"
for a = 0 to 1
print "+--------------------------+"
for b = 0 to 1
print "|--+--------------------+--|"
for c = 0 to 7
print "|----+----------------+----|"
for d = 0 to 7
print "|--------+--------+--------|"
if (array[c,d].numbers[a,b]) < 10 then
print "|--------+"+STR$(array[c,d].numbers[a,b])+"      +--------|"
else
print "|--------+"+STR$(array[c,d].numbers[a,b])+"     +--------|"
end if
if (array[c,d].ages[a,b]) < 10 then
print "|--------+"+STR$(array[c,d].ages[a,b])+"      +--------|"
else
print "|--------+"+STR$(array[c,d].ages[a,b])+"     +--------|"
end if

print "|--------+--------+--------|"
next d
print "|----+----------------+----|"
next c
print "|--+--------------------+--|"
next b
print "+--------------------------+"
next a
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
END


General result, results may vary since its all random:
Added some spacing, lol.. ok I am done with this now.. looks cooler in console cause everything lines up..
its this font...

Arrays
+--------------------------+
|--+--------------------+--|
|----+----------------+----|
|--------+--------+--------|
|--------+ 5      +--------|
|--------+ 4      +--------|
|--------+--------+--------|
|--------+--------+--------|
|--------+ 16     +--------|
|--------+ 3      +--------|
|--------+--------+--------|
|--------+--------+--------|
|--------+ 12     +--------|
|--------+ 5      +--------|
|--------+--------+--------|

etc.