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

Username:   Password: 
 RegisterRegister   
 [Tutorial] The Include Command (Use more than 1 .t file)
Index -> Programming, Turing -> Turing Tutorials
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
recneps




PostPosted: Wed Mar 17, 2004 11:22 am   Post subject: [Tutorial] The Include Command (Use more than 1 .t file)

As asked for in the "Suggest a Tutorial", someone wanted to know how to "link" or use more than one turing file in a program, so ill show you how.

To include more than one .t file in a program, you use the command
code:
include "file.t"

Where "file.t" is the turing file you want to use.

So whats so good about this? Well you could have all your procedures predefined in separate .t files, then include them in your program, which just calls them, and maybe you could use those procedures elsewhere in other programs. Using include, you wouldn't need to put it all at the top again, just call the file using Include. Understand? Ok then, lets look at the syntax as said in Turing Reference.

Quote:

Syntax An includeConstruct is:
include fileName


Description An include is used to copy parts of files so that they become part of the Turing program. This copying is temporary, that is, no files are changed. The file name must be an explicit string constant such as "stdstuff".


So This basically says, that the Include command is used to copy the contents of files into your code, so this doesn't affect the original file, which is good, if it is being used by other programs.

The syntax is:
code:
include "start.t"

Where start.t is the existing file and it must be typed in quotes, OR be the value of a string variable.

Here is an example of how to use it.
Say this is one file, called procedure.t
code:
procedure test
put "This is a test of the Include Command."
end test

And say this is your program you are creating.
code:

include "procedure.t"
test
test
test


So with the include command, you can call the procedure directly, as if it was in the program itself.

Also, when using the include command, you need to have the full path of the file, if it is not in the same directory as the program including it.
Note that turing requires double slashes(\\) when stating a file name,
like
C:\Windows\Desktop would be
C:\\Windows\\Desktop in Turing.

I Will also post the 2 files mentioned above, so that you can try it yourself. Enjoy, and give it a try yourself.



procedure.t
 Description:
Procedure.t, also requires include.t

Download
 Filename:  procedure.t
 Filesize:  72 Bytes
 Downloaded:  422 Time(s)


include.t
 Description:
Include.t also requires procedure.t

Download
 Filename:  include.t
 Filesize:  41 Bytes
 Downloaded:  407 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
AsianSensation




PostPosted: Wed Mar 17, 2004 2:17 pm   Post subject: (No subject)

the advantage here is that someone could make a library of predefined functions which are deemed useful, and then distribute it to other people, so everyone would be able to call those functions. You can think of it like a header file in C++. In fact, I think there might be a post somewhere back that had the TuringLib, I remember it being called.

btw, good job recneps, have some bits.

+25 bits
Mazer




PostPosted: Wed Mar 17, 2004 2:37 pm   Post subject: (No subject)

AsianSensation wrote:
the advantage here is that someone could make a library of predefined functions which are deemed useful, and then distribute it to other people, so everyone would be able to call those functions.

