Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Passing array info to a procedure
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Lucas




PostPosted: Fri Mar 25, 2011 7:08 pm   Post subject: 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?

Turing:


    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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Mar 25, 2011 7:15 pm   Post subject: Re: Passing array info to a procedure

Lucas @ Fri Mar 25, 2011 7:08 pm wrote:
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 flexible for details.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Lucas




PostPosted: Fri Mar 25, 2011 7:23 pm   Post subject: 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




PostPosted: Fri Mar 25, 2011 7:37 pm   Post subject: RE:Passing array info to a procedure

Sorry, I meant to say "at compile time"
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Lucas




PostPosted: Fri Mar 25, 2011 7:44 pm   Post subject: RE:Passing array info to a procedure

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




PostPosted: Fri Mar 25, 2011 8:13 pm   Post subject: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Lucas




PostPosted: Fri Mar 25, 2011 8:19 pm   Post subject: RE:Passing array info to a procedure

okay thx. anyway i can get around that?
Tony




PostPosted: Fri Mar 25, 2011 8:58 pm   Post subject: Re: Passing array info to a procedure

Yes. Use constants or flexible arrays, instead of regular ones.
Tony @ Fri Mar 25, 2011 7:15 pm wrote:
You might want to read the docs on flexible for details.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Lucas




PostPosted: Fri Mar 25, 2011 9:13 pm   Post subject: RE:Passing array info to a procedure

numpoints is a flexible array
Tony




PostPosted: Fri Mar 25, 2011 9:25 pm   Post subject: RE:Passing array info to a procedure

RTFM
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Lucas




PostPosted: Sat Mar 26, 2011 7:32 am   Post subject: 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




PostPosted: Sat Mar 26, 2011 12:21 pm   Post subject: RE:Passing array info to a procedure

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

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)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Lucas




PostPosted: Sat Mar 26, 2011 8:16 pm   Post subject: RE:Passing array info to a procedure

AHH! thank you Smile
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: