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

Username:   Password: 
 RegisterRegister   
 Arrays as a Result for a Function
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DKNiGHTX




PostPosted: Fri Nov 03, 2006 6:15 pm   Post subject: Arrays as a Result for a Function

Is it possible? Razz

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




PostPosted: 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.
Tony




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




PostPosted: 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?
Tony




PostPosted: Fri Nov 03, 2006 10:21 pm   Post subject: (No subject)

how are you going to have two instances of it?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Andy




PostPosted: Sat Nov 04, 2006 4:54 am   Post subject: (No subject)

put it in a record, and return the record
Cervantes




PostPosted: 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?
DKNiGHTX




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
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  [ 8 Posts ]
Jump to:   


Style:  
Search: