A flow-function is a recognition of the fact that in programming, different structures of control flow are often strongly related to specific classes of function. For instance, the if-then-else construct (known as a conditional) is often affiliated with testing or comparing values.
In OBYX, we have tied the flow structure with the functions that commonly occur with them, by declaring the specific function that controls the flow as the 'operation' attribute of each of the language's four flow-functions.
In general, "hello world" is simple enough such that people who have no previous experience with computer programming can easily understand it, especially with the guidance of a text or teacher. Using this simple program as a basis, elements of a specific programming language can be explained to novice programmers. Experienced programmers learning new languages can also gain a lot of information about a given language's syntax and structure from a "hello world" program.
To run this simple program just copy and paste the following code into your favourite editor and save it as "hello.obyx", place it on your server, the page should show a "hello world" line on your browser.
<?xml version="1.0" encoding="utf-8"?> <instruction operation="assign" xmlns="http://www.obyx.org" > <output space="immediate" /> <input space="immediate">hello world</input> </instruction>
<?xml version="1.0" encoding="utf-8"?>
As you probably can tell by now, OBYX is written using XML syntax. The XML definition is used to define the document as part of XML family.
<instruction operation="assign" xmlns="http://www.obyx.org" > [...] </instruction>
Being XML, each OBYX document must have a single element as it's root which, for Obyx, should indicate the "http://www.obyx.org" namespace as an xmlns attribute. The xmlns attribute is used to tell the XML parser that the XML contained in the file is controlled by the OBYX schema. OBYX allows for one of four root elements, which we will look into later, and one of these is the "instruction" element.
The instruction element in OBYX is what we call a "flow-function" (see the margin note for an explanation). The instruction flow-function invokes it's operation sequentially over it's inputs. The operation being used within this program is the "assign" operation, which simply moves the input value into the output.
<output space="immediate" />
For all flow-functions, we declare the outputs first, and then the inputs. Both outputs and inputs are also elements, and these elements must be contained within a flow-function.
There is one output in this program - which has an attribute "space" having the value "immediate". This means that the value should be passed on by the instruction to the containing input, or to the console if the instruction is the root element, which is the case here.
<input space="immediate">hello world</input>
There is likewise one input for "assign" operations - here we can see that input has a "space" attribute which is also "immediate". This indicates that it should use the contents of the element as being the actual value to be used for the input.
The value ("hello world") of the input will be moved to the "immediate" output of the instruction - which, being the document root, is the console.
"Syntactic sugar" is a term for additions to the syntax of a computer language that do not affect its functionality but make it "sweeter" for humans to use. OBYX uses defaults to provide some syntactic sugar. (The term "default" in programming means a preselected value adopted by the software when no alternative is specified by the programmer.)
Each of the inputs, outputs and flow-functions of OBYX have very common attribute uses - for instance, the instruction element is most often used for an "assign" operation, and likewise the input and outputs will most often use an "immediate" type. OBYX recognizes this by making them default.
Therefore the hello world program can be rewritten as
<?xml version="1.0" encoding="utf-8"?> <instruction xmlns="http://www.obyx.org" > <output/> <input>hello world</input> </instruction>
It's more usual for there to be the need of a single output than for there to be no output at all, so for flow-functions, a single immediate output is also the default, and therefore we don't need to include the output at all in this case.
<?xml version="1.0" encoding="utf-8"?> <instruction xmlns="http://www.obyx.org" > <input>hello world</input> </instruction>
Also, the value of input and output elements may be written as an attribute (as long as it remains legal XML!), and this is done using the "value" attribute.
<?xml version="1.0" encoding="utf-8"?> <instruction xmlns="http://www.obyx.org" > <input value="hello world" /> </instruction>
All of the listings so far are programmatically identical. Much potential verbosity of OBYX can be avoided by relying upon the defaults defined by the language.
By the end of this tutorial you should have knowledge about the following concepts:
Understanding these basic concepts are essential to OBYX programming. Spend time experimenting with each of the examples and ensure you understand why each of the elements are used.