Java Reference
In-Depth Information
call, we'll be able to determine when elements are recalculated. So on to the
changes.
start = 1; println(seq);
This removes the first element of seq , and will not cause any other recalcula-
tions. The contents of seq now look like
[ 1, 2, 3, 4 ]
Changing the value of end from 4 to 5:
end = 5; println(seq);
will change the sequence, inserting a new element at index 4. Only the new ele-
ment (value=5) is recalculated. The contents of seq are now
[ 1, 2, 3, 4, 5 ]
Finally, let's set start back to 0.
start = 0; println(seq);
This changes seq once again, this time inserting a new element at index 0. The
new element needs a recalculation, but no other recalculation is required. seq
now looks like:
[ 6, 1, 2, 3, 4, 5 ]
One corner case with binding sequences and for expressions involves use of the
indexof operator. Combining all of the preceding code, and modifying just the
bind statement (emboldened below) to include the indexof expression, yields
sequences of the same size, but significantly different contents. In essence, any
time the start variable changes, all elements are recalculated. Here's what the set
of code looks like now
var val = 0;
function incrementVal() : Integer {
return val++;
}
var start = 0;
var end = 4;
var seq = bind for (x in [start..end] where indexof x >= 0)
incrementVal();
Search WWH ::




Custom Search