Arrays as a Result for a Function
Author |
Message |
DKNiGHTX
![](http://img168.imageshack.us/img168/6264/zoomshockdn5hc2.gif)
|
Posted: Fri Nov 03, 2006 6:15 pm Post subject: Arrays as a Result for a Function |
|
|
Is it possible?
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.
code: | function testFunction(iString : string, dString : string) : array 1 .. * of string
%Insert block here
end testFunction |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Fri Nov 03, 2006 9:10 pm Post subject: (No subject) |
|
|
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. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Fri Nov 03, 2006 9:32 pm Post subject: (No subject) |
|
|
you could accomplish this with a global flexible array that gets modified inside the function, and have a pointer to it returned |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
DKNiGHTX
![](http://img168.imageshack.us/img168/6264/zoomshockdn5hc2.gif)
|
Posted: Fri Nov 03, 2006 10:03 pm Post subject: (No subject) |
|
|
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? |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Sat Nov 04, 2006 4:54 am Post subject: (No subject) |
|
|
put it in a record, and return the record |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sat Nov 04, 2006 1:40 pm Post subject: (No subject) |
|
|
Andy wrote: 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? |
|
|
|
|
![](images/spacer.gif) |
DKNiGHTX
![](http://img168.imageshack.us/img168/6264/zoomshockdn5hc2.gif)
|
Posted: Sun Nov 05, 2006 10:12 am Post subject: (No subject) |
|
|
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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|