Dissection of Hello World in Operon
Hello World is a classic first application that is written when learning new language. Here's the Hello World in Operon:
Let's go through this line by line:
As we can see, the query starts with the word "From". From is a keyword in Operon, and it tells from where we are going to get the data. Please note that the keywords in Operon start with the capital letters, so From has big F in it.
After From comes the input-source, which first in our examples is most of the time "json". You might be familiar with JSON already, but if you are not, then don't worry, you will learn it fast by going through the examples. Here we say that the input is a JSON-string, which has the value "Hello world!".
The From-statement is optional, so you may skip it. In this case the root-value will be an empty-value.
Each query must have the Select-statement. Here we have this dollar-symbol ($) after our Select-keyword. It means that we want to select root value, which means the value that was assigned by our input-source, and in this case it is a JSON-string "Hello world!".
- Finally we have the line which starts with hashtag-symbol, followed by the greater-than -symbol. Everything followed by the hashtag-symbol means that it is a comment. This is how we denote the query's output while going through examples.
There's more than one way to do it
The above example is the canonical way to write the Hello World, but there are other ways to achieve this. Let's see a few alternatives.
Where to go next?
Check out next Operon 1-2-3 - first steps to learn Operon!
To run these examples, download the Operon-executable, make sure it is executable (chmod +x operon)
and you are good to go (nothing needs to be installed).
The fastest way to try small snippets of code is to use the --query (or -q) -option, .e.g. in the shell: ./operon -q 'Select "Hello!"'. Just make sure to fit the code in one line.
To place the query into file, then running it is as simple as starting with: ./operon queryfilename.op. The file suffix doesn't have to be .op, but is a convention used in this site.
Run command "./operon --help" to see the options.