
-----------------------------------
DKNiGHTX
Fri Nov 03, 2006 6:15 pm

Arrays as a Result for a Function
-----------------------------------
Is it possible?  :P

So far I've managed to try 10+ different methods, all result as a syntax error at "*" when trying to return.  However, if I harcode the amount, it does work, but the array is of the wrong size (since it's a string manipulation function, it sets its own length).  However, I can't use the flexable modifier; it won't let me.  I don't have the code on me, seeing as I'm getting the student copy in about 3 +/- days.  I believe this is what I used.  

function testFunction(iString : string, dString : string) : array 1 .. * of string
%Insert block here
end testFunction

-----------------------------------
Clayton
Fri Nov 03, 2006 9:10 pm


-----------------------------------
No, as far as i know, you cannot return an array with unknown upper bounds at compile time. I believe that this is due to some sort of difficulty in the way it would have to be stored in memory.

-----------------------------------
Tony
Fri Nov 03, 2006 9:32 pm


-----------------------------------
you could accomplish this with a global flexible array that gets modified inside the function, and have a pointer to it returned

-----------------------------------
DKNiGHTX
Fri Nov 03, 2006 10:03 pm


-----------------------------------
See, I was going to use a global variable, but if I have two instances of it at the same time, would it affect it?

-----------------------------------
Tony
Fri Nov 03, 2006 10:21 pm


-----------------------------------
how are you going to have two instances of it?

-----------------------------------
Andy
Sat Nov 04, 2006 4:54 am


-----------------------------------
put it in a record, and return the record

-----------------------------------
Cervantes
Sat Nov 04, 2006 1:40 pm


-----------------------------------
put it in a record, and return the record
As far as I remember, Turing won't allow flexible arrays within records. This is for the same reason that we have so much trouble doing multi-dimensional flexible arrays.

However, this is the right train of thought. One solution is to wrap the flexible array in an object and return that object.

Now that you're going to the trouble of making objects, it's time to think about whether there's anything else you might like to include in that object. Should you make your code object-oriented at this point?

-----------------------------------
DKNiGHTX
Sun Nov 05, 2006 10:12 am


-----------------------------------
Sorry, I guess I meant threading, but I don't think my Gr10 course will be getting anywhere near that.  I was thinking more along the lines of Lua, my mistake.
