-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Open
Labels
collectionsData structures holding multiple items, e.g. setsData structures holding multiple items, e.g. setsdocsThis change adds or pertains to documentationThis change adds or pertains to documentationiterationInvolves iteration or the iteration protocolInvolves iteration or the iteration protocol
Description
The doc strings are already in the Manual, but the Interfaces page does not mention them:
-
https://docs.julialang.org/en/v1/base/collections/#Base.rest
-
https://docs.julialang.org/en/v1/base/collections/#Base.split_rest
They should be added to the Interfaces page, as user-defined collection types might wish to add methods for performance.
Side note: there's another function that part of the destructuring interface, although it is not public: indexed_iterate
. Perhaps it, too, should be public?
Example of the lowering of destructuring:
julia> function f(x)
(a, b, c...) = x # lowers using `rest`
(m, n..., p, q) = c # lowers using `split_rest`
n
end
f (generic function with 1 method)
julia> code_lowered(f)
1-element Vector{Core.CodeInfo}:
CodeInfo(
1 ─ %1 = dynamic Base.indexed_iterate(x, 1)
│ a = Core.getfield(%1, 1)
│ @_4 = Core.getfield(%1, 2)
│ %4 = @_4
│ %5 = dynamic Base.indexed_iterate(x, 2, %4)
│ b = Core.getfield(%5, 1)
│ @_4 = Core.getfield(%5, 2)
│ %8 = @_4
│ c = Base.rest(x, %8)
│ %10 = c
│ %11 = dynamic Base.indexed_iterate(%10, 1)
│ m = Core.getfield(%11, 1)
│ @_3 = Core.getfield(%11, 2)
│ %14 = c
│ %15 = @_3
│ %16 = dynamic Base.split_rest(%14, 2, %15)
│ n = Core.getfield(%16, 1)
│ %18 = builtin Core.getfield(%16, 2)
│ %19 = dynamic Base.indexed_iterate(%18, 1)
│ p = Core.getfield(%19, 1)
│ @_3 = Core.getfield(%19, 2)
│ %22 = @_3
│ %23 = dynamic Base.indexed_iterate(%18, 2, %22)
│ q = Core.getfield(%23, 1)
│ %25 = n
└── return %25
)
PatrickHaecker
Metadata
Metadata
Assignees
Labels
collectionsData structures holding multiple items, e.g. setsData structures holding multiple items, e.g. setsdocsThis change adds or pertains to documentationThis change adds or pertains to documentationiterationInvolves iteration or the iteration protocolInvolves iteration or the iteration protocol