Re:Why is Common Lisp not the most popular programming langu...
by o11c on Wednesday February 14, 2024 @06:49PM
(#39377220)
What do a-list/p-list have to do with sharing structure?
If you want shared structure of lists in Python, use `itertools.chain`.
If you want key-value mappings, use a dict. Order is preserved by default nowadays, and conversion to/from an iterable of 2-tuples is trivial.
Re:Why is Common Lisp not the most popular programming langu...
by thaumasiotes on Wednesday February 14, 2024 @07:32PM
(#39377586)
> If you want shared structure of lists in Python, use `itertools.chain`.
That would involve zero shared structure. itertools.chain is just an iterator that iterates one iterable and then, instead of declaring that it's done, goes on to iterate another one.
Shared structure between lists means that two lists refer to some of the same regions of memory.
Re:Why is Common Lisp not the most popular programming langu...
by o11c on Wednesday February 14, 2024 @08:49PM
(#39378176)
And multiple `itertools.chain` instances pointing to the same list chunk(s) also use sharing.
Re:Why is Common Lisp not the most popular programming langu...
by thaumasiotes on Wednesday February 14, 2024 @10:31PM
(#39378785)
OK, that is true, but that approach would have the significant downside that you can't pass over a list more than once.
Re:Why is Common Lisp not the most popular programming langu...
by d0mine on Thursday February 15, 2024 @02:22PM
(#39387212)
Iterators can be shared in Python e.g.,
here's a well-known grouper recipe (traverse `it` iterator in chunks of `N` items each):
zip(*[it]*N)
Example: >>> L = [1, 2, 3, 4]
>>> *zip(*[iter(L)]*2),
((1, 2), (3, 4))
Here's the single result of the iter() call is shared. The purpose is to show that iterator can be shared in principle (ignore other aspects of the code).
In idiomatic Lisp, it's rather common to search a list for a value, cdr it, and cons that cdr to the collection you're building up. Python has nothing like that, because what I said makes no sense in terms of Python lists.