Posted: Sat Sep 16, 2006 11:39 pm Post subject: Can you do cross referencing in Turing?
The following code does not work as expected...
code:
procedure f1(d: int)
put d
if d > 0 then
f2(d-1)
end if
end f1
procedure f2(d: int)
put d
if d > 0 then
f1(d-1)
end if
end f2
f1(6)
... because Turing can't call f2 while in f1. Is that possible to fix?
Sponsor Sponsor
[Gandalf]
Posted: Sun Sep 17, 2006 1:21 am Post subject: (No subject)
Yes it is. Look up the forward keyword in Turing help.
You must be careful when doing this, though, since it's easy to create an endless loop of procedure calls. For example f1 calls f2, f2 calls f1, f1 calls f2, and so on until the program crashes or just stops running.
NikG
Posted: Sun Sep 17, 2006 2:23 am Post subject: (No subject)
I noticed your procs are the same. If this is intentional, then what you are intending is called recursion!
code:
procedure f1(d: int)
put d
if d > 0 then
f1(d-1)
end if
end f1
No need for two procs!
HazySmoke)345
Posted: Sun Sep 17, 2006 10:47 am Post subject: (No subject)
Quote:
Yes it is. Look up the forward keyword in Turing help.
Thanks for the hint. I only have about 3 bits to give away, though...
Quote:
I noticed your procs are the same. If this is intentional, then what you are intending is called recursion!
Actually, I wrote the source code that way to simplify the problem I really had, the two procedures in my real program are in fact very different. Thanks for helping anyways.