Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Can you do cross referencing in Turing?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
HazySmoke)345




PostPosted: 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
Sponsor
sponsor
[Gandalf]




PostPosted: 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




PostPosted: 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




PostPosted: 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... Sad

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. Very Happy
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: