
-----------------------------------
chimerix
Tue Nov 24, 2009 9:43 am

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)








Please specify what version of Turing you are using
4.1.1

-----------------------------------
nosleepdemon
Tue Nov 24, 2009 9:49 am

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

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


-----------------------------------
Tony
Tue Nov 24, 2009 10:32 am

Re: Can you extract values from inside a procedure.
-----------------------------------

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.

-----------------------------------
jbking
Tue Nov 24, 2009 11:56 am

Re: Can you extract values from inside a procedure.
-----------------------------------
Processes + Global variables are simply a terrible idea.

It could be a fun way to learn about the [url=http://en.wikipedia.org/wiki/Readers-writers_problem]Readers-writers problem, though I'm not sure if Turing would have [url=http://en.wikipedia.org/wiki/Semaphore_%28programming%29]Semaphores or if something similar could be created from scratch.   :twisted:

-----------------------------------
nosleepdemon
Tue Nov 24, 2009 1:37 pm

Re: Can you extract values from inside a procedure.
-----------------------------------

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
