Qore Programming Language Reference Manual
 All Classes Namespaces Functions Variables Groups Pages

An expression can be any of the following (note that expressions are also recursively defined; also note that all examples are given in %new-style):


Type Description Examples
An immediate value Qore values that can be expressed directly (see Basic Data Types and Container Data Types for more information)
1 True
1 1.2
1 "a string"
1 2005-10-27
1 ("key" : val)
A variable reference Variables
see also %allow-bare-refs
1 var
A variable declaration Variable Declarations and Lexical Scope, Variables
see also %assume-local and %new-style
1 int var
An in-class object member reference References to members of an object from within the class
see Class Members also allow-bare-refs "%allow-bare-refs"
1 member
An lvalue assignment Assigns a value to a lvalue (see Assignment Operator (=))
1 var = 1
1 (a, b, c, date) = (1, "two", 3.3, 2005-10-28)
A function call Qore function calls (see Functions)
1 calculate(var1, var2, "string", 4)
A method call Qore object method calls (see Object Method Calls)
see also %allow-bare-refs
1 object.method("argument")
An in-class method call Qore in-class object method calls (see Object Method Calls)
see also %allow-bare-refs
1 method("argument")
A static method call Qore static method calls (see static_methods)
1 ClassName::static_method("argument")
Expressions with operators Use of Qore operators
1 1 + 2
1 a || b
1 background my_function()
An expression in parentheses Use of parentheses for clarity or to specify evaluation precedence
1 (3 * (2 + a))
A find expression Finds a value or values in a hash of lists, such as returned by the Qore::SQL::Datasource::select() or Qore::SQL::SQLStatement::fetchColumns() method
1 find %name, %id in data where (%name =~ /Smith/)
A context reference (name) A contextual reference to the value of a key of the current row being iterated by a context, summarize, subcontext statement, or a find expression
1 %name
A context row reference (%%) A contextual reference to the current row being iterated by a context, summarize, subcontext statement, or a find expression; this expression returns a hash of the current row
1 %%
A call reference A reference to a function or object method call (similar to a function pointer in C or C++). Function references are resolved in the second phase of parsing (commit phase), while object method references are resolved at run-time
1 \function_call()
1 \object_expression.method_name()
A closure An anonymous function used a value; technically a closure must have at least one bound variable, but in Qore a closure is any function used as a value, whether or not it encloses local variables from the scope in which it was created or not
1 string sub (string a) { return a + b; }
A call reference call An expression executing a call reference or closure
1 my_closure(arg1, arg2)
An implicit argument reference ($1) References an implicit argument
1 $1
A reference to the entire implicit argument list ($$) References the implicit argument list
1 $$
An implicit index reference Gives the list index position when implicitly iterating a list
1 $#

Static Method Calls

Calls to static class methods are made by giving the class name followed by two colons and then the method name. The method name must be implemented and accessible (i.e. not private and accessed outside the class) somewhere within the class hierarchy and must be static or a parse exception will occur.
class_name::method_name ([argument_expressions...])
The name of the class implementing the static method.

The name of the static method to call.

Expressions passing arguments to the static method.
1 TimeZone::setRegion("Europe/Prague");

Find Expressions

The find expression can be used to quickly find data in a hash of lists (such as a query result set returned by the Qore::SQL::Datasource::select() or Qore::SQL::SQLStatement::fetchColumns() methods). The find expression will loop through a data structure, and for each element in the structure where the where expression is True, it will evaluate and return a result expression.

If the where_expression only is True for one element in the list, it will return the result of evaluating the result expression directly, otherwise if the where_expression is True more than once, then a list of the results of evaluting the result expression for each element is returned.

In each expression in the find expression, column values can be referred to by preceding the name with a "%" character (as with context statements).
find result_expression in data_expression where (where_expression)
This expression will be evaluated and returned when the where_expression evaluates to True.

This expression must evaluate to a hash of lists, so that the internal context can be set up for the find loop.

