Author |
Message |
Amarylis
|
Posted: Wed May 09, 2012 8:57 am Post subject: Returning arrays without known bounds |
|
|
Just out of curiosity, can Turing return (result, I guess) arrays that whose array bounds aren't known?
Example:
Turing: | fcn myFcn (x : array 1 .. * of int) : array 1 .. * of int |
Basically, I'm looking to make something like...
Java: | public int[] myMethod (int[] x) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Wed May 09, 2012 8:59 am Post subject: RE:Returning arrays without known bounds |
|
|
Yup. Once the function is used, the bounds will be known, so you can use the upper bounds.
just use upper (x) in your function |
|
|
|
|
![](images/spacer.gif) |
Amarylis
|
Posted: Wed May 09, 2012 9:35 am Post subject: RE:Returning arrays without known bounds |
|
|
If I understood right, you're saying for me to do this?
Turing: | fcn myFcn (x : array 1 .. * of int) : array 1 .. upper (x ) of int |
If so, that causes an error, since "x" has not been declared |
|
|
|
|
![](images/spacer.gif) |
Dreadnought
|
Posted: Wed May 09, 2012 12:07 pm Post subject: Re: Returning arrays without known bounds |
|
|
Turing functions must return arrays of size known at compile time (although the size of the parameter does not need to be known a compile time) so this wont work.
I believe the issue is that if the compiler does not know the size of the array at compile time, then it cannot perform all its checks to ensure array sizes match (Turing is not setup to do these checks at run time).
However, if your goal is to modify an array using a function, you could pass the array to a procedure using the var keyword and modify it that way.
Turing: | proc myProc (var myArray : array 1..* of int) |
It's likely that whatever you are trying to accomplish can be done without a function that returns an array of unknown size. Pointers (addressint) and type cheats might be necessary though. |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Wed May 09, 2012 1:25 pm Post subject: RE:Returning arrays without known bounds |
|
|
sorry, misinterpreted the question.
Yeah, when I run into problems like these, I just switch to using procedures. If you do it right, it'll basically accomplish the same thing. |
|
|
|
|
![](images/spacer.gif) |
Amarylis
|
Posted: Wed May 09, 2012 8:20 pm Post subject: RE:Returning arrays without known bounds |
|
|
I managed to solve my problem with procedures, though it would've made my life 10x easier if it would cause a run-time error if it didn't return the right array bounds rather than making it a compile-time error |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Thu May 10, 2012 12:37 pm Post subject: RE:Returning arrays without known bounds |
|
|
The magic of Turing. |
|
|
|
|
![](images/spacer.gif) |
|