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:
The query starts with the dollar-sign "$", which tells that we are assigning an input for the query. The input will become root-value, which can be refered with $ in the Select-statement.
After $ 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!".
Assigning an input ($) is optional, so we may skip it. When omitted, the root-value will be an empty-value.
Each query must have the Select-statement. Here we have again the dollar-symbol ($) after our Select-keyword, which means that we want to select root value, which was the value assigned by our input-source, in this case 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 verbose way to write the Hello World, but there are other ways to achieve this. Let's see a few alternatives.
This is the form that we normally would use when working with Operon.
We can of course just select what we want because there's no need for input in this example.
This is like previous, but shorter form.
We can also select the value with `-quotes. In this case the output is not a JSON-string, but a sequence of bytes.
Where to go next?
Check out next Operon 1-2-3 - first steps to learn Operon!
To run these examples, download the Operon-executable, uncompress it (
tar -xvf operon.tar.gz), make sure it is executable with
chmod +x operon
and you are good to go (nothing needs to be installed).
We recommend that you make alias for operon:
this makes it nicer to run the command.
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:
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.