|<< 2 Installing Euphoria||< 3.1 Example Programs||Up: 3 Using Euphoria||3.3 Editing a Program >||4 Language Reference >>|
3.2 Creating Euphoria programs
Euphoria programs can be written with any plain text editor. As a convenience Euphoria comes with edx, an editor written in Euphoria, that is handy for editing and executing Euphoria programs. Take a look at \euphoria\demo and euphoria\tutorial to see many example programs.
3.2.1 Running a Program
To run a Euphoria program you type the name of the interpreter followed by the filename of the program you want to run. Such as:
What you just typed is known as the command-line.
Depending on the platform you are using the interpreter could be called:
|eui||General interpreter on Windows and Unix variants|
|euiw||Console-less Windows interpreter|
The command-line may contain extra information. Following your program filename you may add extra words (known as arguments) that can used in your program to customize its behavior. These arguments are read within your program by the built-in function command_line.
Optionally, you may also use command line switches that are typed between the interpreter name and the program name. Command line switches customize how the interpreter itself behaves.
Unlike many other compilers and interpreters, there is no obligation for any special command-line options for eui or euiw. Only the name of you Euphoria file is expected, and if you do not supply it, Euphoria will display all the command line options available.
Euphoria doesn't care about your choice of file extensions. By convention, however, console-based applications have an extension of .ex, GUI-based applications have an extension of .exw and include files have an extension of .e. Note that a GUI application is not necessarily a Windows program. A GUI application can exist on Linux, OS X, FreeBSD, and so on.
You can redirect standard input and standard output when you run a Euphoria program, for example:
eui filesort.ex < raw.txt > sorted.txt
eui filesort < raw.txt > sorted.txt
For frequently-used programs under Windows you might want to make a small .bat (batch) file, perhaps called myprog.bat, containing two statements like:
@echo off eui myprog.ex %1 %2 %3 %4 %5 %6 %7 %8 %9
The first statement turns off echoing of commands to the screen. The second runs eui myprog.ex with up to 9 command-line arguments. See command_line for an example of how to read these arguments. Having a .bat file will save you the minor inconvenience of typing eui all the time; for example you can just type:
Under modern Unix variants, you can use #!/usr/bin/env eui as the first line of your script file. On older Unix variants, you may need to use the full path to eui, #!/usr/local/bin/eui.
If your program is called foo.ex:
#!/usr/bin/env eui procedure foo() ? 2+2 end procedure foo()
Then if you make your file executable:
chmod +x foo.ex
You can just type:
to run your program. You could even shorten the name to simply "foo". Euphoria ignores the first line when it starts with #!. Be careful though that your first line ends with the Unix-style \n, and not the Windows-style \r\n, or the unix shell might get confused. If your file is shrouded, you must give the path to eub, not eui.
You can also run bind to combine your Euphoria program with the eui interpreter, to make a stand-alone executable file. With a stand-alone executable, you can redirect standard input and output. Binding is discussed further in Distributing a Program.
Using the Euphoria To C Translator, you can also make a stand-alone executable file, and it will normally run much faster than a bound program.
3.2.2 Running under Windows
You can run Euphoria programs directly from the Windows environment, or from a console shell that you have opened from Windows. By "associating" .ex files with eui.exe and .exw files with euiw.exe. You will then be able to double click a Euphoria source file to run it. The installer will perform this operation for you, if you wish.