Complex multi-dimensioned flexible array reallocation
Author |
Message |
Jephir
|
Posted: Mon Aug 20, 2007 9:28 am Post subject: Complex multi-dimensioned flexible array reallocation |
|
|
When I try to run this code in Turing I get an error.
Turing: |
var stream : int
var _index : flexible array 1 .. 0, 1 .. 1 of string
procedure FileOpen (fileName : string)
open : stream, "data/" + fileName, get
end FileOpen
procedure FileClose
close : stream
end FileClose
procedure FileIndex (fileName : string)
new _index, upper (_index, 1) + 1, 1 %Increase dimension 1
_index (upper (_index, 1), 1) := fileName %Name dimension 1 the file name
FileOpen (fileName ) %Open the text file
loop %Get all the words in the text file
exit when eof (stream ) %Exit when there are no more words
new _index, upper (_index, 1), upper (_index, 2) + 1 %Increase dimension 2 to fit new word - Error occures here
get : stream, _index (upper (_index, 1), upper (_index, 2)) %Get the new word
end loop
FileClose %Close the text file
end FileIndex |
Here is the error I get:
code: | Complex multi-dimensioned flexible array reallocation not implemented yet - sorry. |
Anybody know a way around this problem? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Clayton
|
Posted: Mon Aug 20, 2007 10:22 am Post subject: RE:Complex multi-dimensioned flexible array reallocation |
|
|
Well... there really isn't unfortunately, however, take a look at the arrays tutorial in the Turing Walkthrough, as there is a really rough sort of implementation (although it's hardly a substitute.) |
|
|
|
|
|
Ultrahex
|
Posted: Mon Aug 20, 2007 4:12 pm Post subject: Re: Complex multi-dimensioned flexible array reallocation |
|
|
the real question should is why are you doing such a thing, what type of data structure are you trying to make ?
If you could explain what you are trying to read in There may be an easier way without doing multiple dimensions. |
|
|
|
|
|
CodeMonkey2000
|
Posted: Mon Aug 20, 2007 9:45 pm Post subject: RE:Complex multi-dimensioned flexible array reallocation |
|
|
There is a way around it. But you need to know to upper limits for all the dimensions. Using this you can organize a single dimensional array so it can store you multidimensional information and access the information easily. It will take a bit of thinking. Look at my MapEditor example in my 2d tile tutorial. That method only supports 2d arrays, but adding more isn't that hard.
Alternatively you can't use a multidimensional linked list, but that's really complex |
|
|
|
|
|
Nick
|
Posted: Sat Aug 25, 2007 9:21 am Post subject: RE:Complex multi-dimensioned flexible array reallocation |
|
|
hey i tired the same thing in another program im using and if you get rid of the +1 at the end of this line code: | new _index, upper (_index, 1), upper (_index, 2) + 1 | it'll work fine... however im not too sure if it'll work in your program you'll have to test it out
Edited by Clayton: Merged the double post.
sorry for the double post but with more experiment i discovered that the code you used is whats causing problems try using this instead
code: | new arrayName,newUpper1,newUpper2 |
|
|
|
|
|
|
Clayton
|
Posted: Sat Aug 25, 2007 10:26 am Post subject: RE:Complex multi-dimensioned flexible array reallocation |
|
|
In your first example, you won't ever be changing the size of your array. "Why?", you ask? Because you are just specifying new bounds for the array to be the same size that it already has by using itself as the array to reference for it's own bounds.
In your second example, what are the values of newUpper1 and newUpper2? These kinds of things make a big difference on whether the program will run or not. |
|
|
|
|
|
Nick
|
Posted: Sat Aug 25, 2007 10:03 pm Post subject: RE:Complex multi-dimensioned flexible array reallocation |
|
|
ya sorry but when i ran the first i didn't realize however the second will work but note it only ran for me when i used actually numnbers and varibles can not be used I have no idea why not |
|
|
|
|
|
|
|