Skip to content

confusing docs for range #31707

@ssfrr

Description

@ssfrr

As of 1.1 the docs for range say:

    range(start[, stop]; length, stop, step=1)

Given a starting value, construct a range either by length or from start
to stop, optionally with a given step (defaults to 1, a UnitRange). One of
length or stop is required. If length, stop, and step are all specified, they
must agree.

Based on the docs it seems like range(1, 5) should be valid, but it throws the error that "at least one of length or step must be specified".

From the doc header it looks like step is specified by default, so it seems weird that range(1, 5) would be different from range(1, 5; step=1). Also it makes it look like stop can be specified either positionally or by keyword, so I'd think specifying positionally would satisfy that "One of length or stop is required".

Based on the discussion in #28708 this seems like the intended behavior, but it seems like allowing range(a, b) would be consistent with the docs and somewhat simpler as just meaning the same thing as a:b.

This confusion popped up in a recent PR in DSP.jl.

(@galenlynch)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions