A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/tpapp/cl-slice/issues/3 below:

Unexpected behaviour · Issue #3 · tpapp/cl-slice · GitHub

After a bit of testing, I've found that cl-slice exhibits unexpected behaviour in some cases and makes a few easy tasks unnecessarily difficult.

  1. t selects all subscripts, according to the manual.

Sometimes, that appears to be more than I asked for:

(let ((my-array (make-array 0 :adjustable t :fill-pointer 0)))
  (loop for x from 0 below 100
        do (vector-push-extend x my-array))
  (format t "This array has length ~a yet the full slice has length ~a.~%"
     (length my-array) (length (cl-slice:slice my-array t))))

Prints

This array has length 100 yet the full slice has length 128.

for me (there are 28 trailing zeros that I did not expect).
2. nil cannot be replaced with an index in cons

To take get anything from the 3rd element on from a list, I can use

(cl-slice:slice '(a b c d e) (cons 2 nil))

While that's convenient because I don't need to pass the length of my data, I do not see the need to make

(cl-slice:slice '(a b c d e) (cons 2 5))

illegal. If the final index of my slice comes from a function, this requires me to check if that index happens to be identical to the length of the list and if so, replace it with nil.
3. (cons start end) is invalid unless start < end, according to the manual

While it's debatable what should happen if the user passes something like (cons 3 1), I think it's clear what (cons 3 3) should result in: nil.

To illustrate why this is a problem, please consider the following case. You're dealing with some data. Maybe it's this:

;; returns (0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361)
(setf data (loop for x from 0 below 20 collect (* x x)))

From those twenty numbers, I want to remove a slice of length 5, starting at the 3rd entry. Easy enough:

(let* ((begin 3) (end (+ 5 begin)))
  (cl-slice:slice data (vector (cons 0 begin) (cons end nil))))

This will seize to work in the corner case where end happens to equal (length data) or begin happens to equal 0.

(let* ((begin 0) (end (+ 5 begin))) ;; does not work
  (cl-slice:slice data (vector (cons 0 begin) (cons end nil))))

(let* ((begin 15) (end (+ 5 begin))) ;; does not work
  (cl-slice:slice data (vector (cons 0 begin) (cons end nil))))

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4