Open greimel opened 1 month ago
In Julia end
is parser level syntax. There is no way we can influence what it does in a package, as we can't see that code at all unless you use macros for everything.
But the good news is DD implements type level begin and end with Begin
and End
, and these will work in way more places than base end
. Like in view
.
I see. A big warning in the README/docs would be nice (did I miss it?). Using begin/end
can lead to bugs that are pretty hard to find.
(I like your package very much btw!)
Yeah I just haven't documented it well, and its quite new. If you want to add it to the docs and the readme that would be very helpful.
What we have now is just docs for Begin
and End
, they could also have examples, but at least give you the API definitions:
help?> End
search: End end endswith ENDIAN_BOM append! QuoteNode getindex setindex! prevind prepend! expanduser seekend nextind checkindex parentmodule parentindices isdefined LinearIndices @isdefined eachindex
End <: Position
End()
Used to specify the end index of a Dimension axis, as regular end will not work with named dimensions. Can be used with : to create a BeginEndRange or BeginEndStepRange.
Also used to specify lookup values correspond to the end locus of an interval.
help?> Begin
search: Begin begin disable_sigint reenable_sigint
Begin <: Position
Begin()
Used to specify the begin index of a Dimension axis, as regular begin will not work with named dimensions.
Can be used with : to create a BeginEndRange or BeginEndStepRange.
But you're right, discoverability is important as this can lead to bugs. Its just one of those things that once you realise A[1, end]
is just a dumb built in coversion to A[1, lastindex(A, 2)]
you would never try it again on a DimArray. But before that it seems like a horrible bug.
Hmm, do Begin
and End
work with regular abstract arrays as well? That would be pretty interesting to have for me - wouldn't want to accidentally use the wrong thing when dealing with mixtures of dimarrays and regular arrays.
Yes mostly they will work with regular arrays too. Possibly slightly more widely if you construct them as Begin()
and End()
.
The order of arguments matters when indexing with
end
It uses the last index in the first dimension (5), not in the
Y
dimension.