Subsections


Miscellenaous Expressions

A few OQL operators cannot be easily classified in one of the previous categories. We choose to classify them in the miscellenaous operators. These operators are: bodyof, structof, [!] and import.

bodyof operator

The bodyof operaror is used to get the body of an OQL function. For instance, let the function fib: define fib(n) as (n < 2 ? n : fib(n-2) + fib(n-1)). The expression bodyof fib will return: "fib(n) ((n<2)?n:(fib((n-2))+fib((n-1))))". This operator could be applied to expression-functions (i.e. functions defined with the define/as operator) or statement-functions (i.e. functions defined with the function operator).
General Information
Operator bodyof
Syntax classof expr
Type unary
Operand Type ident denoting a function
Result Type string
Function returns the body of the function

Expression Examples
bodyof is_int "is_int(x) ((typeof x)=="integer")"
bodyof first "first(l) { if (((!is_list(l))&&(!is_array(l)))) return l; start:=0; f:=nil; for (x in l) if ((start==0)) { start:=1; f:=x; break; }; ; return f; }"
bodyof 1 raises an error

structof operator

The structof is used to get the meta-type of a struct atom. The meta-type of a struct atom is the list of the attributes of this struct. For instance, the meta-type of struct(a : 1, b : "hello") is the list composed of the two attribute a and b. The following expression structof struct(a : 1, b : "hello") returns list("a", "b").
General Information
Operator structof
Syntax structof expr
Type unary
Operand Type struct
Result Type a list of strings
Function returns the meta-type of the operand

Expression Examples
structof struct(alpha : 1, beta : 2) list("alpha", "beta")
structof first(select struct(x: x.firstname) from Person x) list("x")
structof 1 raises an error

[!] operator

The [!] is used to get the length (or size) of an ordered or unordered collection, a string or a struct. For instance, "hello"[!] returns 5, while list(1, 2, 3)[!] returns 3. Note that this operator is far more efficient than the strlen library function.
General Information
Operator [!]
Syntax expr [!]
Type unary
Operand Type string, collection or struct
Result Type a int
Function returns length of the operand

Expression Examples
(select Person)[!] the number of person instances
(struct(a: 1, b:2, c: "hello"))[!] 3
("hello"+"world")[!] 10
"hello"+"world"[!] raises an error

import operator

The import operator is used to import an OQL file in the current OQL session. Its operand is a string which denote the absolute path (i.e. beginning with a /) or relative path (i.e. not beginning with a /) of the file to import. When the path is relative, the OQL interpreter will look in every directories pointed by the EYEDB configuration variable oqlpath. By default, oqlpath is equal to %root%/etc/oql. If the file name has no .oql extension, the OQL interpreter will automatically adds one.
General Information
Operator import
Syntax import expr
Type unary
Operand Type string
Result Type a string
Function import the file

Expression Examples
import "stdlib" "/usr/local/eyedb/etc/so/stdlib.oql"
import "roudoudou" raises an error: cannot find file 'roudoudou'

EyeDB manual