Commands
Every computer language has two components: Commands and Data. Commands tell the computer what to do with data (including either manipulating data or outputting data). For instance, in our first program, we commanded the PC to print (the command) the result of adding (another command) two numbers (the data). We're going to look at the print command more closely.
There's no point in programming a computer if we're not going to get something out of it; namely, output. We give a computer input and expect some kind of result to be displayed for us, similar to the way our first program showed us the result of the addition of two numbers. In Euphoria, when we want to see the output displayed on the screen, we can use one of a few output commands.
| Output Command | Example Use |
| puts() | puts(1,"Hello, world!") |
| print() | print(1, 3 + 7) |
| ? | ?10+44 |
The puts() command is short for "output sequence." We'll get into sequences later when we consider the data portion of input. For now, just get it in your head that puts() means "output sequence."
The ? is actually short hand for the print(1,…) command. The '1' in the puts() and print() commands above tell the PC to output the result to the monitor screen. So, the following statements are equivalent:
print( 1 , 2 + 3 )
? 2 + 3
The reason we need to specify where to direct output is because the PC can not only "print" to the screen, it can also print to a file (disk) or to a printer.
Let's run our first program again. Type at the command line:
eui add.ex
This command tells your computer to use the program called "eui" to interpret the input found in the file "add.ex." "eui" is, of course, the Euphoria interpreter!
After running our program, we should get this on the screen:
1316863
We have commanded the PC to print to the screen the sum of our two numbers. Euphoria took our commands and converted them into language that the computer would understand. The computer then did what we told it to do.
You can run this program anytime and you will get the exact same results each time. By saving the set of commands, we make code reusable. This is very important, especially when you have programs that are tens of thousands of lines long. Not having to type the same commands each time you need output is a big time saver.
You might be asking, "What if I want to add two different numbers? What if I want to subtract numbers? Or multiply them? Or divide them?" Well, just hold on. We'll get to that later. Right now we're trying to get some basics in our head, okay? Onward...