![]() |
Qore Programming Language Reference Manual 1.12.3
|
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):
Expressions
| Type | Description | Examples |
| An immediate value | Qore values that can be expressed directly (see Basic Data Types and Container Data Types for more information) | True
1.2
"a string"
2005-10-27
NULL
NOTHING
("key" : val)
|
| A variable reference | Variables see also %allow-bare-refs | var
|
| A variable declaration | Variable Declarations and Lexical Scope, Variables see also %assume-local and %new-style | 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" | member
|
| An lvalue assignment | Assigns a value to a lvalue (see Assignment Operator (=)) | var = 1
(a, b, c, date) = (1, "two", 3.3, 2005-10-28)
|
| A function call | Qore function calls (see Functions) | calculate(var1, var2, "string", 4)
|
| A method call | Qore object method calls (see Object Method Calls) see also %allow-bare-refs | object.method("argument")
|
| An in-class method call | Qore in-class object method calls (see Object Method Calls) see also %allow-bare-refs | method("argument")
|
| A static method call | Qore static method calls (see static_methods) | ClassName::static_method("argument")
|
| Expressions with operators | Use of Qore operators | 1 + 2
a || b
background my_function()
|
| An expression in parentheses | Use of parentheses for clarity or to specify evaluation precedence | (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 | 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 | %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 | %%
|
| 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 | \function_call()
\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 | string sub (string a) { return a + b; }
|
| A call reference call | An expression executing a call reference or closure | my_closure(arg1, arg2)
|
An implicit argument reference ($1) | References an implicit argument | $1
|
A reference to the entire implicit argument list ($$) | References the implicit argument list | $$
|
| An implicit index reference | Gives the list index position when implicitly iterating a list | $#
|
([argument_expressions...])where expression is True, it will evaluate and return a result expression."%" character (as with context statements).find result_expression in data_expression where (where_expression)\function_name()\class::static_method()\object.method()\ function_name ()\ class :: static_method ()\ object . method ()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.OBJECT-ALREADY-DELETED exception to be thrown.sub ([[type] variable1, ...]) { [code] }returns keyword after the parameters:sub ([ [type] variable1, ...]) returns return_type { [code] }self and $.member from within closures created from objects) and additionally prolongs the scope of the object for the lifetime of the closure.$int (for a single implicit argument; int is the argument number, where 1 is the first argument)$$ (for the entire implicit argument list)$) 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.$#.$#$#) can be used whenever a list is iterated implicitly, such as with foreach statements and the map, foldl, foldr, and select operators.