Can you extract values from inside a procedure.
Author |
Message |
chimerix
|
Posted: Tue Nov 24, 2009 9:43 am Post subject: Can you extract values from inside a procedure. |
|
|
What is it you are trying to achieve?
I need to extract variable values from inside a prodecurde or proccess into another.
What is the problem you are having?
I have no idea what to do.
Describe what you have tried to solve this problem
I tried to use the variable value into another procedure but its not working.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
<Add your code here>
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
nosleepdemon
|
Posted: Tue Nov 24, 2009 9:49 am Post subject: Re: Can you extract values from inside a procedure. |
|
|
you should declare them as global variables (outside of a procedure at the top of your program), that way you can access them in any procedure or process
Turing: | var x : int
procedure one()
x := 5 %now x is 5
end one
procedure two()
one()
put x % output will be 5
x := 10 %now x is 10
end two
|
|
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Tue Nov 24, 2009 10:32 am Post subject: Re: Can you extract values from inside a procedure. |
|
|
chimerix @ Tue Nov 24, 2009 9:43 am wrote:
I need to extract variable values from inside a prodecurde or proccess into another.
Sounds like you might want to turn your procedures into functions.
Global variables are typically a bad idea, though it's difficult to discuss a good design, without knowing more about your code.
Also, processes are typically a very bad idea, as they are complex, not very well understood, introduce certain types of problems, and make it more difficult to figure out exactly what is going on in your code. Processes + Global variables are simply a terrible idea. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
jbking
|
Posted: Tue Nov 24, 2009 11:56 am Post subject: Re: Can you extract values from inside a procedure. |
|
|
Tony @ Tue Nov 24, 2009 8:32 am wrote: Processes + Global variables are simply a terrible idea.
It could be a fun way to learn about the Readers-writers problem, though I'm not sure if Turing would have Semaphores or if something similar could be created from scratch. ![Twisted Evil Twisted Evil](http://compsci.ca/v3/images/smiles/icon_twisted.gif) |
|
|
|
|
![](images/spacer.gif) |
nosleepdemon
|
Posted: Tue Nov 24, 2009 1:37 pm Post subject: Re: Can you extract values from inside a procedure. |
|
|
Tony wrote:
Also, processes are typically a very bad idea, as they are complex, not very well understood, introduce certain types of problems, and make it more difficult to figure out exactly what is going on in your code. Processes + Global variables are simply a terrible idea.
my mistake, i forgot how random they are in turing and that would be a deadly combination, i never used them anyways after i read this: http://compsci.ca/v3/viewtopic.php?t=7842. what are you using a process for? you can probably avoid them all together, but you post didnt post any code or much info |
|
|
|
|
![](images/spacer.gif) |
|
|