Re: Various comments Jens Axel Søgaard 02 May 2003 06:07 UTC

xxxxxx@freenetproject.org wrote:

>The short answer is that while an iterator can easily be functional and
>efficient (because it usually only needs a small amount of state, like a
>pointer), a datastructure may not be.  Take as an example an actively
>balanced tree.  A functional version of remove may have to do a lot of
>work to modify the tree, but even more if its not allowed to affect the
>original (possibly as bad as copying the entire tree).  At best this
>creates a lot of extra GC pressure.
>

Fully functional datastructures do have some advantages though. For one
it is possible
to store severeal instances of the same datastructure in different stages,
in order to provide undo-functionallity. Second, there are no problems
with concurrency
if the process forks some children.

In order to accomodate a functional way of using collections, one could
consider letting
the remove! functions return the altered datastructure. This would make
code like this
possible, that passes the datastructure it self around.

Silly example that removes the elements 1 2 3 from some set s:

  (let loop ([l (list 1 2 3)]
             [s ...some set...])
      (if (null? l)
          s
          (loop (cdr l)
                (set-remove! (car l) s))))

I other words, I also prefer remove and friends to return something useful.

--
Jens Axel Søgaard