Smart pascal source code
var i = Ord('A');
function MyString: String;
begin
Result := Chr(i);
Inc(i);
end;
procedure DoWriteLn(nb: Integer; lazy str: String);
begin
WriteLn('WriteLn nb=' + IntToStr(nb) + ': ' + str);
if nb > 1 then
DoWriteLn(nb - 1, str);
end;
procedure Local;
var v: String;
begin
v := 'World';
DoWriteLn(3, v);
end;
type
TMyObj = class
Field: String;
function IncField: String;
end;
function TMyObj.IncField: String;
begin
Field := Field + Chr(Ord('a') + Length(Field));
Result := Field;
end;
DoWriteLn(3, 'hello');
Local;
DoWriteLn(4, MyString);
var
o = TMyObj.Create;
DoWriteLn(3, o.IncField);
DoWriteLn(3, o.Field);
DoWriteLn(3, o.Field + o.IncField);
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
Print nb=3: hello
Print nb=2: hello
Print nb=1: hello
Print nb=3: World
Print nb=2: World
Print nb=1: World
Print nb=4: A
Print nb=3: B
Print nb=2: C
Print nb=1: D
Print nb=3: a
Print nb=2: ab
Print nb=1: abc
Print nb=3: abc
Print nb=2: abc
Print nb=1: abc
Print nb=3: abcabcd
Print nb=2: abcdabcde
Print nb=1: abcdeabcdef
-----------------------------
{<<<<<<<<< THE END >>>>>>>>>}
var TMyObj = {
$ClassName:"TMyObj",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
$.Field = "";
}
,IncField:function(Self) {
var Result = "";
$Check(Self,"").Field = $Check(Self,"").Field+Chr(97+$Check(Self,"").Field.length);
Result = $Check(Self,"").Field;
return Result
}
,Destroy:TObject.Destroy
};
function MyString() {
var Result = "";
Result = Chr(i);
++i;
return Result
};
function Local() {
var v = "";
v = "World";
DoWriteLn(3,function () { return v});
};
function DoWriteLn(nb, str) {
WriteLn(("WriteLn nb="+nb.toString()+": "+str()));
if (nb>1) {
DoWriteLn(nb-1,function () { return str()});
}
};
var i = 0,
o = null;
/* <<< main JS >>> */
i = 65;
DoWriteLn(3,function () { return "hello"});
Local();
DoWriteLn(4,function () { return MyString()});
o = TObject.Create($New(TMyObj));
DoWriteLn(3,function () { return TMyObj.IncField(o)});
DoWriteLn(3,function () { return $Check(o,"").Field});
DoWriteLn(3,function () { return ($Check(o,"").Field+TMyObj.IncField(o))});