Posted: Mon Nov 26, 2007 6:55 pm Post subject: Thoughts on Action Procedures and a Dynamic Number of Parameters.
So I've recently been compelled to think about the age old problem of having an action procedure with a variable number of parameters for use with a GUI Widget (think buttons here). I've come up with a couple ideas on a rough design plan on how to implement it, and I keep getting close. However, everytime I think about that plan, it gets shot down because I have no clue as to how I would get to that magical dynamic number of parameters.
Basically my plan thus far is to have a basic Action class. From that, when you code your program that uses buttons, you create a specific subclass of Action from which you can code in your action procedure. However, like I said above, the issue still comes up where you need to account for a variable number of parameters.
That being said, I'm wondering if anyone out there might have an idea on how to do this. I'm really starting to miss Ruby's way of grouping multiple arguments into an array right now.
Sponsor Sponsor
chrisciscoioio
Posted: Mon Nov 26, 2007 7:43 pm Post subject: Re: Thoughts on Action Procedures and a Dynamic Number of Parameters.
Hey,
I gave up my Turing days years ago, but I know Inheritance would fit the bill, OO Turing has Inheritance. Read up on that some.
For Unlimited Params, that is not done, just overload which all your workable options.
I know this is how Java, C# solve problems to name a few.
10 cents
Chris
md
Posted: Mon Nov 26, 2007 8:00 pm Post subject: RE:Thoughts on Action Procedures and a Dynamic Number of Parameters.
maybe find a hackish way to look at the stack with pointers? I know C does variable number of parameters no problem, and since turing goes to C (or C++... whatever) it might support it too...
More likely your SOL and you'll have to resort to some hackish array type call.
Clayton
Posted: Mon Nov 26, 2007 8:04 pm Post subject: RE:Thoughts on Action Procedures and a Dynamic Number of Parameters.
Yes, and that's what I was afraid of. In the end, it will probably end up being some hackish type of solution. We shall see.
Nick
Posted: Mon Nov 26, 2007 11:34 pm Post subject: RE:Thoughts on Action Procedures and a Dynamic Number of Parameters.
think about how View.Set() works, it takes a single parameter as a string then checks that string for known code such as (pseudo code since im not sure how turing works this exactly)
code:
procedure Set(param:string)
if param has offscreen only in it then
change screen to offscreenonly
elsif more code
end if
end Set
Posted: Tue Nov 27, 2007 12:36 am Post subject: Re: Thoughts on Action Procedures and a Dynamic Number of Parameters.
I still think, the best and not hackish way is to do it through classes, with inheritance.
Create overloaded methods (or whatever you want to call them).
Yes turing has that View set, but is a very hackish method, very high chance of causing errors, because you would rely on the user knowing everything down to a nail.
With OO classes you can quickly create the features, and include overloading for as many types as you need, as well as allowing other users to create other
classes that use inheritance, and they can extend your class as needed.
Lets see about some psuedo code
class TButton
{
TButton (int x, int y, string name)
{
}
TButton (int x, int y, string name, int colour)
{
}
}
My second 10 cents
Chris
zylum
Posted: Tue Nov 27, 2007 12:43 am Post subject: RE:Thoughts on Action Procedures and a Dynamic Number of Parameters.
im pretty sure turing doesnt support method overloading
chrisciscoioio
Posted: Tue Nov 27, 2007 12:53 am Post subject: Re: Thoughts on Action Procedures and a Dynamic Number of Parameters.
It does, and second arg to you, stupid cannot edit a post that has been replied to, I just finished it.
This snippet is from holtsoft, I duno like I said I gave up Turing years ago, but the programming concepts are still the same.
Quote:
Object Oriented Programming in Turing - Advanced
The course uses the Object Oriented Turing programming language to provide a brief overview of object-oriented concepts before proceeding to advanced concepts. These include: abstract classes, polymorphism, factoring (object-oriented design), genericity, method overloading, operator overloading, and multiple inheritance. There will also be a walkthrough of a large project which incorporates many of these principles. (Lab required, Turing software will be provided)
Also since I cannot edit that top post anymore, basicly you need to look to OO Turing and then you should be able to do it, it will not be easy, but go for it.
Reason it is 1 AM, and that was approx 15 or so minutes of typing, and I am tired, maybe I will add it again later.
Sponsor Sponsor
zylum
Posted: Tue Nov 27, 2007 12:59 am Post subject: RE:Thoughts on Action Procedures and a Dynamic Number of Parameters.
correct me if im wrong but this:
code:
proc a (v1 : int)
put v1
end a
proc a (v1, v2 : int)
put v1, " ", v2
end a
is method overloading... doesn't seem to work, does it?
Clayton
Posted: Tue Nov 27, 2007 12:03 pm Post subject: RE:Thoughts on Action Procedures and a Dynamic Number of Parameters.
No. Turing does not support method overloading. However, I am thinking of something slightly hackish, although not entirely hackish. I'll explain later when I have more time.
chrisciscoioio
Posted: Tue Nov 27, 2007 12:26 pm Post subject: Re: RE:Thoughts on Action Procedures and a Dynamic Number of Parameters.
Clayton @ Tue Nov 27, 2007 12:03 pm wrote:
No. Turing does not support method overloading. However, I am thinking of something slightly hackish, although not entirely hackish. I'll explain later when I have more time.
Ask Holtsoft, not that they will answer, but there site is still there and it says that it does, and really if it has classes it needs overloading.
I mean as far as I can see it does, like I said I gace up turing for C++ and Game Programming, but it is wite there it sayd it does.
Clayton
Posted: Tue Nov 27, 2007 5:46 pm Post subject: RE:Thoughts on Action Procedures and a Dynamic Number of Parameters.
And I'm telling you, Turing does not support method overloading. And if it does, it's most likely going to involve something that's not exactly worth the effort. On top of that, Turing doesn't support multiple inheritance, nor does it support operator overloading. If you read closer, you'll see that the section quoted is from a course description page. Not a language reference.
chrisciscoioio
Posted: Tue Nov 27, 2007 10:43 pm Post subject: Re: Thoughts on Action Procedures and a Dynamic Number of Parameters.
I guess that is what I get for playing with good programming lanuages, I assumed that when they used classes they would support an actual class,
not just make module, group, package, they are deceptive.
I also kind thought that when the course description says there will be a lab with the involved topics and Turing will be provided it means it can be done.
Anyways, Hackish method.
code:
class foobar
export foobar_i, foobar_ii
var cFoo : int
var cBar : int
procedure foobar_i (foo : int)
cFoo := foo
end foobar_i
procedure foobar_ii (foo : int, bar : int)
cFoo := foo
cBar := bar
end foobar_ii
end foobar
For reference, the i stand for int, it a pseudo code way of showing what params are accepted, so...
i = int
s = string
r = real
b = boolean
and so forth.
Clayton
Posted: Wed Nov 28, 2007 4:41 pm Post subject: RE:Thoughts on Action Procedures and a Dynamic Number of Parameters.
That.... is beyond hackish to me. I think what I'm going to end up doing is creating a basic Object class. From that, I will subclass Integers, Strings, Floats, Booleans. Then, in my GUI class, I will have the action procedure take in an array of Objects. Hackish I know, but... not bad when considering the alternative.
chrisciscoioio
Posted: Wed Nov 28, 2007 11:13 pm Post subject: Re: Thoughts on Action Procedures and a Dynamic Number of Parameters.
Thats not a bad idea, it might work, less hackish.
My hackish method stepping over the compile phase, since that is what they tag overloaded methods like, except it is at the beginning no underscore and its in assembly.