18.3. with-near statement

Example 18-2. Example:

with able, baker near ... end
with_near_statement ==>
        with ident_or_self_list near statement_list [else statement_list] end
ident_or_self_list ==>identifier | self { , identifier | self }

The with-near statement asserts that particular reference objects must remain near at run-time. The ident_or_self_list may contain local variables, arguments, and self; these are called near variables. When the with statement begins execution, the identifiers are checked to ensure that all of them hold either objects that are near or void. If this is true then the statements following near are executed, and it is a fatal error if the identifiers stop holding either near objects or void at any time. It is a fatal error if some identifiers hold neither near objects nor void and there is no else. Otherwise, the statements following the else are executed.

18.3.1. Locality examples

Example 18-3. This code creates a object and then inserts it into a table, taking care that the insertion code runs at the same cluster as the table.

table.insert(#FOO) @ where(table);

Example 18-4. To make sure the object is at the same cluster as the table, one could write

loc ::= where(table);
table.insert(#FOO @ loc) @ loc;

Example 18-5. or, equivalently:

fork @ where(table);

Example 18-6. This code recursively copies only that portion of a binary tree which is near. Notice that 'near' returns false if its argument is void.

near_copy:NODE is
   if near(self) then
      return #NODE(lchild.near_copy,
      return self;