program listtest(input, output); Uses lists; var mylist: list; type type1 = char; type2 = integer; type3 = real; type4 = string; procedure filllist; var v1: type1; v2: type2; v3: type3; v4: type4; begin v1 := 'a'; v2 := ord('a'); v3 := 3.3; v4 := 'This is a test.'; mylist := listnew; if (mylist = NIL) then begin writeln('listnew() returned NIL.'); halt(1); end; if (listinsert(mylist, addr(v1), sizeof(v1), 65535) = NIL) then begin writeln('listinsert() returned NIL when adding v1.'); end; if (listinsert(mylist, addr(v2), sizeof(v2), 65535) = NIL) then begin writeln('listinsert() returned NIL when adding v2.'); end; if (listinsert(mylist, addr(v3), sizeof(v3), 65535) = NIL) then begin writeln('listinsert() returned NIL when adding v3.'); end; if (listinsert(mylist, addr(v4), length(v4)+1, 65535) = NIL) then begin writeln('listinsert() returned NIL when adding v4.'); end; end; procedure checklist; type type1ptr = ^type1; type2ptr = ^type2; type3ptr = ^type3; type4ptr = ^type4; begin writeln('0''th element from list: "', type1ptr(listelmt(mylist, 0))^, '" (size=', elmtwidth(mylist, 0), ' bytes)'); writeln('1''th element from list: "', type2ptr(listelmt(mylist, 1))^, '" (size=', elmtwidth(mylist, 1), ' bytes)'); writeln('2''th element from list: "', type3ptr(listelmt(mylist, 2))^, '" (size=', elmtwidth(mylist, 2), ' bytes)'); writeln('3''th element from list: "', type4ptr(listelmt(mylist, 3))^, '" (size=', elmtwidth(mylist, 3), ' bytes)'); listdispose(mylist); end; begin writeln('filling list...'); filllist; writeln('checking list...'); checklist; writeln('Done.'); end.