If, for example, I want to put a value into the middle of a list, would I be doing something akin to. . .
MyList = MyList.firstHalf + NewValue + MyList.secondHalf?
And how doesn't this become a horrible bottleneck?
If, for example, I want to put a value into the middle of a list, would I be doing something akin to. . .
MyList = MyList.firstHalf + NewValue + MyList.secondHalf?
And how doesn't this become a horrible bottleneck?
Given a zipper (as x bs) you can move the cursor right (rather, compute the zipper with the cursor one step further to the right, since we're purely functional) as ((cons x as) (car bs) (cdr bs)). You can insert a new element "y" into you current position by computing (as y (cons x bs)). If you discard the old version of the zipper every time you move or insert, this will use the same amount of memory as just storing the list, and you get insertions in O(N) time and O(1) memory. There's a whole field devoted to making data structures like this for purely functional languages, and this zipper concept extends itself rather naturally to trees.
[1]https://en.wikipedia.org/wiki/Zipper_%28data_structure%29
Your example is not possible in an immutable list. Also note that this reassigning of variables is a red flag even in standard Lisps. In fact, variables are not that common. The most common way of referencing something for later usage is the let form, which already creates new "variables" anyway. Just eliminate ways to reassign them (setf?).
What you would do is to create a new list containing the elements you want. You may or may not want to give it a new name afterwards. Most likely, you'll use as it is and pass on to some other function.
I can't comment on this particular implementation. But it does not necessarily have to be a bottleneck. In fact, by having immutable data structures, that means that you can share data like crazy, without fear of anything being replaced where it should not. All sorts of optimizations are enabled that wouldn't be possible otherwise. If this implementation uses them, it's another matter entirely. No idea.
You can learn more in Okasaki's great book: http://www.amazon.com/Purely-Functional-Structures-Chris-Oka...
Read Chris Okasaki, "Purely functional data structures" for better options.