Le 12/06/2023 à 19:05, Steve Litt via fpc-pascal a écrit :
Busted! I used Pascal 1984-1993
So I guess you are not familiar too with the "Result" variable which
appeared with Delphi 1 in 1995 if I remember correctly.
nextt:= num;
can be written to as :
Result:= num;
Steve,
If you're looking for equivalent to "return X", use "Exit" with a
parameter in Pascal: "Exit(X)".
It's just a shortcut for "Result := X; Exit;"
Regards,
Michalis
pon., 12 cze 2023 o 19:57 Steve Litt via fpc-pascal
napisał(a):
>
> Nikolay Nikolov via fpc-pascal said on Mon, 12 Jun 2023
Nikolay Nikolov via fpc-pascal said on Mon, 12 Jun 2023 09:15:17 +0300
>On 6/12/23 04:44, Steve Litt via fpc-pascal wrote:
[snip]
>> So, subject to your guidance, I'm assuming FPC isn't optimized for
>> tail recursion. Is my assumption an accurate one?
>
>FPC supports tail recursion
Marco van de Voort via fpc-pascal said on Mon, 12 Jun 2023 09:12:22
+0200
>On 12-6-2023 08:15, Nikolay Nikolov via fpc-pascal wrote:
>
>Shouldn't the recursive call assign the result?
>
>> nextt(num - 1);
>
>
>nextt:=nextt(num - 1);
>
>
>if you don't use the result, the whole call may be
Jean SUZINEAU via fpc-pascal said on Mon, 12 Jun 2023 18:04:07 +0200
>According to you other posts, I won't be surprised that you think in a
>C/C++ way.
:-) Busted! I used Pascal 1984-1993, and C 1986-present with C++ (hate
it) 1990-1998. So I long ago forgot the details of pascal, and program
According to you other posts, I won't be surprised that you think in a
C/C++ way.
This doesn't change anything in your last example, but particularly :
nextt := num;
doesn't behave like in C :
return num;
In pascal I think the equivalent would be :
nextt := num; exit;
On 12-6-2023 08:15, Nikolay Nikolov via fpc-pascal wrote:
Shouldn't the recursive call assign the result?
nextt(num - 1);
nextt:=nextt(num - 1);
if you don't use the result, the whole call may be optimized away?
___
fpc-pascal maillist -
On 6/12/23 04:44, Steve Litt via fpc-pascal wrote:
Hi all,
Tail recursion is recursion in which absolutely nothing gets executed
after the return statement. Some programming languages, including
Guile, optimize for tail recursion such that tail recursive algorithms
don't use additional stack
Hi all,
Tail recursion is recursion in which absolutely nothing gets executed
after the return statement. Some programming languages, including
Guile, optimize for tail recursion such that tail recursive algorithms
don't use additional stack space as you pile up more and more levels of
recursion.