4 ms·
Lisp has had vectors and hash tables considerably longer than Python has existed. It's a general purpose language, and any competent Lisper uses the right data
by User23 4y ago
Lisp has had vectors and hash tables considerably longer than Python has existed.
It's a general purpose language, and any competent Lisper uses the right data structure for the job. As it happens, the cons tree (not a list, a tree!) is the right data structure for representing Lisp code. It's not necessarily the right data structure for representing other non-code data that Lisp code is working with.
- sillysaurusx 4y agoYes, but cdr(vector(1, 2, 3)) throws an error in almost all lisp implementations. Which means you can’t use the classic algorithms on them, like map. It’s worth considering carefully why you feel cons cells are so important for lisp code. Nested vectors are trees. Why not represent (define (foo x) x) as [define, [foo, x], x] ?
- User23 4y ago> Yes, but cdr(vector(1, 2, 3)) throws an error in almost all lisp implementations. Which means you can’t use the classic algorithms on them, like map. What? MAP[1] works just fine with vectors and other sequence types. Are you somehow surprised that MAPCAR doesn't? The name makes it pretty obvious I'd think. I'm starting to think you just lack familiarity with the language that you're criticizing. [1] http://clhs.lisp.se/Body/f_map.htm http://clhs.lisp.se/Body/f_map.htm
- sillysaurusx 4y agoSuppose Lisp were forced to abandon cons cells and could only use vectors to represent code. What's the disadvantage? My retort to you would be "I'm starting to think you like complexity for the sake of it," but debates are much more fun when we're both genuinely interested in the other's perspective.
- User23 4y agoVariable length vectors are observably more complex than 2-tuples. And forgive me, but you are giving me the impression that you are trolling rather than debating. Suppose Lisp were forced to abandon cons cells and could only use SQL tables to represent code. What's the disadvantage? Anyhow, by all means write your Python vector based Lisp dialect. It's no skin off my teeth. Maybe it really is superior and you'll be the next Rich Hickey.
- math-dev 4y agocons is a recursive data structure. it’s not discussed much here in the comments, but a lot of its useability comes from that fact - you can write elegant recursive algorithms with cons as your data structure with vectors that doesn’t work UNLESS you add a bit of overhead (which most optimising programs may do since for many cases vectors can be more performant)
- User23 4y agoAnd some Lisp implementations optimize some cons lists into vectors. The technique is called CDR encoding[1]. It's my understanding that at least the latest generation of modern CPUs actually have optimized instructions for tagged 64 bit pointers too, so this can be implemented efficiently on current hardware just as it was on Lisp machines! Of note though is that mutability complicates things, as usual. [1] https://en.wikipedia.org/wiki/CDR_coding https://en.wikipedia.org/wiki/CDR_coding
- math-dev 4y agoThanks for sharing this link, very useful reading
- lispm 4y agoIt's just that since decades Lisp implementations don't do this, since most implementors don't see it providing much advantage (in speed or size) and it complicates the implementation.
- sillysaurusx 4y agoIncidentally, that link proves the point: > In the presence of mutable objects, CDR coding becomes more complex. If a reference is updated to point to another object, but currently has an object stored in that field, the object must be relocated, along with any other pointers to it. Not only are such moves typically expensive or impossible, but over time they cause fragmentation of the store. This problem is typically avoided by using CDR coding only on immutable data structures. This is exactly what I've been saying. Thank you for providing a formal reference to the idea. (I'm a bit confused how we wound up talking past each other, since my original proposal was identical to CDR coding on immutable cons cells.)