3.2 Creating Euphoria programs

Euphoria programs can be written with any plain text editor. As a convenience Euphoria comes with ed, 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:

eui exampleex

What you just typed is known as the command-line.

Depending on the platform you are using the interpreter could be called:

Executable Purpose
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 don't 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, etc...

You can redirect standard input and standard output when you run a Euphoria program, for example:

eui filesortex < rawtxt > sortedtxt

or simply,

eui filesort < rawtxt > sortedtxt

For frequently-used programs under Windows you might want to make a small .bat (batch) file, perhaps called myprog.bat, containing two statements like:

eui myprogex 

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; i.e., you can just type:

myprog

instead of:

eui myprog

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 fooex

You can just type:

fooex

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.