I have found a curios problem with Procedures.
When using Longs i can recurs a number of levels, but with Doubles it stops at 8 calls. I can't figure out why. Anyone, else who can?
code with Long:
Code: Select all
Define.l
Procedure.l fac_rec(n)
Debug n
If n > 1
ProcedureReturn n * fac_rec(n - 1)
EndIf
ProcedureReturn 1
EndProcedure
MessageRequester("faculty with true recursion",Str(fac_rec(12)))
same code with Double:
Code: Select all
Define.d
Procedure.d fac_rec(n)
Debug n
If n > 1
ProcedureReturn n * fac_rec(n - 1)
EndIf
ProcedureReturn 1
EndProcedure
MessageRequester("faculty with true recursion",Str(fac_rec(12)))
#IND I suppose is Indefinite, but I suspect it's the ProcedureReturn from the called Procedure that returns it.
Or have I managed to do something that shouldn't be possible? It works a while but suddenly breaks down - after exactly 8 levels. Change the value to 32 and it will count down to 25 and so on.
Well, here is some code that makes it work suddenly:
Code: Select all
Define.d
Procedure.d fac_rec(n)
Debug n
If n > 1
result = fac_rec(n - 1)
ProcedureReturn n * result
EndIf
ProcedureReturn 1
EndProcedure
MessageRequester("faculty with true recursion",Str(fac_rec(12)))
If this has been handled before somewhere, I'm very sorry, but i have been searching and didn't find anything like this.