An expression can be any of the following (note that expressions are also recursively defined; also note that all examples are given in \hyperlink{parse_directives_new-style}{\%new-\/style})\+:

{\bfseries Expressions}  \tabulinesep=1mm
\begin{longtabu} spread 0pt [c]{*{3}{|X[-1]}|}
\hline
{\bfseries Type} &{\bfseries Description} &{\bfseries Examples}  \\\cline{1-3}
An immediate value &\hyperlink{namespace_qore}{Qore} values that can be expressed directly (see \hyperlink{basic_data_types}{Basic Data Types} and \hyperlink{container_data_types}{Container Data Types} for more information) &
\begin{DoxyCode}
\textcolor{keyword}{True}
\end{DoxyCode}

\begin{DoxyCode}
1.2
\end{DoxyCode}

\begin{DoxyCode}
\textcolor{stringliteral}{"a string"}
\end{DoxyCode}

\begin{DoxyCode}
2005-10-27
\end{DoxyCode}

\begin{DoxyCode}
NULL
\end{DoxyCode}

\begin{DoxyCode}
NOTHING
\end{DoxyCode}

\begin{DoxyCode}
(\textcolor{stringliteral}{"key"} : val)
\end{DoxyCode}
  \\\cline{1-3}
A variable reference &\hyperlink{variables}{Variables} ~\newline
see also \hyperlink{parse_directives_allow-bare-refs}{\%allow-\/bare-\/refs} &
\begin{DoxyCode}
var
\end{DoxyCode}
  \\\cline{1-3}
A variable declaration &\hyperlink{variables_variable_declarations}{Variable Declarations and Lexical Scope}, \hyperlink{variables}{Variables} ~\newline
see also \hyperlink{parse_directives_assume-local}{\%assume-\/local} and \hyperlink{parse_directives_new-style}{\%new-\/style} &
\begin{DoxyCode}
int var
\end{DoxyCode}
  \\\cline{1-3}
An in-\/class object member reference &References to members of an object from within the class~\newline
see \hyperlink{qore_classes_class_members}{Class Members} also allow-\/bare-\/refs \char`\"{}\%allow-\/bare-\/refs\char`\"{} &
\begin{DoxyCode}
member
\end{DoxyCode}
  \\\cline{1-3}
An lvalue assignment &Assigns a value to a lvalue (see \hyperlink{operators_assignment_operator}{Assignment Operator (=)}) &
\begin{DoxyCode}
var = 1
\end{DoxyCode}

\begin{DoxyCode}
(a, b, c, date) = (1, \textcolor{stringliteral}{"two"}, 3.3, 2005-10-28)
\end{DoxyCode}
  \\\cline{1-3}
A function call &\hyperlink{namespace_qore}{Qore} function calls (see \hyperlink{qore_functions}{Functions}) &
\begin{DoxyCode}
calculate(var1, var2, \textcolor{stringliteral}{"string"}, 4)
\end{DoxyCode}
  \\\cline{1-3}
A method call &\hyperlink{namespace_qore}{Qore} object method calls (see \hyperlink{qore_classes_object_method_calls}{Object Method Calls})~\newline
see also \hyperlink{parse_directives_allow-bare-refs}{\%allow-\/bare-\/refs} &
\begin{DoxyCode}
object.method(\textcolor{stringliteral}{"argument"})
\end{DoxyCode}
  \\\cline{1-3}
An in-\/class method call &\hyperlink{namespace_qore}{Qore} in-\/class object method calls (see \hyperlink{qore_classes_object_method_calls}{Object Method Calls})~\newline
see also \hyperlink{parse_directives_allow-bare-refs}{\%allow-\/bare-\/refs} &
\begin{DoxyCode}
method(\textcolor{stringliteral}{"argument"})
\end{DoxyCode}
  \\\cline{1-3}
A \hyperlink{expressions_static_method_calls}{static method call} &\hyperlink{namespace_qore}{Qore} static method calls (see \hyperlink{qore_classes_static_methods}{static\+\_\+methods}) &
\begin{DoxyCode}
ClassName::static\_method(\textcolor{stringliteral}{"argument"})
\end{DoxyCode}
  \\\cline{1-3}
Expressions with operators &Use of \hyperlink{operators}{Qore operators} &
\begin{DoxyCode}
1 + 2
\end{DoxyCode}

\begin{DoxyCode}
a || b
\end{DoxyCode}

\begin{DoxyCode}
background my\_function()
\end{DoxyCode}
  \\\cline{1-3}
An expression in parentheses &Use of parentheses for clarity or to specify evaluation precedence &
\begin{DoxyCode}
(3 * (2 + a))
\end{DoxyCode}
  \\\cline{1-3}
