Computer Science Canada Including via variables? |
Author: | StealthArcher [ Sat Jan 12, 2008 12:21 pm ] |
Post subject: | Including via variables? |
Is it possible? Or at least possible to choose to import a certain turing files' procedure via user input? |
Author: | Nick [ Sat Jan 12, 2008 12:26 pm ] |
Post subject: | RE:Including via variables? |
I don't belive so because according to memory imorpt has to be done before anything then include has to be done right after that, thus creating a error if a varible has be declared before |
Author: | StealthArcher [ Sat Jan 12, 2008 12:27 pm ] |
Post subject: | RE:Including via variables? |
Dang, now I'll have to figure out another way... |
Author: | Clayton [ Sat Jan 12, 2008 2:56 pm ] |
Post subject: | RE:Including via variables? |
have you actually tried and tested some code? then you wouldn't have to ask this question. |
Author: | StealthArcher [ Sat Jan 12, 2008 3:02 pm ] |
Post subject: | RE:Including via variables? |
I have tried, found nothing, then I asked. Seeming this is as that, anyone know a way to execute a procedure off of user input, I haven't found any way to do it yet, except peicing apart the input letter by letter, and coding a thousand different cases for each possible letter combination... Any ideas or am I stuck? |
Author: | McKenzie [ Sat Jan 12, 2008 3:22 pm ] |
Post subject: | Re: Including via variables? |
I know what you are asking, there are a number of languages that allow this but Turing is not one of them. You are basically going to have to use big a case structure for all of your options. |
Author: | StealthArcher [ Sat Jan 12, 2008 3:41 pm ] |
Post subject: | RE:Including via variables? |
Dang, Looks like I'll be porting my HBM Converter sooner than I wanted to... |
Author: | ericfourfour [ Sat Jan 12, 2008 6:58 pm ] | ||||||||||||||||
Post subject: | Re: Including via variables? | ||||||||||||||||
This can be done in Turing but it is very static. The way I would do it might be advanced for the average Turing programmer. However, it greatly simplifies the process of adding more procedures. First make a datatype that contains a procedure and a string representation (the name) of the procedure.
The easiest thing to do from here would be to store this datatype in an array. You also need a function to search through the array with a specified string and find the matching name. This function will return the index in the array to simplify error checking (ie. 0=error, everything else is good):
Next, a few simple test procedures will be needed. One will output "Hello World". Another will draw a random box. The third will allow the end-user to quit the program. A global variable will be needed for the latter because the procedures cannot take parameters.
Now the basic structure is defined and set up. For the test section, an array will be required. This array will contain 3 elements, 1 for each procedure. If there were more procedures, there would be more elements in the array. To iniitialize the array, each element will be assigned a procedure and name of the procedure:
Now that the procedure array initialized, it's time to setup the user input. This will be looped so the end-user has the option to try more than once:
That is pretty simple. Next, the user input will be parsed. If you remember, the function declared at the top of the program takes a string and returns the index of the procedure with that name.
The end-user might have not entered the procedure name correctly. In this case, the function used will return 0 instead of an array index. This needs to be checked for. If the index returned is 0, an error message will be given. If it is not 0, the procedure at the returned index will be called:
Finally, an exit condition for the loop is needed. Otherwise the program would go on forever. During the test procedure declarations, a global variable called done was declared and initialized. The procedure named quitProgram changes the value of this variable to true. This works perfectly for the exit statement:
This method simplifies calling procedures based on input greatly in a very static language like Turing. If this is too complex or you only are using one or two procedures, you should do what McKenzie suggested. |
Author: | StealthArcher [ Sat Jan 12, 2008 7:00 pm ] |
Post subject: | RE:Including via variables? |
Wow, a bit of reading, but looks good. Thanks, that would've taken me a while to get, as I still am rather noobish with records. Thanks again, I'll mention you in the credits. |
Author: | ericfourfour [ Sat Jan 12, 2008 7:29 pm ] |
Post subject: | Re: Including via variables? |
More information on records here. I don't remember seeing a tutorial specified on the procedure datatype but a simple google search on callback functions will provide some explanation. The Turing as a Functional Programming Language tutorial expands on using procedures as variables to allow functions as parameters. If you want to give credit, I think it would be better to cite this thread. |
Author: | StealthArcher [ Sat Jan 12, 2008 8:26 pm ] |
Post subject: | RE:Including via variables? |
ATM, I'm just trying to see if there is a way to assign the call variable by a string, and have it call the procedure based on the string I write in or get. I don't want to have a predefined set of options, namely I want to be able to scan a directory for Compressor files (They'll be marked to assure no errors), then make a set of this, using the file's name as the procedure call. Just in case I can't get it to work, what would be a lang. that can do this easily, I'm currently learning Python and C++.... |
Author: | OneOffDriveByPoster [ Sat Jan 12, 2008 9:40 pm ] |
Post subject: | Re: RE:Including via variables? |
StealthArcher @ Sat Jan 12, 2008 8:26 pm wrote: namely I want to be able to scan a directory for Compressor files (They'll be marked to assure no errors), then make a set of this, using the file's name as the procedure call. I am interested but confused. Exactly what do the procedures do? You mean, you will somehow have a procedure generated from the files? |
Author: | StealthArcher [ Sat Jan 12, 2008 10:16 pm ] |
Post subject: | Re: Including via variables? |
In essence, something like other programs having plugins, I want my HBM converter to scan a directory at opening, checking for compressor files, which have a specific opening sequence, then allow the user later on to choose one to compress the file with, the user will input a string, so after the inclusion of all the files at the beginning, I need turing to be able to run a proc(in the compressor's file) named the same as the users input. All procs in com. files will be the same name as the file. |
Author: | OneOffDriveByPoster [ Sat Jan 12, 2008 10:31 pm ] |
Post subject: | Re: Including via variables? |
I think you will get better luck with Python or C. Are these Compressor files supposed to be scripts/source code/executables? For C, you will likely get stuck with OS-specific code though--and DLLs and the such. |
Author: | StealthArcher [ Sat Jan 12, 2008 10:34 pm ] |
Post subject: | Re: Including via variables? |
AATM with turing, they are source code, however if I move to python they will be scripts. |
Author: | ericfourfour [ Sun Jan 13, 2008 9:42 am ] |
Post subject: | RE:Including via variables? |
Here is a way this can be done. It is the simplest way of doing what I think you want to do. 1. Have two files. One contains a list of included source files. The other one contain the procedure array's initialization. 2. Make a separate program that scans the plugin directory and adds each source file to the include list. Then have it scan each source file individually and add the procedures the array. Turing 4.1.1 has a lexer class that can help you parse source files. It supports commands for c, c++ and Turing. It is pretty buggy and will not work without some modifications. |
Author: | Clayton [ Sun Jan 13, 2008 10:20 am ] |
Post subject: | RE:Including via variables? |
Really, a lexer class you say... interesting. |
Author: | StealthArcher [ Sun Jan 13, 2008 10:47 am ] |
Post subject: | Re: Including via variables? |
It's new to me, what exactly is the syntax for usage, it isn't in the help files.(That or I'm using the wrong help files...) |
Author: | Tony [ Sun Jan 13, 2008 2:51 pm ] |
Post subject: | RE:Including via variables? |
I always through that the lexer was there to parse Turing into C++, before compilation. I'd love to see some examples of implementing it in your own Turing app. |
Author: | ericfourfour [ Sun Jan 13, 2008 7:14 pm ] |
Post subject: | RE:Including via variables? |
Check the folder "Support\lib". The lexer folder contains the lexer classes. A window class was also added (essentially a wrapper for the window module). The problem with the lexer class is that it uses Error.Trip(). This function was removed from Turing 4.1.1. It's commented out in the Error module ("Support\predefs\Error.tu"). When uncommented, an error occurs. The easiest way of implementing the Lexer class would be to copy it from the folder into your program folder. Then comment out the line that uses Error.Trip(). After writing this whole comment, I realized there is a lexer class in Turing 4.0.5 as well. This one does not require modifications to work. What I wrote before this paragraph was for Turing 4.1.1. Turing 4.0.5 can easily implement the lexer class. There is a window class in the older version as well. |
Author: | StealthArcher [ Sun Jan 13, 2008 7:24 pm ] |
Post subject: | RE:Including via variables? |
Ouch, you mean after a year of work they made it worse? Do you know how to call it though? |
Author: | ericfourfour [ Mon Jan 14, 2008 8:36 am ] |
Post subject: | RE:Including via variables? |
I guess it is worse, but who does error checking through the Error module anyway? I rember trying to set it up and it was a lot of extra work. The lexer class is not documented. There's a guide on object orientation in the Turing Walkthrough. That will teach you how to use classes. The rest you have to figure out on your own. |
Author: | StealthArcher [ Mon Jan 14, 2008 6:00 pm ] |
Post subject: | RE:Including via variables? |
Alrighty, after a while of fiddling around with it, I have come to a conclusion: IT HATES ME I have set up a test file to see how it works before integrating it with my main program. I attempt to scan the file Inline.t (one of my compressors), it scans the first two lines fine(which are a comment, and a return[newline whatever]) however, when I get to the next one which states "proc Inline (fileName:string)" It tells me I have a segmentation error, which confused me, any ideas? It only happens when I use the OOT.SFD file, not when I use C.SFD or CPP.SFD. (Yes they really are capitalized like that) Any way I got another idea going, but I need some help on implementing it. I was thinking I could make every compressor an exe, then run it using Sys.Exec, with a chain to appear as though the program seamlessly transferred, but in order to allow for user-friendliness, I need the compressor to already know the filename the .hbm was saved under, how do you pass arguments(vars) via Sys.Exec, asnd then how would I retrieve them? I'll be scanning the tutorials section for a while, but seing as I was already going to post, I threw this in. I'll edit it out if I find something. |
Author: | StealthArcher [ Mon Jan 14, 2008 9:45 pm ] | ||
Post subject: | Re: RE:Including via variables? | ||
Okay, sorry for double post, but I have found the way to get args from runtime, but it always makes me type it into the box that pops up, rather than accepting it from my Sys.Exec Command:
Name is a variable I'm attemptting to pass to the other program, I have also attempted passing a plain and quoted string. I'm at a loss. |