[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

consider exclusive index ranges

This page is part of the web mail archives of SRFI 47 from before July 7th, 2015. The new archives for SRFI 47 contain all messages, not just those from before July 7th, 2015.

Title: consider exclusive index ranges

> One more comment: Why specify bounds as two-element lists rather than as
> pairs? It seems a bit strange to allocate two cons cells when the data
> is known to always contain exactly two values. Is there some reason why
>     (make-array '#(foo) '(0 2) '(0 2))
> is preferable to
>     (make-array '#(foo) '(0 . 2) '(0 . 2))

Allow both. Typing (0 . 2) all the time is more tedious. (0 2) is just as easy
to read (easier in fact, I think) and easier for the programmer to write.

My point is to consider the use of exclusive ranges instead of inclusive
ones. My instinct is that things like array slicing and subsetting will
compose better using exclusive ranges.

Consider exclusive:

  (let* ((n ...)
         (mid (/ n 2))
         (a (make-array default (list 0 n)))
         (first-half (array-slice arr (list 0 mid)))
         (second-half (array-slice arr (list mid n)))))
versus inclusive:

  (let* ((n ...)
         (mid (/ n 2))
         (a (make-array default (list 0 (- n 1))))
         (first-half (array-slice arr (list 0 (- mid 1))))
         (second-half (array-slice arr (list mid (- n 1))))))