Lazy



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