Reputation: 35
Usually functional recursion is simulated using the call stack ,but is there any way to simulate recursion without using the stack ADT?
Upvotes: 2
Views: 62
Reputation: 9377
Yes: one of the well-known approaches to implementing functional languages with first-class continuations is to heap allocate activation records, deallocation being handled by garbage collection. In this scheme call information is arranged in an immutable DAG, and a continuation has the particularly straightforward implementation of a pointer to an activation record.
Without the motivation of first-class continuations this arrangement isn't all that attractive for performance reasons.
Upvotes: 1
Reputation: 63
You can simulate a stack using an array, for example (not using the stack ADT) ... But if you want an implementation of recursion without using stacks at all - implicit, explicit, or self-defined, go through this link: http://home.olympus.net/~7seas/recurse.html
Upvotes: 1