Lessons/Output arguments

In the lesson we created a function, i.e. a predicate that retruned a value. Here we will look at output parameters, which is another way to let data flow outwards.

The first thing to notice here is the use of [out] in the predicate declaration, this "mark" indicates that the corresponding argument is an output argument rather than an input argument.

In the clause we still have a "position" corresponding to that argument, but this time we have to "calculate" and return a value. So in the clause above Date and Time does not have a value when the body starts to execute, it is our responsibility to create bind values to these variables.

In the clause body we call the function now on the class time this function returns a time object that represents the time the function was called. Here we will not go into details about objects, but the next two lines of code shows that objects have predicates associated with them and that these are referenced these using a single colon:  : .

A time object represents a time and date, and in the last two lines we "request" the date using the short format and the time formatted as a string. What exactly these functions does depends on the users settings on the computer (i.e. the users locale settings).

Sometimes you will accidentally use a single colon where you intended to use two and vice versa:

Output arguments can also be used in functions, and together with input arguments.

Summary:


 * Output arguments are declared using the [out] attribute.
 * An output argument is unbound when the clause  </vp> is entered and must be bound when the predicate returns.
 * There is something called objects.
 * Objects are values that can be passed around and held in variables.
 * Objects have predicates associated and these are referenced with single colon:  : </vp> (predicates in classes are referenced using a double-colon).