Re: range-reverse missing from spec Wolfgang Corcoran-Mathe 06 Jul 2021 18:56 UTC

On 2021-07-06 14:00 -0400, John Cowan wrote:
> On Tue, Jul 6, 2021 at 12:12 PM Wolfgang Corcoran-Mathe <xxxxxx@sigwinch.xyz>
> wrote:
>
> * range-reverse may return an expanded range.
> >
>
> How's that?  Or do you mean that it returns a compact range on a compact
> range and an extended range on an extended range, which is what I would
> expect?  (Reverse the start and end values and negate the step in the first
> case, reverse the contents in the second case.)

No, sic.  As we discussed back in September[1], many of the range
operations are expected to work via composition of indexer functions,
with the range being expanded only when the number of compositions
reaches a certain threshold.  range-reverse was actually the poster
child for this discussion, though, ironically, it was missing from the
spec the whole time; here's the sample implementation:

(define (range-reverse r)
  (assume (range? r))
  (%range-maybe-vectorize           ; expand the range if composition
   (raw-range (range-start-index r) ; has reached threshold
              (range-length r)
              (lambda (n)
                ((range-indexer r) (- (range-length r) 1 n)))
              (+ 1 (range-complexity r)))))  ; bump complexity

We could do things differently, of course.  In any case, I hope we
don't have to rerun the lengthy discussion of this issue from last
fall.

[1] https://srfi-email.schemers.org/srfi-196/msg/15115132/

--
Wolfgang Corcoran-Mathe  <xxxxxx@sigwinch.xyz>

"A LISP programmer knows the value of everything, but the cost
of nothing." --Alan J. Perlis