A \hyperlink{expressions_find}{find expression} &Finds a value or values in a hash of lists, such as returned by the \hyperlink{class_qore_1_1_s_q_l_1_1_datasource_a05b1d0d126d815b2d7578e5ce8b9a0de}{Qore\+::\+S\+Q\+L\+::\+Datasource\+::select()} or \hyperlink{class_qore_1_1_s_q_l_1_1_s_q_l_statement_ab889448c79985fc26e41b7e2086308df}{Qore\+::\+S\+Q\+L\+::\+S\+Q\+L\+Statement\+::fetch\+Columns()} method &
\begin{DoxyCode}
find %name, %id \textcolor{keywordflow}{in} data where (%name =~ /Smith/)
\end{DoxyCode}
  \\\cline{1-3}
A context reference ({\ttfamily name}) &A contextual reference to the value of a key of the current row being iterated by a \hyperlink{statements_context}{context}, \hyperlink{statements_summarize}{summarize}, \hyperlink{statements_subcontext}{subcontext} statement, or a \hyperlink{expressions_find}{find expression} &
\begin{DoxyCode}
%name
\end{DoxyCode}
  \\\cline{1-3}
A context row reference ({\ttfamily \%\%}) &A contextual reference to the current row being iterated by a \hyperlink{statements_context}{context}, \hyperlink{statements_summarize}{summarize}, \hyperlink{statements_subcontext}{subcontext} statement, or a \hyperlink{expressions_find}{find expression}; this expression returns a hash of the current row &
\begin{DoxyCode}
%%
\end{DoxyCode}
  \\\cline{1-3}
A \hyperlink{expressions_call_reference}{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 &
\begin{DoxyCode}
\(\backslash\)function\_call()
\end{DoxyCode}

\begin{DoxyCode}
\(\backslash\)object\_expression.method\_name()
\end{DoxyCode}
  \\\cline{1-3}
A \hyperlink{expressions_closure}{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 &
\begin{DoxyCode}
string sub (string a) \{ \textcolor{keywordflow}{return} a + b; \}
\end{DoxyCode}
  \\\cline{1-3}
A call reference call &An expression executing a \hyperlink{expressions_call_reference}{call reference} or \hyperlink{expressions_closure}{closure} &
\begin{DoxyCode}
my\_closure(arg1, arg2)
\end{DoxyCode}
  \\\cline{1-3}
An \hyperlink{expressions_implicit_arguments}{implicit argument} reference ({\ttfamily \$1}) &References an implicit argument &
\begin{DoxyCode}
$1
\end{DoxyCode}
  \\\cline{1-3}
A reference to the entire \hyperlink{expressions_implicit_arguments}{implicit argument} list ({\ttfamily \$\$}) &References the implicit argument list &
\begin{DoxyCode}
$$
\end{DoxyCode}
  \\\cline{1-3}
An \hyperlink{expressions_implicit_index}{implicit index} reference &Gives the list index position when implicitly iterating a list &
\begin{DoxyCode}
$\textcolor{comment}{#}
\end{DoxyCode}
  \\\cline{1-3}
\end{longtabu}




 \hypertarget{expressions_static_method_calls}{}\section{Static Method Calls}\label{expressions_static_method_calls}
\begin{DoxyParagraph}{Synopsis}
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.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\itshape class\+\_\+name\+::method\+\_\+name} {\ttfamily (}{\itshape \mbox{[}argument\+\_\+expressions...\mbox{]}}{\ttfamily )}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
{\itshape class\+\_\+name} ~\newline
 The name of the class implementing the static method.~\newline
~\newline
 {\itshape method\+\_\+name} ~\newline
 The name of the static method to call.~\newline
~\newline
 {\itshape \mbox{[}argument\+\_\+expressions...\mbox{]}}~\newline
 Expressions passing arguments to the static method.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
TimeZone::setRegion(\textcolor{stringliteral}{"Europe/Prague"});
\end{DoxyCode}

\end{DoxyParagraph}


 \hypertarget{expressions_find}{}\section{Find Expressions}\label{expressions_find}
\begin{DoxyParagraph}{Synopsis}
The find expression can be used to quickly find data in a hash of lists (such as a query result set returned by the \hyperlink{class_qore_1_1_s_q_l_1_1_datasource_a05b1d0d126d815b2d7578e5ce8b9a0de}{Qore\+::\+S\+Q\+L\+::\+Datasource\+::select()} or \hyperlink{class_qore_1_1_s_q_l_1_1_s_q_l_statement_ab889448c79985fc26e41b7e2086308df}{Qore\+::\+S\+Q\+L\+::\+S\+Q\+L\+Statement\+::fetch\+Columns()} methods). The find expression will loop through a data structure, and for each element in the structure where the {\ttfamily where} expression is \hyperlink{basic_data_types_True}{True}, it will evaluate and return a result expression.~\newline
~\newline
 If the {\itshape where\+\_\+expression} only is \hyperlink{basic_data_types_True}{True} for one element in the list, it will return the result of evaluating the result expression directly, otherwise if the {\itshape where\+\_\+expression} is \hyperlink{basic_data_types_True}{True} more than once, then a list of the results of evaluting the result expression for each element is returned.~\newline
~\newline
 In each expression in the find expression, column values can be referred to by preceding the name with a {\ttfamily \char`\"{}\%\char`\"{}} character (as with \hyperlink{statements_context}{context statements}).
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily {\bfseries find}} {\itshape result\+\_\+expression} {\ttfamily {\bfseries in}} {\itshape data\+\_\+expression} {\ttfamily {\bfseries where} (}{\itshape where\+\_\+expression{\ttfamily })}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
{\itshape result\+\_\+expression} ~\newline
 This expression will be evaluated and returned when the {\itshape where\+\_\+expression} evaluates to \hyperlink{basic_data_types_True}{True}.~\newline
~\newline
 {\itshape data\+\_\+expression} ~\newline
 This expression must evaluate to a hash of lists, so that the internal context can be set up for the find loop.~\newline
~\newline
 {\itshape where\+\_\+expression} ~\newline
 This expression will be evaluated for each row in the {\itshape data\+\_\+expression}. Each time it evaluates to \hyperlink{basic_data_types_True}{True}, the {\itshape result\+\_\+expression} will be evaulated and used for the return value for the find expression.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
rlist = find %fname, %id \textcolor{keywordflow}{in} data where (%lname =~ /^Smith/);
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxySeeAlso}{See also}

\begin{DoxyItemize}
\item context
\item summarize
\item subcontext
\end{DoxyItemize}
\end{DoxySeeAlso}


 \hypertarget{expressions_call_reference}{}\section{Call References}\label{expressions_call_reference}
\begin{DoxyParagraph}{Synopsis}
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.~\newline
~\newline
 Note that the empty parentheses after the call are required to identify the expression as a call reference.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily \textbackslash{}}{\itshape function\+\_\+name}{\ttfamily ()}~\newline
 {\ttfamily \textbackslash{}}{\itshape class}{\ttfamily \+:\+:}{\itshape static\+\_\+method}{\ttfamily ()}~\newline
 {\ttfamily \textbackslash{}}{\itshape object.\+method}{\ttfamily ()}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
{\ttfamily \textbackslash{}} {\itshape function\+\_\+name} {\ttfamily ()}~\newline
 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.~\newline
