Lisp type list, recursion and tail call optimisation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Lisp type list, recursion and tail call optimisation

alan r
I just implemented a Lisp or Scheme style of list collection, which I
find extremely useful and elegant for certain applications. One
interesting problem is that the semantics for this kind of list are
very different than Smalltalk. For example, list changing operations
are non-destructive. So for example, on a #remove: , if the element is
in the first position, then the answer is simply the sublist starting
at the 2nd position. So this means that #remove: implemented this way
cannot return the object being removed (not necessarily identical to
the argument), like in Smalltalk, since it must return the new list.
More of a functional approach.

Most of the usual operations on lists in Scheme utilize recursion
instead of iteration. For example, #remove: would have an recursive
invocation for each element it visited until it hit the element to
remove. I'm sure Dolphin doesnt do tail-call optimisation (do any
smalltalks?). So I am curious as to how practical it would be
performance-wise, to implement functions like this recursively in
Dolphin, ie what is the cost of an activation and what are the
practical limits on the depth. (Actually I think the number of
activations would be roughly the same as an iterative version, but in
the recursive version (without tail-call optimization) they are all in
the stack at the same time).