1. newcomer problem
- Posted by Franco Marangoni <NX176 at MAIL2.CROWN-NET.COM> Nov 14, 1998
- 737 views
To all Euphoria enthusiasts: I have a multi-dimensional array, array[x][y]. This array is now little, but could grow up to some Mbyte. During debug, when I want to know the content of a cell (example: array[3= 70][41]), the answer is: "NOT DEFINED AT THIS POINT". I can see only the= first elements in the array by typing "array". Is there a solution to overcome this?
2. Re: newcomer problem
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> Nov 14, 1998
- 626 views
- Last edited Nov 15, 1998
>To all Euphoria enthusiasts: >I have a multi-dimensional array, array[x][y]. >This array is now little, but could grow up to some Mbyte. >During debug, when I want to know the content of a cell (example: array[370][41]), the answer is: "NOT DEFINED AT THIS POINT". I can see only the first elements in the array by typing "array". >Is there a solution to overcome this? First of all, the actual size is dynamic, once a new cell is *initialized* you can use it. sequence my_array my_array = {{}} -- 2D array Now you want to set cell [370][41] you need to specific cells [1..369]. To simulate basic arrays, you could do this: constant CELLS = 370, ROWS = 41 my_array = repeat (repeat(0,CELLS),ROWS) All values are now initialized to 0 (like in basic) You can now set the value of a cell: my_array[370][41] = "Hello!" However, to set cell 41, you need to ADD it. my_array[370] = append(my_array[370], "This goes into cell 42") After that you could set it to another value: my_arra[370][42] = "This is the 42th row" To add another row with 41 cells do this: my_array = append(my_array, repeat (0, CELLS)) All cells are initialized to 0 (like in basic). You could also have a new row that is a copy of an other row: my_array = append(my_array, my_array[1]) Now the first row, is copied and add to the array at the end. This is how sequences work. They are dynamic, but they can *not* contain uninitialized values. They can be un-initialized: sequence s -- s is not yet initialized s = {} There is no way to add an un-initialized *element* (Euphoric term: same as cell) to the sequence. You can only add *values* not just room for values. The declaration and storage occupation is all handled by the interpreter dynamically. Even though you have 400 by 400 array, it may well be much different in memory, if the interpreter can figure it can "cheat". For example: s = repeat ("Euphoria", 10) S is now a sequence, containing 10 sequences contain the atoms for each character in "Euphoria". Its like: { "Euphoria", "Euphoria", "Euphoria" .. etc.. (10 times) } You would think it would have the sequence/string "Euphoria" in memory 10 times, though this is an example where it cheats, and only keeps one instance of "Euphoria" in memory and points to it 10 times. It can cheat, because the end-programmer (you and me) has no control over storage at all. We can't add room for data storage, only data itself, where Euphoria handles all the storing issues. Ralf
3. Re: newcomer problem
- Posted by Irv Mullins <irv at ELLIJAY.COM> Nov 14, 1998
- 615 views
On Sat, 14 Nov 1998 20:50:57 +0100, Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> wrote: >>To all Euphoria enthusiasts: >>I have a multi-dimensional array, array[x][y]. >>This array is now little, but could grow up to some Mbyte. >>During debug, when I want to know the content of a cell (example: >array[370][41]), the answer is: "NOT DEFINED AT THIS POINT". I can see only >the first elements in the array by typing "array". >>Is there a solution to overcome this? > > >First of all, the actual size is dynamic, once a new cell is *initialized* >you can use it. > Correct. But the message "not defined at this point" is Euphoria's response (in the trace mode) to *any* reference to an element of a sequence: name = "Irv" ? name will print "Irv", whereas (in the debugger) ? name[1] will say "not defined at this point". What it really is saying is: Euphoria can't do that, even though it can easily reference the same array elements programmatically. Try this: with trace sequence array array = repeat(repeat({},100),400) trace(1) array[371][41] = 49 ? array[371][41] -- look at array in the trace mode. Other than sprinkling print statements thru the code, you can use the type () function to track changes to an element of an array. Irv
4. Re: newcomer problem
- Posted by Irv Mullins <irv at ELLIJAY.COM> Nov 14, 1998
- 685 views
Franco Marangoni wrote: > To all Euphoria enthusiasts: > I have a multi-dimensional array, array[x][y]. > This array is now little, but could grow up to some Mbyte. > During debug, when I want to know the content of a cell (example: > array[370][41]), the answer is: "NOT DEFINED AT THIS POINT". I can see only the > first elements in the array by typing "array". > Is there a solution to overcome this? If you want to see the contents only at certain points, you can put in a print statement: ? array[370][41] A better (neater) way is to display the item each time there is an assignment to it: This is easy using the Euphoria "type", as there is only 1 line of code to change when you are finished debugging (instead of numerous "print" statements scatterd thru your program!) I use: type debug_array (object x) position(1,1) puts(1,' ') -- blank out previous contents position(1,1) ? x[370][41] -- show the area in question -- you could insert a pause or delay here if things are changing much too fast. return 1 end type now, define your array as: debug_array my_array rather than sequence array change it back to sequence array when you're finished debugging. Regards, Irv