

-----------------------------------

Lucas

Fri Mar 25, 2011 7:08 pm


Passing array info to a procedure

-----------------------------------

What is it you are trying to achieve?
I would like to do a procedure using data from a flexible array, but when i hit run it says "Compile time expression expected", and highlights "numpoints" in the line procedure transition (x, y : array 0 .. numpoints of real). All of the code i posted is in a module, not usre if that has anything to do with it. Anyway i can fix this?



    procedure transition (x, y : array 0 .. numpoints of real)
        for decreasing : 100 .. 1
            for i : 0 .. numpoints
                %%%%%%
                %%%%%%
                refresh (false)
            end for
        end for
    end transition
    
    % calculating stuff for the transition to XY view
    procedure tooxy
        if view not= "xy" then
            for a : 0 .. numpoints
                if view = "zy" then
                    dix (a) := (points (a).x - points (a).z) / 100
                    diy (a) := 0
                elsif view = "zx" then
                    dix (a) := (points (a).x - points (a).z) / 100
                    diy (a) := (points (a).y - points (a).x) / 100
                elsif view = "3d" then
                    dix (a) := (points (a).x - points (a).dx) / 100
                    diy (a) := (points (a).y - points (a).dy) / 100
                end if
            end for
            transition (points.x, points.y)
            view := "xy"
        end if
    end tooxy



Please specify what version of Turing you are using
4.1.1


-----------------------------------

Tony

Fri Mar 25, 2011 7:15 pm


Re: Passing array info to a procedure

-----------------------------------

when i hit run it says "Compile time expression expected", and highlights "numpoints"
The value of numpoints is not known at the runtime. You might want to read the docs on [tdoc]flexible[/tdoc] for details.


-----------------------------------

Lucas

Fri Mar 25, 2011 7:23 pm


RE:Passing array info to a procedure

-----------------------------------

The value of numpoints at runtime is -1, i declare it earlier in the program. Or does that not make a difference?


-----------------------------------

Tony

Fri Mar 25, 2011 7:37 pm


RE:Passing array info to a procedure

-----------------------------------

Sorry, I meant to say "at compile time"


-----------------------------------

Lucas

Fri Mar 25, 2011 7:44 pm


RE:Passing array info to a procedure

-----------------------------------

Doesnt it just complie it when i hit "run"?


-----------------------------------

Tony

Fri Mar 25, 2011 8:13 pm


RE:Passing array info to a procedure

-----------------------------------

Yes, but we don't know how it compiles it. For all we know it just sees that it's not a constant, and decides that it doesn't want to deal with that.


-----------------------------------

Lucas

Fri Mar 25, 2011 8:19 pm


RE:Passing array info to a procedure

-----------------------------------

okay thx. anyway i can get around that?


-----------------------------------

Tony

Fri Mar 25, 2011 8:58 pm


Re: Passing array info to a procedure

-----------------------------------

Yes. Use constants or flexible arrays, instead of regular ones.
You might want to read the docs on 


-----------------------------------

Lucas

Fri Mar 25, 2011 9:13 pm


RE:Passing array info to a procedure

-----------------------------------

numpoints is a flexible array


-----------------------------------

Tony

Fri Mar 25, 2011 9:25 pm


RE:Passing array info to a procedure

-----------------------------------

RTFM


-----------------------------------

Lucas

Sat Mar 26, 2011 7:32 am


RE:Passing array info to a procedure

-----------------------------------

1. My mistake, numpoints is a number value of the length of the flexible array.
2. All my arrays are flexible, except for 
procedure transition (x, y : array 0 .. numpoints of real) , and when i made x, y, flexible array 0...numpoints of real i get a syntax error at flexible. I dont understand what you want me to use constants or flexible array is.
3. Yes, i followed your link, thx, and it says that the lower bounds must be known at compile time n stuff.
4. please, im new, and if u think that this is the stupidest message ever and that im a complete idiot, then by all means just dont answer


-----------------------------------

Tony

Sat Mar 26, 2011 12:21 pm


RE:Passing array info to a procedure

-----------------------------------

I was trying to lead you towards this bit in the documentation link posted above

There is no flexible array parameter type, although a flexible array can be passed to an array parameter with "*" as the upper bound.

You should be able to say
[code]
procedure transition (x, y : array 0 .. * of real)
[/code]


-----------------------------------

Lucas

Sat Mar 26, 2011 8:16 pm


RE:Passing array info to a procedure

-----------------------------------

AHH! thank you :)

