
-----------------------------------
HazySmoke)345
Sat Sep 16, 2006 11:39 pm

Can you do cross referencing in Turing?
-----------------------------------
The following code does not work as expected...
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?

-----------------------------------
[Gandalf]
Sun Sep 17, 2006 1:21 am


-----------------------------------
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
Sun Sep 17, 2006 2:23 am


-----------------------------------
I noticed your procs are the same.  If this is intentional, then what you are intending is called recursion!
procedure f1(d: int) 
    put d 
    if d > 0 then 
        f1(d-1) 
    end if 
end f1 No need for two procs!

-----------------------------------
HazySmoke)345
Sun Sep 17, 2006 10:47 am


-----------------------------------
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...  :( 

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.  :D