~\newline
 {\ttfamily \textbackslash{}} {\itshape class} {\ttfamily \+:\+:} {\itshape static\+\_\+method} {\ttfamily ()}~\newline
 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.~\newline
~\newline
 {\ttfamily \textbackslash{}} {\itshape object} {\ttfamily .} {\itshape method} {\ttfamily ()}~\newline

\begin{DoxyItemize}
\item {\itshape object\+:} can be any valid Qore expression that evaluates to an object
\item {\itshape method\+:} must be an unquoted string (see example below) and must represent a valid method name of the object\textquotesingle{}s class.
\end{DoxyItemize}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 {\ttfamily O\+B\+J\+E\+C\+T-\/\+M\+E\+T\+H\+O\+D-\/\+R\+E\+F\+E\+R\+E\+N\+C\+E-\/\+E\+R\+R\+OR} exception will be thrown. If the method does not exist, a {\ttfamily M\+E\+T\+H\+O\+D-\/\+D\+O\+E\+S-\/\+N\+O\+T-\/\+E\+X\+I\+ST} run-\/time exception will be thrown.~\newline
~\newline
 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 {\ttfamily O\+B\+J\+E\+C\+T-\/\+A\+L\+R\+E\+A\+D\+Y-\/\+D\+E\+L\+E\+T\+ED} exception to be thrown.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
code c = \(\backslash\)\hyperlink{group__string__functions_ga32070517a9f8a70a32ef48f83a6f128e}{printf}(); 
\end{DoxyCode}
 
\begin{DoxyCode}
code c = \(\backslash\)MyClass::method(); 
\end{DoxyCode}
 
\begin{DoxyCode}
code c = \(\backslash\)obj.method(); 
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxyNote}{Note}

\begin{DoxyItemize}
\item The backslash at the beginning and the empty parentheses at the end; these are required when specifying a call reference.
\item call reference is a code data type; see \hyperlink{code_data_types_callref_type}{Call Reference Type} for more information
\end{DoxyItemize}
\end{DoxyNote}


 \hypertarget{expressions_closure}{}\section{Closures}\label{expressions_closure}
