On Wed, Feb 20, 2008 at 11:10:47PM -0800, [EMAIL PROTECTED] wrote:
Adding an element to a Python list is simply calling the append method. I just noticed that appending to a Scheme list means I have to walk the cons tree since I don't know the length of it.
Very different operation. Scheme's append doesn't modify the original list. Python "list" append adds the element to the existing list. This is more like scheme's "append!" call.
<whine>Picking out say the third element or deleting the 4th element suddenly take a few extra brain cells where with Python lists they were trivial. </whine>
Yes, although, to be Frank, you don't have any choice in the matter, at least if your going to implement something resembling lisp. The copying append is important, because it doesn't modify the original list. Much code will depend on this behavior. The user can also modify it if they wish, and they are expecting it to behave as a linked list. There are tradeoffs between linked lists and arrays, and decent programmers will use the right one in a given case. But, they're going to need to get the one that they ask for. Remember, scheme does have a vector type which is a lot more like Python lists. Common lisp arrays have even more functionality, including slices. David -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg
