3 ms·
> Sure you can always write a function to do a slice Common Lisp provides the function SUBSEQ for primitive slices. CL-USER 66 > (subseq '((a 1 x0) (b 2 x1)
by lispm 10y ago
> Sure you can always write a function to do a slice
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))
- js8 10y agoAs I said, I am sure I can do it or find it in some library. But the integration of the APIs that Python has is missing. For example, I doubt your subseq works on strings (or bytestrings). But as I said, Python is IMHO the state of the art when it comes to PL usability (people have spent a lot of time thinking about use cases, sometimes at the expense of elegance or versatility), so no shame here.
- ScottBurson 10y ago> I doubt your subseq works on strings (or bytestrings) Actually, it does.
- lispm 10y ago> For example, I doubt your subseq works on strings (or bytestrings) 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) #*101010