| > When you pass a value to a function, is it by value or by reference? Who knows? Value. Value, value, always value. However, it seems that maybe you don't understand exactly what the value is that you're passing. > Notice how, in my example, the resultant list is updated in the function parameter No [0]. It makes a new list (really a new cons cell, which contains the new item and then points to the old list [1]), and assigns that to v. And your example doesn't actually show this update happening, it just shows the return value of push (it so happens that it is updated, however). The original list --- passed in or otherwise --- is never changed. You say that you're "updating" a list, but you're not mutating or updating your data structure at all --- you're making something new, and assigning that to v. > These are two logically different behaviors! They are two logically different operations. Are you sure that you understand the data structures you're working with, and the operators that you're calling on them? Did you perhaps try to map concepts from another language into Common Lisp, find functionality that looked similar on the surface, then become surprised when the results were not identical? Linked lists differ fundamentally in structure from arrays, and so the operators which are commonly used with them differ in turn. Perhaps you would like to compare arrays to vectors, as a closer approximation in data structures, with similar typical strategies of manipulation? > does not follow the principle of least surprise. You keep saying this, as if that is that. But nothing about your example is surprising to me, so I suppose this is a matter of perspective. [0] http://clhs.lisp.se/Body/m_push.htm [1] https://en.wikipedia.org/wiki/Linked_list |
This is a distinction without a difference.
> ...you're making something new, and assigning that to v.
Yes, I know that. The point is that the behavior seen by the user for similar operations is entirely different between lists and other pieces of Common Lisp.
> They are two logically different operations.
Yes, obviously. The point is that Common Lisp does an absolutely crap job of making these things actually consistent from the point of view of the user. The language is littered with entirely inconsistent behavior and choices.