That's part of it, but it's also useful for organization. If you're making a pretty complex with lots of functions, it'd be a real bitch to look through a single turing file to find the single function you wanted to change. But this way, you can have all functions that deal with a certain aspect of the game together in one file so you'll know right away where to look.
The advantage of this in real programming languages ( Wink ) is that, in C++ for example, if you have a 2000 line program split up into 20 files of 100 lines each and you just want to change one line in the program when you compile it to test, you only need to recompile the file which the modified line was in (assuming you've already compiled the rest).

recneps wrote:

Note that turing requires double slashes(\\) when stating a file name,
like
C:\Windows\Desktop would be
C:\\Windows\\Desktop in Turing.

Not really. You can use single forward slashes ('/').
recneps




PostPosted: Wed Mar 17, 2004 2:40 pm   Post subject: (No subject)

oh well, i learned something today then too ;D I thought you had to use double slash no matter what... o.O Oh well
bevoyleick




PostPosted: Sun Mar 21, 2004 7:09 pm   Post subject: (No subject)

thank you very much, this is very useful
Catalyst




PostPosted: Sun Mar 21, 2004 8:35 pm   Post subject: (No subject)

TuringLib:
http://www.compsci.ca/v2/viewtopic.php?t=855
bevoyleick




PostPosted: Sun Apr 25, 2004 7:04 am   Post subject: (No subject)

what happens if you compile the "main"Turing file to an .exe file?? will the include command still work?? and for the include statement, does it work if I write code in notepad or something and have Turing interpret the file as Turing code?
Dan




PostPosted: Sun Apr 25, 2004 9:40 am   Post subject: (No subject)

bevoyleick wrote:
what happens if you compile the "main"Turing file to an .exe file?? will the include command still work?? and for the include statement, does it work if I write code in notepad or something and have Turing interpret the file as Turing code?


i do not bivled include will work when compiled, what it dose is just put the code in that file right where the include line is. so you could not dymaticy load turing files when compiled.

you can all ready wirte turing code in notepad then run it in turing, the editor makes no diffrence. u can read any file in truing, just may not come out right, turing is just like notepad but with some compiler buttions at the top and some nice colors.


for the above posts: if u are making an add on or lib for turing i whould sugested using a modual and import line rather then include. this is how the real turing comands are made and to make it be loaded in to turing with out the import line u just have to edit the perdefs files.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Sponsor
Sponsor
Sponsor
sponsor
Raugrist




PostPosted: Sun Apr 25, 2004 12:43 pm   Post subject: (No subject)

Of course it works. Using include is the same as opening up the other files and copying that code into the file where you wrote include. That's how the compiler/interpreter sees it anyways.
So, if you have main.t and somuchcrap.t, and the contents of main.t is:
code:

include "somuchcrap.t"
put "WHEEEEE!"

and the contents of somuchcrap.t is:
code:

put "HADOUKEN!"
put "SHORYUKEN!"
put "Naruto sucks."

You'll get the same result as if you had only one file with the code:
code:

put "HADOUKEN!"
put "SHORYUUKEN!"
put "Naruto sucks."
put "WHEEEEE!"


Very Happy

EDIT: Oops, was he talking about dynamically including a file? Sorry, you can't do that in turing. At least, not with the include command.
Tony




PostPosted: Sun Apr 25, 2004 1:39 pm   Post subject: (No subject)

well it is possible to dynamically include .t files... but only if your program includes its own copy of the interpreter Thinking so that's kind of limited
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
the_short1




PostPosted: Thu Apr 29, 2004 7:44 pm   Post subject: (No subject)

Mazer.... yea... what u say is true... having all the small files is much better... specially on a SLOW comp... in which u have long time to compile..

too bad i was unaware at the time of my pac man game...
but then agan i orgaanized my code really well so i could memorize where was what..


yea... being able to have the encoder in ur program would be WICKED..
i wish i could do that... Evil or Very Mad so i can make a virus (while running a program) save into a .t then compile it into a .exe
that way... i wouldn't have the .exe or .t file along in the zip so noone would know Wink *** i wont put on compsci.... i just have a few enemies in which i want to screw over... Wink

anyways... back to the subject..
good one recepneps... heres 5 BITS..

only BAD part of include...
u cant do the same file twice...
so i was unable to use it to launch cervants puzzles...

UNITS can be redone again and again..
as long as u reset all variables in ur MAIN proc..

also...
for help on modules and turings 'unit' files...
search compsci for it... or if ur really stuck... ask DELOS... as he kicks the module A$$... ***he helped me make my virtual keyboard into a turing unit..


also...*** if u look in source code...

an EXCELLENT example of the powers of turing units **dont mean to plug... but this is really relevant..

look for Cervants Puzzles... then get the puzzle launcher.,..
that is all in units...
iop




PostPosted: Thu May 20, 2004 5:32 pm   Post subject: (No subject)

What if my main program is a menu, and from that menu, i am trying to include turing files that have procs? how can i do that?
Tony




PostPosted: Thu May 20, 2004 6:16 pm   Post subject: (No subject)

you include them on a very top of the program as you could include any library file
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
iop




PostPosted: Thu May 20, 2004 6:27 pm   Post subject: (No subject)

no, you didnt understand me. ill try to explain it in another way. i have 2 turing files. lets call them f1.t and f2.t these 2 files have proc's in them. i need to create a main menu using GUI. the main menu will be a different file. if i use the GUI way then in order for me to make buttons ill have to use procs. if i use a proc to launch f1.t or f2.t then it will give me an error saying that i cannot have proc's inside of procs. i have the program that im doing this with, if you need it, ill attach it
Paul




PostPosted: Thu May 20, 2004 6:41 pm   Post subject: (No subject)

Um... are u talking about this?
in file f1.t
proc put1
put "paul "..
end put1

in file f2.t
proc put2
put " is the best"
end put2

in main file
include "f1.t"
include "f2.t"
proc button
put1
put2
end button
button

this works for me
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: