The Fabl Manual
Function Index
Class Index
Globals Index
Libraries
Contents

Title Page
Introduction
Sample Code
Architecture
Syntax
Strong Typing
Polymorphism
Operators
Help
Errors
Configuration
RDF
Namespaces
Owl
Datatypes
Resources
Dot ops
Coercion
Type Casting
nil

Types
string
id
int
double
boolean
Literal
Containers
Functions
void

Home
Regarding
The Path
Classes
Delegation
Functional Values
Read/Write
Load/Store
Libraries
Imports
CGI
Containers

Fabl introduces two kinds of parametric types which are not found in OWL: container types, and function types. Container types are described in this section. The container types are subclasses of the three container classes defined in RDF: rdf:Seq, rdf:Bag, and rdf:Alt.

For any Fabl type <Type>, SeqOf(<Type>) (resp BagOf(<Type>), AltOf(<Type>)) is the type of sequences (resp bags, alts) whose elements belong to <Type>. Sequences, Bags, and Alts behave identically in Fabl - only their intended meaning is different. (See the RDF documentation on containers). Sequences can be given by enclosing their members in brackets. For example.

var someIds = ['aa','bb','cc'];
someIds;
-->[aa,bb,cc]

The types of the bracketed expressions must match, so that for example,

[1,'a'];

will generate an error. However, since all data can be cast to Resource (see the section on type casting), this is not a limitation on the content of sequences, only on the expressions used to construct them.

[1~ob,'a'~ob]

is perfectly legal.

Bags and Alts are generated by expressions of the form bag(elt0,elt1 ... eltn) or alt(elt0,elt1 ... eltn) respectively. Example:

var bagOfInts = bag(1,2,3);

As for sequences, the types of elements must match.

To access elements of a container by index, conventional syntax is used, as illustrated by:


someIds[1];
-->bb
someIds[1] = 'abc';
someIds;
-->[aa,abc,cc]

Note that sequence selection is zero-based: s[0] is equivalent to s.rdf:_1

The following operations are available for all container types <tp>:

<tp> function new(Type <tp>)

returns an empty container of the given type tp. For example

new(SeqOf(int));

returns an empty sequence of ints.(new also manufactures new elements of OWL classes.)

<Type> function plus(<Type> x,<Type> y)

concatenates x and y of the same container type <Type>. As always, the operator + is equivalent to plus. Thus, for example:

[1,2,3] + [10,20,30] + [100];
-->[1,2,3,10,20,30,100]

plus does not modify its inputs, but, as for strings, times does.

<Type> function times(<Type> x,<Type> y)

adds the elements of y onto the end of x, and returns x. As always, the operator * is equivalent to times. Thus, for example:

var ss = [2,3,4];
-->[2,3,4,5,6]
ss * [5,6];
ss;
-->[2,3,4,5,6]

The following functions:

SeqOf(<Type>) function push(SeqOf(<Type>) x,<Type> y)

BagOf(<Type>) function push(BagOf(<Type>) x,<Type> y)

AltOf(<Type>) function push(AltOf(<Type>) x,<Type> y)

add y onto the end of x. For example:

var ss = [1,2];
push(ss,3);
->[1,2,3]
ss;
->[1,2,3]

void function reset(<Type> s)

resets the container s to zero length.

int function length(<Type> s)

returns the length of the container.