transparent lambda
Peter Levart
peter.levart at gmail.com
Sun Dec 27 11:14:45 PST 2009
On Sunday 27 December 2009 19:54:49 Peter Levart wrote:
> (see attached HTML)
>
I see that listprocessor ate my HTML attachment. I'm including it here in-line:
BlockExpression
A block expression is one of Primary (15.8) expressions. It is syntactically equivalent to Block
(14.2) but appears in expression contexts.
BlockExpression:
Block
Block:
{ BlockStatementsopt }
BlockStatements:
BlockStatement
BlockStatements BlockStatement
BlockStatement:
LocalVariableDeclarationStatement
ClassDeclaration
Statement
A block consists of Statements (14.5). One class of statements is a
StatementWithoutTrailingSubstatement. We extend it's definition to include another form of
statement called LocalYieldStatement:
StatementWithoutTrailingSubstatement:
Block
EmptyStatement
ExpressionStatement
AssertStatement
SwitchStatement
DoStatement
BreakStatement
ContinueStatement
ReturnStatement
SynchronizedStatement
ThrowStatement
TryStatement
LocalYieldStatement
LocalYieldStatement:
= Expressionopt ;
Local yield statement is only valid if the innermost containing syntactical construct of the
following constructs:
ClassDeclaration
ClassBody (of the ClassInstanceCreationExpression)
BlockExpression
is a BlockExpression. It's a compile-timer error if it appears anywhere else. Any local yield
statement is said to belong to the innermost block expression in which it appears. All local
yield statements that belong to a particular block expression constitute the block expression's
set of local yield statements.
It is a compile-time error if there are both local yield statements with Expression and local
yield statements with no Expression present in the block expression's set of local yield
statements.
It is a compile-time error if there are any local yield statements with Expression present in
the block expression's set of local yield statements and last block statement can complete
normally.
A local yield statement with no Expression attempts to transfer control to the evaluator of the
block expression that contains it.
To be precise, a local yield statement with no Expression always completes abruptly, the reason
being a local yield with value null.
A local yield statement with an Expression attempts to transfer control to the evaluator of the
block expression that contains it; the value of the Expression becomes the value of the block
expression. More precisely, execution of such a local yield statement first evaluates the
Expression. If the evaluation of the Expression completes abruptly for some reason, then the
local yield statement completes abruptly for that reason. If evaluation of the Expression
completes normally, producing a value V, then the local yield statement completes abruptly, the
reason being a local yield with value V.
A block expression is evaluated by executing each of the block statements in order from first to
last (left to right). If any of block statements complete abruptly for any reason except for a
local yield, then no further actions are performed and the block expression completes abruptly
for the same reason. If any block statements complete abruptly and the reason is a local yield
with value V, then no further actions are performed and the block expression attempts to
complete normally, producing value V converted to the type of block expression (see below). If
last block expression statement completes normally then block expression completes normally,
producing the value null.
The type of block expression is:
Nothing if there are no reachable local yield statements in the block expression's set of local
yield statements and the last block statement can not complete normally; otherwise
Void if there are no local yield statements with Expression present in the block expression's
set of local yield statements; otherwise
A reduction of the types of all Expressions of local yield statements in the block expression's
set of local yield statements using the reduction function defined as follows: Let T1 and T2 be
two types. The reduction of types T1 and T2 is the type of ConditionalExpression defined by JLS
(15.25) where T1 and T2 represent the types of second and third operands of conditional operator
? :
The preceding descriptions of local yield statement say "attempts to transfer control" rather
than just "transfers control" because if there are any try statements (14.20) within the block
expression whose try blocks contain the local yield statement, then any finally clauses of those
try statements will be executed, in order, innermost to outermost, before control is transferred
to the evaluator of block expression. Abrupt completion of a finally clause can disrupt the
transfer of control initiated by a local yield statement.
...
Examples:
String s = ...;
char c = ...;
int firstIndex = {
for (int i = 0; i < s.length(); i++)
if (s.charAt(i) == c)
=i;
=-1;
};
More information about the lambda-dev
mailing list