Smart pascal source code
type
TRec = record
x: Integer;
y: string;
end;
const r1: TRec = (x: 1; y: 'one');
r2: TRec = (x: 2; y: 'two');
r3: TRec = (x: 2; y: 'twobis');
{ unit1.pas}
var
recs: array of TRec;
ints: array of Integer;
objs: array of TObject;
o := New TObject;
begin
ints.Add(1);
ints.Add(2);
Writeln('Integers'); // Integers
Writeln(0 in ints); // False
Writeln(1 in ints); // True
Writeln(2 in ints); // True
Writeln(0 not in ints); // True
Writeln(1 not in ints); // False
Writeln(2 not in ints); // False
Writeln('Records'); // Records
recs.Add(r1); // True
recs.Add(r2); // True
Writeln(r1 in recs); // true
Writeln(r2 in recs); // true
Writeln(r3 in recs); // false
objs.Add(TObject.Create);
objs.Add(o);
Writeln('Objects'); // Objects
Writeln(TObject.Create in objs); // False
Writeln(o in objs); // True
{ unit2.pas}
var
list: array of Integer = [5, 7];
item: variant = 5;
begin
if item in list then
Writeln('success')else Writeln('fail');
if not item in list then
Writeln('bug');
if not 5 in list then
Writeln('bug');
if not (not 5) in list then
Writeln('ok');
{
success
ok
}
/* unit1.js */
function Copy$TRec(s, d) {
d.x$1 = s.x$1;
d.y = s.y;
return d;
}
function Clone$TRec($) {
return {
x$1 : $.x$1,
y : $.y
}
}
function $IndexOfRecord(a, i, f) {
var ij = JSON.stringify(i);
for (var k = f, n = a.length; k < n; k++)
if (JSON.stringify(a[k]) == ij)
return k;
return -1
}
var recs = [],
ints = [],
objs = [],
o = null,
o = TObject.Create($New(TObject));
ints.push(1);
ints.push(2);
WriteLn("Integers");
WriteLn((ints.indexOf(0)>=0));
WriteLn((ints.indexOf(1)>=0));
WriteLn((ints.indexOf(2)>=0));
WriteLn((!(ints.indexOf(0)>=0)));
WriteLn((!(ints.indexOf(1)>=0)));
WriteLn((!(ints.indexOf(2)>=0)));
WriteLn("Records");
recs.push(Clone$TRec({x$1:1,y:"one"}));
recs.push(Clone$TRec({x$1:2,y:"two"}));
WriteLn(($IndexOfRecord(recs,{x$1:1,y:"one"},0)>=0));
WriteLn(($IndexOfRecord(recs,{x$1:2,y:"two"},0)>=0));
WriteLn(($IndexOfRecord(recs,{x$1:2,y:"twobis"},0)>=0));
objs.push(TObject.Create($New(TObject)));
objs.push(o);
WriteLn("Objects");
WriteLn((objs.indexOf(TObject.Create($New(TObject)))>=0));
WriteLn((objs.indexOf(o)>=0));
/* unit2.js */
var list = [],
list = [5, 7].slice();
var item,
item = 5;
if (list.indexOf(parseInt(item,10))>=0) {
WriteLn("success");
} else {
WriteLn("fail");
}
if (list.indexOf(parseInt((!item),10))>=0) {
WriteLn("bug");
}
if (list.indexOf(~5)>=0) {
WriteLn("bug");
}
if (list.indexOf(~(-6))>=0) {
WriteLn("ok");
}
function Copy$TRec(s,d) {
d.x$1=s.x$1;
d.y=s.y;
return d;
}
function Clone$TRec($) {
return {
x$1:$.x$1,
y:$.y
}
}