flushing
do Write_Line( "This is box.demo.Q" );
set .interv = [ 1->4 ];
with_format _table_
do Display each[ .x, .y ]
each_time(
.box1 = [ [.a, .c+1] : .a Is_In .interv and .c = .a *.a ]
and [.x, .y] Is_In .box1
);
set .box2 = [ [.a, .b, (.a *.a)+1] :
.a Is_In [ 1->4 ] and .b Is_In [ .a -1 -> .a + 2 ]
: with_reverse_lexico_order
with_sort_spec[ -2, 1] ];
do Write_Line( "Total integers = ",
sum( over .qq each_time( [.x, .y, .z] Is_In .box2 and .qq = .x + .y + .z )) );
flushing
do Write_Line( "Total first two components = ",
sum( over .qq each_time( [.x, .y, ?] Is_In .box2 and .qq = .x + .y )) );
with_format _table_
do Display each[ .x, .y, .z ]
each_time(
[.x, .y, .z] Is_In .box2 in_reverse_lexico_order
);
with_format _table_
do Display each[ .x, .y, .z ]
each_time(
[.x, .y, .z] Is_In .box2 sorted_by_spec[ -2, 1 ]
);
/** log n membership testing **/
with_format _table_
do Display each .x each_time(
.x Is_In [ 0 -> 10 ]
and [ .x, 3, (.x * .x)+1 ] Is_In .box2 in_reverse_lexico_order
);
/** ground element index use **/
with_format _table_
do Display each[ .x ]
each_time(
.y Is_In [3,4] and
[.x, .y, ?] Is_In .box2 sorted_by_spec[ -2, 1 ]
);
with_format _table_
do Display each .city
each_time(
.city Is_In { .x : there_is_a SUPPLIER where( City = .x ) } in_reverse_lexico_order
);
flushing
do Write_Line( 25 * "*" );
/** From the manual: with_sort_specs **/
{
set .bbb =
box( for ~[ .x, .y, .z ] such_that(
.x Is_In [ 10 -> 1 by -1 ] and .y Is_In [ .x - 3 -> .x + 3 ]
and .z = .x * .y )
with_sort_specs [ [ -3, 2 ], [ 1 ], [ -2, 1 ] ]
with_lexico_order
with_selection_index_vbl si
stopping_if( .si > 10 )
);
with_format _table_
do Display tuples_satisfying ~[.x,.y,.z]such_that(
[.x,.y,.z] Is_In .bbb ); /* default here: arbitrary order */
with_format _table_
do Display tuples_satisfying ~[.x,.y,.z]such_that(
[.x,.y,.z] Is_In .bbb in_lexico_order );
with_format _table_
do Display tuples_satisfying ~[.x,.y,.z]such_that(
[.x,.y,.z] Is_In .bbb sorted_by_spec [ -2, 1] );
with_format _table_
do Display each [.x,.y,.z]
each_time(
[.x,.y,.z] Is_In .bbb with_selection_index 5
);
with_format _table_
do Display each [.x,.y,.z]
each_time(
[.x,.y,.z] Is_In .bbb with_sort_index 5 sorted_by_spec [ -2, 1]
);
}
flushing
do Write_Line( 25 * "*" );
/** From the manual: outside vbls **/
{
set .d = 4;
with_format _table_
do Display each[.x, .y, .z]
each_time( [.x, .y, .z] Is_In { [ .w, .w * .d, 16 ] : .w Is_In [ .d -> 8 ] } );
/* the equivalent */
with_format _table_
do Display each[.x, .y, .z]
each_time( [.x, .y, .z] Is_In
box( for ~[.w, .v1, .v2] such_that(
.w Is_In [ .d -> 8 ]
/* and .w = .w */ and .v1 = .w * .d and .v2 = 16 )
with_no_duplicates with_default_arbitrary_order )
);
}
flushing
do Write_Line( 25 * "*" );
/** From the manual: ancillary vbls and assertions **/
{
set .bb = box( for ~[ .w ] such_that( .w Is_In [ 50 -> 80 ] )
with_candidate_indices_stored
with_selection_index_vbl si
with_selection_indices_stored
selecting_if( .w % 2 = 0 )
stopping_if( .si = 10 )
);
with_format _table_
do Display tuples_satisfying ~[.x,.y,.z]such_that(
.x Is_In .bb
with_candidate_index_vbl y
with_selection_index_vbl z
);
}
flushing
do Write_Line( 25 * "*" );
/** From the manual: ancillary vbls and assertions **/
{
with_format _table_
do Display each .x
each_time( .x Is_In [ 4, 2, 0, 1, 3, 5 ] in_reverse_selection_order );
}
/** boxes whose assertions contain quantifiers, disjunction, there_isas, and other boxes
caching involved
**/
set .pbox =
{ [ .a, .b, (.b+1)<*2 ]:
( .a Is_In [ 150 -> 160 ]
or ( .a Is_In [ .pno :
there_is_a PART where( Number = .pno which_is > 175 & < 180 )
and there_exists .onbr such_that(
there_is_an ORDER where(
Part_Nbr = .pno and Number = .onbr which_is > 500 ) ) ] )
)
and .b Is_In [ .a -3 -> .a +3 ]
: with_sort_spec[ -1 ] };
with_format _table_
do Display each [ .x, .y, .z ]
each_time( [ .x, .y, .z ] Is_In .pbox sorted_by_spec [ -1 ] );