Smart pascal source code
type
TIntegers = array of Integer;
var
a1, a2: TIntegers;
i: Integer;
begin
a1 := [1,2,3];
for i := a1.Low to a1.High do
Writeln(a1[i]); // 1,2,3
Writeln(a1.Length); // 3
WriteLn('--------------');
a2 := a1.Copy(1);
for i := a2.Low to a2.High do
Writeln(a2[i]); // 2,3
Writeln(a2.Length); // 2
WriteLn('--------------');
a2 := a1.Copy;
for i := a2.Low to a2.High do
Writeln(a2[i]); //1,2,3
Writeln(a2.Length); //3
WriteLn('--------------');
try a2 := a1.Copy(3, 0);
except on e: Exception do
Writeln(e.Message);
end;
try a2 := a1.Copy(1, - 1);
except on e: Exception do
Writeln(e.Message);
end;
try a2 := a1.Copy(0, 4);
except on e: Exception do
Writeln(e.Message);
end;
try a2 := a1.Copy(-1, 2);
except on e: Exception do
Writeln(e.Message);
end;
var a1 = [],
a2 = [],
i = 0;
a1 = [1, 2, 3].slice();
var $temp1;
for(i=0,$temp1=a1.length;i<$temp1;i++) {
WriteLn(a1[i]);
}
WriteLn(a1.length);
WriteLn("--------------");
a2 = a1.slice(1);
var $temp2;
for(i=0,$temp2=a2.length;i<$temp2;i++) {
WriteLn(a2[i]);
}
WriteLn(a2.length);
WriteLn("--------------");
a2 = a1.slice(0);
var $temp3;
for(i=0,$temp3=a2.length;i<$temp3;i++) {
WriteLn(a2[i]);
}
WriteLn("--------------");
try {
a2 = a1.slice(3,0);
} catch ($e) {
var e = $W($e);
WriteLn(e.FMessage) }
try {
a2 = a1.slice(1,(-1));
} catch ($e) {
var e$1 = $W($e);
WriteLn(e$1.FMessage) }
try {
a2 = a1.slice(0,4);
} catch ($e) {
var e$2 = $W($e);
WriteLn(e$2.FMessage) }
try {
a2 = a1.slice((-1),2);
} catch ($e) {
var e$3 = $W($e);
WriteLn(e$3.FMessage) }
//--------------------------------------
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;
};