Thanks for all the details -- it really makes the point I was trying to
make.

On Apr 29, 2020, at 08:33, Christopher Barker <[email protected]> wrote:

> > I've wondered about Linked Lists for a while, but while there are many
> versions on PyPi, I can't find one that seems to be mature and maintained.
> Which seems to indicate that there isn't much demand for them.
>

Isn't much demand for a *generic* linked list. It would probably be a good
recipe though -- so users could have a starting point for their custom
version.

Also -- as you point out, while it may be useful for a linked list to be a
Sequence, the API shouldn't be only that -- it'd almost defeat the purpose
of a linked list at all.

-CHB





> I think there’s lots of demand for them, but there are so many different
> variants that can’t substitute for each other (try taking any nontrivial
> sample code using Haskell’s single-linked, no-handle, immutable
> tail-sharing list and rewriting it with C++’s doubly-linked handled mutable
> list, or vice-versa), and most of the key operations fit so poorly with
> Python’s sequence/iterable API, and they’re all so easy to build, that
> people just build the one they need whenever they need it.
>
> I do have a few different linked lists in my toolbox that have come up
> often enough that I stashed them (an immutable cons, a handled
> double-linked list, a cffi wrapper for a common style of C
> internally-linked lists, probably others), but half the time I reach for
> one I have to modify it anyway, so I haven’t bothered to turn them into a
> package I just import and use.
>
> And, while I did add the whole (Mutable)Sequence API to each one (because
> it’s convenient for debugging and REPL exploration to be able to list(xs),
> or to get a repr that’s written in terms of a from_iter classmethod so I
> can eval it back, etc.), I usually don’t use that API for anything but
> debugging. When you’re dealing with linked lists, you usually need to deal
> with the nodes directly. For example, one big reason to use linked lists is
> constant-time splicing, but you can’t splice in constant time if all you
> have is the head/handle and/or an opaque iterator that only knows how to go
> forward; you need the node before the splice point (or, for doubly-linked,
> after is fine too). Another reason to use (Lisp/Haskell-style) linked lists
> is that they automatically release nodes as you iterate unless you keep a
> reference to the head, but that’s clumsy to do with Python-style APIs. And
> so on.
>
>
>

-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/5QCUQDP7KYKFC2PUCGZGUUYI22S7R7XB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to