> -----Original Message-----
> From: Patrick E. Hughes [mailto:hu...@tr...]
>
> <question>
> Where in heck did recursion get such a bad rap?
> </question>
>
The original poster indicated programming since TurboPascal 1.0 when
recursion did not exist...as was with other languages at that time such as
GWBasic. However, it could still be done in GWBasic or by creating an
assembler function in MASM, but the concequences were stack management since
every call to the procedure pushes the return address and flags onto the
stack. It required that the program keep track of it's calls and execute a
return statement for every call like this:
public loopcount
public callitself
Sub Main()
loopcount=0
callitself=0
GoSub Recursive
End
Sub Recursive()
GoSub dostuff 'will return with callitself = 1 or callitself=0
if callitself=1 then
loopcount=loopcount+1
GoSub Recursive
end if
For loopcounter=1 To loopcount
Return
Next
Return
End Sub
I think later Return(count) was added for a short period of time that
allowed count number of parameters to be popped off the stack (compiled
directly into the Ret i assembly instruction) ...but was actually
implemented for languages that called other languages with different calling
conventions of far addresses and near address thus needing to clear the
stack...otherwise you'd have to set sp=bp when finished...and other such
lunatic coding.
As you can see it was scary stuff back then...especially when you had to
allocate stack space and suffered serious damage and unpredictable results
if the stack moved into data or code segments.
R&R
|