Lazy Recursive



Lazy Recursive
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 >>>>>>>>>}