{"id":283,"date":"2015-02-22T10:49:47","date_gmt":"2015-02-22T10:49:47","guid":{"rendered":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=283"},"modified":"2017-11-25T18:07:56","modified_gmt":"2017-11-25T18:07:56","slug":"expressions","status":"publish","type":"page","link":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=283","title":{"rendered":"Expressions"},"content":{"rendered":"<ul>\n<li><strong>assignment<\/strong>: $<em>var<\/em><code>=<\/code><em>expr<br \/>\n<\/em>$<em>var<\/em>[<em>expr<\/em><sub>1<\/sub>][<em>expr<\/em><sub>2<\/sub>]&#8230;[<em>expr<sub>n<\/sub><\/em>]<em>=expr<\/em><br \/>\nevaluate <em>expr<\/em> and assign its value <em>val<\/em> to variable $<em>var<\/em>, or to the entry indexed <em>expr<\/em><sub>1<\/sub>, <em>expr<\/em><sub>2<\/sub>, &#8230;, <em>expr<sub>n<\/sub><\/em> in array $<em>var<\/em>.<br \/>\nreturn value <em>val<\/em><br \/>\n<strong>Typing<\/strong>:<\/p>\n<ul>\n<li>Requires: $<em>var<\/em> and <em>expr<\/em> have the same <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a> <em>type<\/em><\/li>\n<li>Yields: result of type <em>type<\/em><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>variables<\/strong> $<em>var<\/em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <code>$<\/code>[<code>A<\/code>&#8211;<code>Za<\/code>&#8211;<code>z_<\/code>][<code>A<\/code>&#8211;<code>Za<\/code>&#8211;<code>z0<\/code>&#8211;<code>9_.<\/code>]*<br \/>\nordinary variables, can be read and assigned to<br \/>\n<a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a> will be inferred automatically<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>array elements<\/strong> $<em>var<\/em>[<em>expr<\/em><sub>1<\/sub>][<em>expr<\/em><sub>2<\/sub>]&#8230;[<em>expr<sub>n<\/sub><\/em>]<br \/>\nwhere\u00a0$<em>var<\/em> holds an <em>n<\/em>-dimensional array<br \/>\nagain, <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a> and dimensionality will be inferred automatically<br \/>\nthe indices <em>expr<\/em><sub>1<\/sub>, <em>expr<\/em><sub>2<\/sub>, &#8230;, <em>expr<sub>n<\/sub><\/em> can have any basic type (<code>int<\/code>, <code>uint<\/code>, <code>str<\/code>, <code>bstr<\/code>, <code>ipv4<\/code>, <code>ipv6<\/code>, etc.), and one can even use indices of different types for the same array<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>logical variables<\/strong> <em>Var<\/em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [<code>A<\/code>&#8211;<code>Z<\/code>][<code>A<\/code>&#8211;<code>Za<\/code>&#8211;<code>z0<\/code>&#8211;<code>9_.<\/code>]*<br \/>\nstart with a capital letter<br \/>\nused in database collections<br \/>\ncan be read but not assigned to<br \/>\n<a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a> will be inferred automatically<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>field names<\/strong> <code>.<\/code><em>module<code>.<\/code><em>field<\/em>\u00a0<\/em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <code>.<\/code>[<code>A<\/code>&#8211;<code>Za<\/code>&#8211;<code>z0<\/code>&#8211;<code>9_<\/code>]+<code>.<\/code>[<code>A<\/code>&#8211;<code>Za<\/code>&#8211;<code>z0<\/code>&#8211;<code>9_.<\/code>]*<em><br \/>\n<\/em><a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a> is given in its respective <a title=\"List of Orchids modules\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=114\">module<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>constants<\/strong>:\n<ul>\n<li><strong>integer constants \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/strong> [<code>0<\/code>&#8211;<code>9<\/code>]+<br \/>\n<a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a>: <code>uint<\/code><\/p>\n<ul>\n<li>integer constants do not start with a sign; if you write <code>-123<\/code>, this will be interpreted as the arithmetic operator <code>-<\/code> applied to the number <code>123<\/code>, resulting in an expression of type <code>int<\/code>, not <code>uint<\/code><\/li>\n<\/ul>\n<\/li>\n<li><strong>floating-point constants \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/strong> ([<code>0<\/code>&#8211;<code>9<\/code>]*\\<code>.<\/code>[<code>0<\/code>&#8211;<code>9<\/code>]+)([<code>eE<\/code>][<code>-+<\/code>]?[<code>0<\/code>&#8211;<code>9<\/code>]+)?<br \/>\n<a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a>: <code>float<\/code><\/p>\n<ul>\n<li>these are really double precision floating-point numbers, equivalent to <code>double<\/code> in C<\/li>\n<\/ul>\n<\/li>\n<li><strong>string constants<\/strong><br \/>\nSee the STRING token on the <a title=\"The Orchids language\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=279\">Orchids language<\/a> page<br \/>\n<a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a>: <code>str<\/code><\/p>\n<ul>\n<li>as in C, writing two or more string constants in succession produces their concatenation; this allows one to write multi-line string constants, notably<br \/>\n<code><\/code><\/li>\n<\/ul>\n<\/li>\n<li><strong>ctime constants<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <code>_CTIME(<\/code><em>integer constant<\/em><code>)<\/code>,<br \/>\nor \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 <code>_CTIME(<\/code><em>string constant<\/em><code>)<\/code><br \/>\n<a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a>: <code>ctime<\/code><\/p>\n<ul>\n<li><code><\/code>the first syntax uses a number of seconds since the epoch (January 1, 1970)<\/li>\n<li>while the second syntax uses a <a title=\"Date formats\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=270\">human-readable date string<\/a><\/li>\n<\/ul>\n<\/li>\n<li><strong>ipv4 constants \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/strong>\u00a0 <code>_IPV4(<\/code><em>string constant<\/em><code>)<\/code><br \/>\n<a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a>: <code>ipv4<\/code><\/p>\n<ul>\n<li>string can be of the form &#8220;<em>aa<\/em><code>.<\/code><em>bb<\/em><code>.<\/code><em>cc<\/em><code>.<\/code><em>dd<\/em>&#8220;, or &#8220;<em>host.subnet.domain<\/em>&#8220;<\/li>\n<\/ul>\n<\/li>\n<li><strong>ipv6 constants\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/strong> <code>_IPV6(<\/code><em>string constant<\/em><code>)<\/code><br \/>\n<a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a>: <code>ipv6<\/code><\/p>\n<ul>\n<li>string can be of the form &#8220;<em>aa<\/em><code>:<\/code><em>bb<\/em><code>:<\/code><em>cc<\/em><code>:<\/code><em>dd<\/em><code>:<\/code><em>ee<\/em><code>:<\/code><em>ff<\/em><code>:<\/code><em>gg<\/em>&#8221; (or any of the usual variants), or &#8220;<em>host.subnet.domain<\/em>&#8220;<\/li>\n<\/ul>\n<\/li>\n<li><strong>timeval constants<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <code>_TIMEVAL(<\/code><em>integer constant<code>,<\/code> integer constant<code><\/code><\/em><code>)<\/code>,<br \/>\nor\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <code>_TIMEVAL(<\/code><em>string constant<code>,<\/code> integer constant<code><\/code><code><\/code><\/em><code>)<\/code><br \/>\n<a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a>: <code>timeval<\/code><\/p>\n<ul>\n<li>the first syntax uses a pair of a number of seconds and a number of microseconds<\/li>\n<li>the second syntax instead specifies the number of seconds as a date, in a <a title=\"Date formats\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=270\">human-readable format<\/a><\/li>\n<\/ul>\n<\/li>\n<li><strong>regexp constants<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <code>_REGEX(<\/code><em>string constant<\/em><code>)<\/code><br \/>\n<a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a>: <code>regex<\/code><\/p>\n<ul>\n<li><code><\/code>actually compiles the given string to a regexp-matching machine,<br \/>\nusable as second argument to operators <code>=~<\/code>, !<code>~<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li><em>expr<sub>1<\/sub><code><\/code> binop <\/em><em>expr<sub>2<\/sub><\/em><code><\/code><br \/>\nwhere <em>binop<\/em> is a binary <a title=\"Operators\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=294\">operator<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li><em>monop expr<\/em><br \/>\nwhere <em>monop<\/em> is a unary <a title=\"Operators\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=294\">operator<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li><em>function<\/em><code>(<\/code><em>expr<sub>1<\/sub><\/em><code>,<\/code> &#8230;<code>,<\/code> <em>expr<sub>n<\/sub><\/em><code>)<\/code><br \/>\nevaluate <em>expr<sub>1<\/sub><\/em><code>,<\/code> &#8230;<code>,<\/code> <em>expr<sub>n<\/sub><\/em>, yielding values <em>val<sub>1<\/sub><\/em><code>,<\/code> &#8230;<code>,<\/code> <em>val<sub>n<\/sub><\/em>, then call <em>function<\/em> on the latter<\/p>\n<ul>\n<li><em>function<\/em> must be one of the Orchids <a title=\"Primitives\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=246\">primitives<\/a>, defined in the core language or in one of the modules<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>synthetic event<\/strong>:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .{<em>field<sub>1<\/sub><\/em><code>=<\/code><em>expr<sub>1<\/sub><\/em><code>,<\/code> &#8230;<code>, <\/code><em>field<sub>n<\/sub><\/em><code>=<\/code><em>expr<sub>n<\/sub><\/em><code>}<\/code><br \/>\ncreate a synthetic event<\/p>\n<ul>\n<li>evaluate <em>expr<sub>1<\/sub><\/em>, &#8230;, <em>expr<sub>n<\/sub><\/em>, yielding values <em>val<sub>1<\/sub><\/em>, &#8230;, <em>val<sub>n <\/sub><\/em>then create an event with bindings <em>field<sub>i<\/sub><\/em><code>=<\/code><em>val<sub>i<\/sub><\/em><\/li>\n<li>fields may appear in duplicate, however stupid that may seem; if two values are mapped to the same field, only the last one will be kept<\/li>\n<li>synthetic events can be posted using <code>inject_event<\/code>, provided the <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=339\"><code>metaevent<\/code><\/a> module is loaded<\/li>\n<li><strong>Typing<\/strong>:\n<ul>\n<li>Requires: each <em>expr<sub>i<\/sub><\/em> is of the <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a> of <em>field<sub>i<\/sub><\/em>, as given in its respective module<\/li>\n<li>Yields: <code>event<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>event enrichment<\/strong>:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <em>expr<\/em> <code>+ .{<\/code><em>field<sub>1<\/sub><\/em><code>=<\/code><em>expr<sub>1<\/sub><\/em><code>,<\/code> &#8230;<code>, <\/code><em>field<sub>n<\/sub><\/em><code>=<\/code><em>expr<sub>n<\/sub><\/em><code>}<\/code><br \/>\ncreate a synthetic event<\/p>\n<ul>\n<li>evaluate <em>expr<\/em> to an event <em>evt<\/em>, evaluate <em>expr<sub>1<\/sub><\/em>, &#8230;, <em>expr<sub>n<\/sub><\/em>, yielding values <em>val<sub>1<\/sub><\/em>, &#8230;, <em>val<sub>n <\/sub><\/em>then append the indicated bindings <em>field<sub>i<\/sub><\/em><code>=<\/code><em>val<sub>i<\/sub><\/em> to <em>evt<\/em><\/li>\n<li>this is non-destructive, and creates a new synthetic event<\/li>\n<li>fields may appear in duplicate, however stupid that may seem; if two values are mapped to the same field, only the last one will be kept; in particular, this allows one to hide field values from <em>evt<\/em> and replace them with new values<\/li>\n<li>synthetic events can be posted using <a title=\"The metaevent module\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=339\"><code>inject_event<\/code><\/a><\/li>\n<li><em>expr<\/em> can be obtained as a previously synthesized event, or using <a title=\"The metaevent module\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=339\"><code>current_event<\/code><\/a><\/li>\n<li><strong>Typing<\/strong>:\n<ul>\n<li>Requires: <em>expr<\/em> <code>: event<\/code><br \/>\neach <em>expr<sub>i<\/sub><\/em> is of the <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a> of <em>field<sub>i<\/sub><\/em>,<br \/>\nas given in its respective module<\/li>\n<li>Yields: <code>event<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>database expressions<\/strong>\n<ul>\n<li>You should understand that all Orchids databases are <em>applicative<\/em> (<em>non-destructive<\/em>): you do not modify a database, add a tuple to a database, delete tuples from a database; instead, you build new databases from old, using the empty database <code>nothing<\/code>, singleton databases, database collections, as well as database unions (<code>+<\/code>) and differences (<code>-<\/code>)<\/li>\n<li><strong>empty database<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <code>nothing<\/code>\n<ul>\n<li>of <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a> <code>db[*]<\/code>, convertible to any actual database type <code>db[<\/code><em>type<\/em><sub>1<\/sub>,&#8230;,<em>type<sub>n<\/sub><\/em><code>]<\/code><\/li>\n<\/ul>\n<\/li>\n<li><strong>singleton database\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/strong><code>{{<\/code><em>expr<sub>1<\/sub><\/em>, &#8230;, <em>expr<sub>n<\/sub><\/em><code>}}<\/code>\n<ul>\n<li>of <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a> <code>db[<\/code><em>type<\/em><sub>1<\/sub>,&#8230;,<em>type<sub>n<\/sub><\/em><code>]<\/code>, where <em>expr<sub>1 <\/sub><\/em> : <em>type<\/em><sub>1<\/sub>, &#8230;, <em>expr<sub>n <\/sub><\/em> : <em>type<sub>n<\/sub><\/em><\/li>\n<li>contains just one tuple<\/li>\n<\/ul>\n<\/li>\n<li><strong>database collection<\/strong>:<br \/>\n<code>for<\/code> <em>db_pattern<\/em> [<code>and<\/code> <em>db_pattern<\/em>]* [{ <em>statement<\/em>* }] [<code>collect<\/code> <em>expr<\/em>]<\/p>\n<ul>\n<li>where\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<em>db_pattern<\/em> ::=\u00a0<code><em>expr<sub>1<\/sub><\/em>, ..., <em>expr<sub>n<\/sub><\/em><\/code> <code>in<\/code> <em>expr<\/em><\/li>\n<li>computes a generalized join of the databases given at the right of the\u00a0<code>collect<\/code>\u00a0keyword: for each tuple in the generalized join, build a database as given after the\u00a0<code>collect<\/code> keyword, finally compute the union of all the computed databases (see examples below);<br \/>\nif the\u00a0<code>collect<\/code>\u00a0keyword is absent, return the empty database\u00a0<code>nothing<\/code><\/li>\n<li>if the optional block {\u00a0<em>statement<\/em>* } is present, execute it for each matching list of\u00a0<em>db_pattern<\/em><\/li>\n<li>this is non-destructive, and creates new databases<\/li>\n<li>Example 1:<br \/>\n<code>for User, Id, Euid in $mydb collect {{User, Euid}}<\/code><br \/>\nbuilds a new database from <code>$mydb<\/code> where the middle field (<code>Id<\/code>) has been removed; this is an example of <em>projection<\/em>: for each tuple <code>User, Id, Euid<\/code> in <code>$mydb<\/code>, we build a tuple containing just <code>User, Euid<\/code>, and take the union of all those tuples<\/li>\n<li>Example 2:<br \/>\n<code>for \"Bill\", Id, Euid in $mydb collect {{Id, Euid}}<\/code><br \/>\nbuilds a new database from <code>$mydb<\/code> of those tuples whose first field matches the string <code>\"Bill\"<\/code>exactly: this is an example of <em>filtering.<\/em><\/li>\n<li>Example 3:<br \/>\n<code>for User, Service in $jobs and Service, Manager in $mgmt<br \/>\ncollect {{User, Manager}}<\/code><br \/>\nbuilds a new database of pairs <code>User, Manager<\/code> such that the tuple <code>User, Service<\/code> is in <code>$jobs<\/code> and <code>Service, Manager<\/code> is in <code>$mgmt<\/code> for some value <code>Service<\/code>: this is an example of a <em>join<\/em> (followed by projection, since we discard <code>Service<\/code>)<\/li>\n<li>Example 4 (more involved):<br \/>\n<code>for User, Pid, $epid in $mydb + $myotherdb<br \/>\nand Perm, Pid in $perm_db<br \/>\ncollect ( {{Pid*128+Perm, User + \" authorized\"}} + {{Perm, \"denied\"}}<\/code> )<br \/>\ncomputes the union of the two databases <code>$mydb<\/code> and <code>$myotherdb<\/code>, then looks for all triples in it where the third field is equal to <code>$epid<\/code> (obtaining the first and second fields in <code>User<\/code> and <code>Pid<\/code> respectively),<br \/>\nthen does a join with <code>$perm_db<\/code> on the value of the logical variable <code>Pid<\/code>,<br \/>\nand for each set of values <code>User<\/code>, <code>Pid<\/code>, <code>Perm<\/code> thus found, collects the two tuples computed as <code>Pid*128+Perm, User + \" authorized\"<\/code> and\u00a0<code>{{Perm, \"denied\"}}<br \/>\n<\/code>(this is a fancy formula meant to illustrate what we can do with database collections, but has no practical use a priori)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>assignment: $var=expr $var[expr1][expr2]&#8230;[exprn]=expr evaluate expr and assign its value val to variable $var, or to the entry indexed expr1, expr2, &#8230;, exprn in array $var. return value val Typing: Requires: $var and expr have the same type type Yields: result of type type &nbsp; variables $var\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $[A&#8211;Za&#8211;z_][A&#8211;Za&#8211;z0&#8211;9_.]* ordinary variables, can be read and assigned to &hellip; <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=283\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Expressions<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-283","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=283"}],"version-history":[{"count":19,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/283\/revisions"}],"predecessor-version":[{"id":678,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/283\/revisions\/678"}],"wp:attachment":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}