Fork me on GitHub
#clojure-dev
<
2023-02-02
>
dmiller14:02:51

The thing about going through every single of line code-- In the definition LongChunk we see

public Object nth(int i){
        return start + (i * step);
    }

    public Object nth(int i, Object notFound){
        if(i >= 0 && i < count)
            return start + (i * step);
        return notFound;
    }
This allows nth(int) to return a value even when out of range, either negative or way past the end of the range. Should it throw an exception in such cases? Or shall we just let it be giddy with power? (I believe the latter is forbidden by the comment on clojure.core/nth: "if index out of bounds, ... nth throws an exception unless not-found is supplied"

dmiller14:02:01

One reason I ask is I'm not sure if LongChunk.nth(int) every surfaces through to clojure.core/nth.

Alex Miller (Clojure team)15:02:04

I don't think this is user exposed (ie not connected to clojure.core/nth)

Alex Miller (Clojure team)15:02:07

it's definitely not user exposed, but I would need to review how chunks are used to see if it's sufficiently guarded

Alex Miller (Clojure team)16:02:09

this is only used internally and guarded by the chunk count, so don't think it's an issue

dmiller18:02:42

Cool. Thx.