ORIGIN '~beta/containers/list';
--- program:descriptor ---
(* This demo program illustrates the usage of the list pattern. The first
* part of the demo illustrates inserting and deleting elements from the lists.
*
* At the end of this file, a copy of the output of this program is given
*)
(# intList: list(# element:: integerObject #);
intList1, intList2: @intList; intList3: ^intList;
i: [10]^integerObject;
listPosition: ^intList.theCellType;
do (* initializing the integerObjects *)
(for int:10 repeat &integerObject[]->i[int][]; int->i[int] for);
(* initializing intList1 and putting some integerObjects into it *)
intList1.init;
'intList1.prepend: '->puttext;
(for int:4 repeat
i[int][]->intList1.prepend
for);
intList1.scan(# do current->putint; ','->put #); newline;
(* initializing intList3 and putting some integerObjects into it *)
intList2.init;
'intList2.append: '->puttext;
(for int:4 repeat
i[int+3][]->intList2.append
for);
intList2.scan(# do current->putint; ','->put #); newline;
(* illustrates the reverse scanning *)
'intList2.scanReverse: '->puttext;
intList2.scanReverse(# do current->putint; ','->put #); newline;
(* initializing intList3 *)
&intList[]->intList3[]; intList3.init;
(* illustrating concatenation of lists *)
'intList1[]->intList2.concatenate->intList3[]: '->puttext;
intList1[]->intList2.concatenate->intList3[];
intList3.scan(# do current->putint; ','->put #); newline;
(* illustration getting the position of some integerObject in the list, and
* replacing the element at that position
*)
'"10"->("2"->intList3.at).elm[]: '->puttext;
i[2][]->intList3.at->listPosition[];
i[10][]->listPosition.elm[];
intList3.scan(# do current->putint; ','->put #); newline;
(* illustrates deleting an element from the list *)
'6->intList2.at->intList2.delete: '->puttext;
i[6][]->intList2.at->intList2.delete;
intList2.scan(# do current->putint; ','->put #); newline;
i[7][]->intList3.at->listPosition[];
(* illustrating inserting integerObjects before some list position *)
'(8,7)->intList3.insertBefore: '->puttext;
(i[8][],listPosition[])->intList3.insertBefore;
intList3.scan(# do current->putint; ','->put #); newline;
(* illustrating deleting integerObjects after some list position *)
'7->intList3.deleteAfter: '->puttext;
listPosition[]->intList3.deleteAfter;
intList3.scan(# do current->putint; ','->put #); newline;
(*********** OUTPUT ***************
* intList1.prepend: 4,3,2,1,
* intList2.append: 4,5,6,7,
* intList2.scanReverse: 7,6,5,4,
* intList1[]->intList2.concatenate->intList3[]: 4,5,6,7,4,3,2,1,
* "10"->("2"->intList3.at).elm[]: 4,5,6,7,4,3,10,1,
* 6->intList2.at->intList2.delete: 4,5,7,
* (8,7)->intList3.insertBefore: 4,5,6,8,7,4,3,10,1,
* 7->intList3.deleteAfter: 4,5,6,8,7,3,10,1,
******************************)
#) |