Smart pascal source code
procedure WriteLnArray(a: array of Integer);
var
i: Integer;
begin
Writeln(IntToStr(Length(a)) + ':{');
for i := 0 to High(a) do
begin
if i > 0 then
Writeln(',');
Writeln(IntToStr(a[i]));
end;
Writeln('}');
end;
{ unit1.pas }
var
a: array of Integer;
begin
a.Insert(0, 10);
a.Insert(1, 20);
WriteLnArray(a); // 2:{10,20}
a.Insert(0, 0);
WriteLnArray(a); // 3:{0,10,20}
a.Insert(2, 15);
WriteLnArray(a); // 4:{0,10,15,20}
try a.Insert(-1, 0);
except on E: Exception do
Writeln(E.Message);
end;
try a.Insert(5, 0);
except on E: Exception do
Writeln(E.Message);
end;
WriteLnArray(a); // 6:{0,10,15,0,20,0}
var Exception={
$ClassName: "Exception",
$Parent: TObject,
$Init: function () { FMessage="" },
Create: function (s,Msg) { s.FMessage=Msg; return s }
}
function $W(e) { return e.ClassType?e:Exception.Create($New(Exception),e.constructor.name+", "+e.message) }
function $New(c) { var i={ClassType:c}; c.$Init(i); return i }
function $Is(o,c) {
if (o===null) return false;
return $Inh(o.ClassType,c);
};
function $Inh(s,c) {
if (s===null) return false;
while ((s)&&(s!==c)) s=s.$Parent;
return (s)?true:false;
};
function WriteLnArray(a$1) {
var i = 0;
WriteLn(((a$1.length).toString() + ":{"));
var $temp1;
for (i = 0, $temp1 = a$1.length; i < $temp1; i++) {
if (i > 0) {
WriteLn(",");
}
WriteLn((a$1[i]).toString());
}
WriteLn("}");
};
var a = [];
a.splice(0,0,10);
a.splice(1,0,20);
WriteLnArray(a);
a.splice(0,0,0);
WriteLnArray(a);
a.splice(2,0,15);
WriteLnArray(a);
try {
a.splice((-1),0,0);
} catch ($e) {
var E = $W($e);
WriteLn(E.FMessage) }
try {
a.splice(5,0,0);
} catch ($e) {
var E$1 = $W($e);
WriteLn(E$1.FMessage) }
WriteLnArray(a);