\begin{DoxyParagraph}{Synopsis}
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.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
\mbox{[}{\bfseries \hyperlink{deprecated}{deprecated}}\mbox{]} \mbox{[}{\bfseries \hyperlink{qore_classes_public_inheritance}{public}}\mbox{]} \mbox{[}{\bfseries \hyperlink{threading_synchronized}{synchronized}}\mbox{]} {\itshape \hyperlink{data_type_declarations}{\mbox{[}return\+\_\+type\mbox{]}}} {\ttfamily {\bfseries sub} (\mbox{[}}{\itshape \hyperlink{data_type_declarations}{\mbox{[}type\mbox{]}} variable1}{\ttfamily , ...\mbox{]}) \{} {\itshape \mbox{[}code\mbox{]}} {\ttfamily \}}~\newline
~\newline
 or the alternate (deprecated) syntax with the {\ttfamily returns} keyword after the parameters\+:~\newline
~\newline
 \mbox{[}{\bfseries \hyperlink{deprecated}{deprecated}}\mbox{]} \mbox{[}{\bfseries \hyperlink{qore_classes_public_inheritance}{public}}\mbox{]} \mbox{[}{\bfseries \hyperlink{threading_synchronized}{synchronized}}\mbox{]} {\ttfamily {\bfseries sub} (\mbox{[}} {\itshape \hyperlink{data_type_declarations}{\mbox{[}type\mbox{]}} variable1}{\ttfamily , ...\mbox{]}) {\bfseries returns}} {\itshape \hyperlink{data_type_declarations}{return\+\_\+type}} {\ttfamily \{} {\itshape \mbox{[}code\mbox{]}} {\ttfamily \}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
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.~\newline
~\newline
 Note that returning a closure from within an object method encapsulates the state of the object as well (it\textquotesingle{}s legal to refer to {\ttfamily self} and {\ttfamily \$.}{\itshape member} from within closures created from objects) and additionally prolongs the scope of the object for the lifetime of the closure.~\newline
~\newline
 Note that parameter and return types are required when the \hyperlink{group__parse__options_ga66847391bb96dac88c3fee210720bbb3}{Qore\+::\+P\+O\+\_\+\+R\+E\+Q\+U\+I\+R\+E\+\_\+\+T\+Y\+P\+ES} or \hyperlink{group__parse__options_ga196e048def21cb147b21a4871c4e9b29}{Qore\+::\+P\+O\+\_\+\+R\+E\+Q\+U\+I\+R\+E\+\_\+\+P\+R\+O\+T\+O\+T\+Y\+P\+ES} parse options are set.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
\textcolor{comment}{# if b is a local variable in the function where the closure is created}
\textcolor{comment}{# then b will be bound to the closure when the closure is created}
code closure = int sub (int a) \{ \textcolor{keywordflow}{return} a + b; \};
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxyNote}{Note}
closure is a code data type; see \hyperlink{code_data_types_closure_type}{Closure Type} for more information
\end{DoxyNote}


 \hypertarget{expressions_implicit_arguments}{}\section{Implicit Argument References}\label{expressions_implicit_arguments}
\begin{DoxyParagraph}{Synopsis}
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.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily \$}{\itshape int} (for a single implicit argument; {\itshape int} is the argument number, where {\ttfamily 1} is the first argument)~\newline
 {\ttfamily \$\$} (for the entire implicit argument list)
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
Implicit arguments can be directly referenced using the dollar sign ({\ttfamily \$}) and either a number from {\ttfamily 1} onwards (giving the position in the argument list, where {\ttfamily 1} is the first element) or a double dollar sign ({\ttfamily \$\$}) giving the entire implicit argument list.~\newline
~\newline
 For unassigned arguments to functions or methods, this syntax supplements the automatic argv variable holding all function arguments not assigned to parameter variables.~\newline
~\newline
 This syntax is particularly useful when writing expressions for the \hyperlink{operators_map}{map}, \hyperlink{operators_foldl}{foldl}, \hyperlink{operators_foldr}{foldr}, and \hyperlink{operators_select}{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.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
\textcolor{comment}{# extract a list of even numbers from a list}
list l = select list, !($1 % 2);
\end{DoxyCode}

\end{DoxyParagraph}


 \hypertarget{expressions_implicit_index}{}\section{Implicit Index}\label{expressions_implicit_index}
\begin{DoxyParagraph}{Synopsis}
The current list index position when implicitly iterating through lists can be referenced using the implicit index reference characters\+: {\ttfamily \$\#}.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Syntax}
{\ttfamily \$\#}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Description}
The implicit index reference expression ({\ttfamily \$\#}) can be used whenever a list is iterated implicitly, such as with \hyperlink{statements_foreach}{foreach statements} and the \hyperlink{operators_map}{map}, \hyperlink{operators_foldl}{foldl}, \hyperlink{operators_foldr}{foldr}, and \hyperlink{operators_select}{select} operators.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}
\textcolor{comment}{# create a list of indexes with negative values}
list l = map $\textcolor{comment}{#, list, ($1 < 0);}
\end{DoxyCode}
 
\end{DoxyParagraph}
