Recent

Author Topic: functional programming  (Read 5409 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 2268
  • Compiler Developer
Re: functional programming
« Reply #45 on: January 21, 2020, 02:59:39 pm »
That appears to be a bug detecting the tail call correctly. Would you please report it?
Just tested SumL against i386-win32 rev.44002 - works as expected. :D
Updated my version as well.  :-[ It indeed works correctly now.  :)

PascalDragon

  • Hero Member
  • *****
  • Posts: 2268
  • Compiler Developer
Re: functional programming
« Reply #46 on: January 21, 2020, 11:03:12 pm »
No, as these things change/improve with each version. E.g. yesterday Florian helped me to work out how to get constant and by-value open array parameters working as well, so that will probably soon be in trunk (and maybe 3.2) as well. ;)
Good news.
Implemented in r44012. :)

Please note that there is still another restriction (for the foreseeable future): managed types. If a parameter is an AnsiString, UnicodeString, interface, dynamic array, managed record or a record containing one of these types then the optimization won't be applied.

avk

  • Sr. Member
  • ****
  • Posts: 309
    • my self-education project
Re: functional programming
« Reply #47 on: January 22, 2020, 04:54:35 am »
Thank you very much.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1063
    • Burdjia
Re: functional programming
« Reply #48 on: January 22, 2020, 11:53:22 am »
You have two errors in there: you need to use Values[LOW(Values)] and Values[HIGH(Values)].
Doh! %) I've fixed it.  Maybe I'm not the genius I though. :-[

Behold the slice operator (it's documented here at the bottom):
Code: Pascal  [Select][+][-]
  1. function SumR(const Values: array of Integer): Integer;
  2. begin
  3.   if Length(Values) = 1 then
  4.     SumR := Values[Low(Values)]
  5.   else
  6.     SumR := SumR(Values[1..High(Values)]) + Values[Low(Values)];
  7. end;
  8.  
Thanks for the tip. Didn't know it was possible. I wonder if Delphi supports that too.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

 

TinyPortal © 2005-2018