Structure sharing surprise

As a Lisp head I was slightly surprised by the behavior of this code given the that “in front of” is documented to produce a list that “shares structure”. It says true (expected) and then false (not expected). I assume this has to do with the replace item somehow converting back from a linked list to a dynamic array? Is this a bug or a feature?

A feature. Using ADD, INSERT, REPLACE & friends converts a linked list to a dynamic array. Paraphrased from BH

Yeah, if you mutate a list we assume you mean it to be an array. The idea is that people should be able to write efficient recursive functions on lists, and should also be able to write efficient array procedures, but that you won’t do both to the same list. So ALL BUT FIRST OF is constant time as long as you only use functional programming on your list, but ITEM (n) OF is constant time as long as you don’t butfirst your list. The idea is that we read your mind without you having to know anything about data structures. But we do occasionally fail at reading someone’s mind and I’m not 100% sure I would stick to this design if we were starting over. Remember that we started from Scratch, and they use the name “list” for what’s actually a dynamic array, so we started out with already-confused terminology.

On my list of desirable but don’t-hold-your-breath features is to have specific mutators for linked lists, set-car! and set-cdr!, in Snap!.

Yes please!