Smart pascal source code
var i, k: Integer;
function PostInc(var i: Integer): Integer;
begin
Result := i;
i := i + 1;
end;
function GlobInc: Integer;
begin
Result := k;
k := k + 5;
end;
function CondEval(eval: Boolean; lazy a: Integer): Integer;
begin
if eval then
Result := a
else
Result := 0;
end;
procedure LazyWriteLn(lazy a: Integer);
var i: Integer;
begin
for i := 1 to 10 do
begin
WriteLn(a);
WriteLn(',');
end;
WriteLn('');
end;
WriteLn('Pre-Inc');
k := 10;
LazyWriteLn(Inc(k));
k := 5;
LazyWriteLn(Inc(k, 5));
WriteLn('Post-Inc');
k := 10;
LazyWriteLn(PostInc(k));
k := 5;
LazyWriteLn(GlobInc);
WriteLn('Conditional eval');
for k := -1 to 1 do
WriteLn(CondEval(k <> 0, 1 div k));
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
Pre-Inc
11,12,13,14,15,16,17,18,19,20,
10,15,20,25,30,35,40,45,50,55,
Post-Inc
10,11,12,13,14,15,16,17,18,19,
5,10,15,20,25,30,35,40,45,50,
Conditional eval
-1
0
1
-----------------------------
{<<<<<<<<< THE END >>>>>>>>>}
function $Div(a,b) { var r=a/b; return (r>=0)?Math.floor(r):Math.ceil(r) }
function WriteLn(value) {
if (window.console) { window.console.log(value); } };
function PostInc(i$2) {
var Result = 0;
Result = i$2.v;
i$2.v+=1;
return Result
};
function LazyWriteLn(a) {
var i = 0;
for(i=1;i<=10;i++) {
WriteLn(a());
WriteLn(",");
}
WriteLn("");
};
function GlobInc() {
var Result = 0;
Result = k.v;
k.v+=5;
return Result
};
function CondEval(eval$1, a$1) {
var Result = 0;
if (eval$1) {
Result = a$1();
} else {
Result = 0;
}
return Result
};
var i$1 = 0;
var k = {};
k.v = 0;
/* <<< main JS >>> */
WriteLn("Pre-Inc");
k.v = 10;
LazyWriteLn(function () { return ++k.v});
k.v = 5;
LazyWriteLn(function () { return (k.v+= 5)});
WriteLn("Post-Inc");
k.v = 10;
LazyWriteLn(function () { return PostInc(k)});
k.v = 5;
LazyWriteLn(function () { return GlobInc()});
WriteLn("Conditional eval");
for(k.v=-1;k.v<=1;k.v++) {
WriteLn(CondEval((k.v!=0),function () { return ($Div(1,k.v))}));
}