by throwaway7645 · 9y ago · 0 comments
Let me compare for example Lisp lists with Python lists. Lisp lists are in a way more low-level, lacking useful things as slices. Sure you can always write a function to do a slice, but the point is many useful functions are missing from the standard libraries. I tried to learn Common Lisp and Clojure (I like the language more than Python) but I was never more productive in it than in Python for this reason.
This year, I have actually done some AoC in Haskell, and it's a similar deal as with Lisp. There are plenty libraries, but they just don't work as well together. An example: I needed a queue. So I used Data.Seq, but, there is no pop() function. No big deal, for sure, but annoying. Another example: I wanted to put list or set into a hash table, but unfortunately, these are not defined as instances of Data.Hashable.
It's actually debatable whether list should be Hashable by default. Sure it would be practical, but someone could complain about the hashing implementation. And that's why Python is going to beat Haskell on these problems, where you simply don't want to worry about thousands of those little things.
I was actually thinking about building myself a "pythonic" Haskell prelude which would have similar design to Python standard libraries and the same attention to consistency.
Clojure is much much more usable than CL.
I wrote full-time Clojure for two years, and did all of last year's Advent of Code in Clojure. In my entire life, I have never once written a line of Java and I have no idea the details of its standard library. That's how well-encapsulated Clojure is.
Common Lisp provides the function SUBSEQ for primitive slices.
CL-USER 66 > (subseq '((a 1 x0) (b 2 x1) (c 3 x2)) 1 2)
((B 2 X1))
For some more slice functionality you could use the CL-SLICE lib.It's also not too difficult to write. I wrote a multi-dimensional slice like Take in Mathematica:
CL-USER 58 > (take '((a 1 x0) (b 2 x1) (c 3 x2))
'(1 3)
'(1 3))
((2 X1) (3 X2))
CL-USER 59 > (take '((a 1 x0) (b 2 x1) (c 3 x2))
-2)
((B 2 X1) (C 3 X2))
CL-USER 61 > (take '((a 1 x0) (b 2 x1) (c 3 x2))
:all
'(1 2))
((1) (2) (3))
CL-USER 62 > (take '((a 1 x0) (b 2 x1) (c 3 x2))
'(1 2)
:all)
((B 2 X1))
CL-USER 65 > (take '((a 1 x0) (b 2 x1) (c 3 x2))
-2
-2)
((2 X1) (3 X2))
with steps: CL-USER 71 > (take '((a 1 x0 y0) (b 2 x1 y1) (c 3 x2 y2))
:all
'(1 4 2))
((1 Y0) (2 Y1) (3 Y2))Your view of Common Lisp seems to be created more by assumptions and not so by actual real limitations.
Strings:
CL-USER 10 > (subseq "xxfoobarxx" 2 8)
"foobar"
Any vector: CL-USER 11 > (subseq #(10 30 20 100 50 30 20 20) 2 8)
#(20 100 50 30 20 20)
Bitvector: CL-USER 12 > (subseq #*10101010010101001010101 2 8)
#*101010Actually, it does.
Perhaps "viewl :: Seq a -> ViewL" a could be used as pop.
> I wanted to put list or set into a hash table, but unfortunately, these are not defined as instances of Data.Hashable.
Are you using the "hashable" package? There does seem to be an instance for lists (when the elements of the list are themselves hashable):
> Hashable a => Hashable [a]
OK, I stand corrected on Hashable, apparently what I said is not true for neither lists or sets.