Computer Science Canada

Procedure problems

Author:  packocrayons [ Fri Feb 22, 2013 3:37 pm ]
Post subject:  Procedure problems

What is it you are trying to achieve?
Have one procedure call a second procedure and that first procedure call the second


What is the problem you are having?
Second procedure is not declared when the first procedure calls it because second procedure is below first


Describe what you have tried to solve this problem
I have no clue how to


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
example:

Turing:


procedure one
% stuff
two
end one

procedure two
%stuff
one
end two



Please specify what version of Turing you are using
4.1.2 (the newest version)

Author:  A.J [ Fri Feb 22, 2013 3:57 pm ]
Post subject:  Re: Procedure problems

You need to declare procedure two before the implementation of procedure one so that the compiler knows what 'two' in procedure one is referring to. You can do this with a "forward" declaration in Turing:

Turing:

forward procedure two (argument : int)

procedure one
% stuff
var args : int
two(args)
end one

body procedure two
%stuff
one
end two


Note that the implementation of the procedure two doesn't require the arguments' definition, and requires the keyword 'body'.


: