recursion issue lazarus / 62-General ---------------------------------------------------------------------- wgrandinetti · 2015-06-12 13:36 Hi!    I have the following issue, which can be bypassed in two ways but I just want to report it in case that it were a bug. Consider this program: Code: [Select]program issue; function suma:integer; var num: integer; begin      read(num);      if num = -1         then suma:=0         else suma:= num + suma; end; begin     writeln('enter a sequence of integer numbers ended by -1 ');     writeln('the sum is: ',suma);     readln; end.  This program yields an erroneos result because it interprets that the identifier suma in the expression (recursive call) is a variable instead of the parameterless call. Solution 1: call parameterless functions always with () for instance suma() Solution 2: add {$mode tp}{$H-}{$X+} ---------------------------------------------------------------------- Bart · 2015-06-12 14:12 It's documented behaviour, so not a bug. Bart ---------------------------------------------------------------------- Leledumbo · 2015-06-12 17:34 Documented here. ---------------------------------------------------------------------- User137 · 2015-06-14 23:05 Solution 3: Code: [Select]function suma: integer; var num: integer; begin   read(num);   if num = -1 then result:=0   else result:=num + suma(); end; ---------------------------------------------------------------------- jc99 · 2015-06-15 00:02 @User137: To me this is Solution1, you just replaces the return variable with 'result', which is of course better readable. And wgrandinetti should code this way. But this does not make this a new Solution. Or please explain why you think it differs from solution1. ---------------------------------------------------------------------- User137 · 2015-06-15 17:52 He didn't mention the use of result. ---------------------------------------------------------------------- jc99 · 2015-06-16 02:36 Quote from: User137 on June 15, 2015, 07:52:01 pmHe didn't mention the use of result. Yes, He didn't you are right. And using your code is much better. But just using result and omitting the brackets would leave You with the same Problem.