This expression will be evaluated for each row in the data_expression. Each time it evaluates to True, the result_expression will be evaulated and used for the return value for the find expression.
1 rlist = find %fname, %id in data where (%lname =~ /^Smith/);
See Also
  • context
  • summarize
  • subcontext

Call References

References to functions or object methods are called call references. A call reference can be used like a function pointer; a call reference is a Qore data type that can be returned by functions or methods or assigned to variables.

Note that the empty parentheses after the call are required to identify the expression as a call reference.
\ function_name ()
This makes a call reference to a function. Call references to functions are resolved at parse time; if the function does not exist a parse exception will be thrown.

\ class :: static_method ()
This makes a call reference to a static method. Call references to static methods are resolved at parse time; if the static method does not exist a parse exception will be thrown.

\ object . method ()
  • object: can be any valid Qore expression that evaluates to an object
  • method: must be an unquoted string (see example below) and must represent a valid method name of the object's class.
This makes a call reference to an object method call, binding the object and the method in the call reference. Call references to object methods are executed and resolved at run time; if the object expression does not evaluate to an object at run-time, an OBJECT-METHOD-REFERENCE-ERROR exception will be thrown. If the method does not exist, a METHOD-DOES-NOT-EXIST run-time exception will be thrown.

When called, a call reference to an object method will be executed in the context of the object originally referenced. Object method call references do not prolong the lifetime of an object; if the object is deleted (for example, by going out of scope), then if called the call reference will cause an OBJECT-ALREADY-DELETED exception to be thrown.
1 code c = \printf();
1 code c = \MyClass::method();
1 code c = \obj.method();
  • The backslash at the beginning and the empty parentheses at the end; these are required when specifying a call reference.
  • call reference is a code data type; see Call Reference Type for more information


A closure is an anonymous function used as a value. Closures can be returned from functions or methods, assigned to variables, or passed as arguments to other functions.
[return_type] sub ([[type] variable1, ...]) { [code] }

or the alternate (deprecated) syntax with the returns keyword after the parameters:

sub ([ [type] variable1, ...]) returns return_type { [code] }
Closures encapsulate the state and value of local variables of the outer code block referenced from within the closure when the closure is created. Whenever local variables are bound within a closure, these variables are subject to concurrent thread access protection (locking) just as with global variables, in order to allow closures to be used in any context without restriction and to preseve thread-safety regarding bound local variables.

Note that returning a closure from within an object method encapsulates the state of the object as well (it's legal to refer to self and $.member from within closures created from objects) and additionally prolongs the scope of the object for the lifetime of the closure.

Note that parameter and return types are required when the Qore::PO_REQUIRE_TYPES or Qore::PO_REQUIRE_PROTOTYPES parse options are set.
1 # if b is a local variable in the function where the closure is created
2 # then b will be bound to the closure when the closure is created
3 code closure = int sub (int a) { return a + b; };
closure is a code data type; see Closure Type for more information

Implicit Argument References

Implicit arguments are arguments not captured by parameter variables as well as automatic arguments in list-processing operator expressions. A special syntax to reference these arguments is documented here.
$int (for a single implicit argument; int is the argument number, where 1 is the first argument)
$$ (for the entire implicit argument list)
Implicit arguments can be directly referenced using the dollar sign ($) and either a number from 1 onwards (giving the position in the argument list, where 1 is the first element) or a double dollar sign ($$) giving the entire implicit argument list.

For unassigned arguments to functions or methods, this syntax supplements the automatic argv variable holding all function arguments not assigned to parameter variables.

This syntax is particularly useful when writing expressions for the map, foldl, foldr, and select operators, where implicit argument references are the only way the operator expressions can reference the current list values that are populated as implicit arguments as the operators traverse the list.
1 # extract a list of even numbers from a list
2 list l = select list, !($1 % 2);

Implicit Index

The current list index position when implicitly iterating through lists can be referenced using the implicit index reference characters: $#.
The implicit index reference expression ($#) can be used whenever a list is iterated implicitly, such as with foreach statements and the map, foldl, foldr, and select operators.
1 # create a list of indexes with negative values
2 list l = map $#, list, ($1 < 0);