RAY66
RAY66

Reputation: 35

Is there any way to simulate recursion without implicit or explicit use of the stack ADT?

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

Answers (2)

gsg
gsg

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

Wraith
Wraith

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

Related Questions