Skip to content

@set with slices or broadcasting #75

Closed
@Jollywatt

Description

@Jollywatt

Hello,
If I understand correctly, we may expect this to work out-of-the-box:

julia> using Accessors, StaticArrays

julia> s = SVector{4}(1:4) # immutable fixed size vector
4-element SVector{4, Int64} with indices SOneTo(4):
 1
 2
 3
 4

julia> @set s[2] += 100 # single indexing works
4-element SVector{4, Int64} with indices SOneTo(4):
   1
 102
   3
   4

julia> @set s[2:3] .+= 100 # broadcasted functions are not recognised
ERROR: UndefVarError: .+ not defined
Stacktrace:
 [1] top-level scope
   @ REPL[257]:1

julia> @set s[2:3] += [100, 100] # slicing fails ungracefully
ERROR: StackOverflowError:

Regarding the first error, the macro expands to something containing Accessors.:.+. We probably need to esc the operator symbol .+ so it gets evaluated to Base.Broadcast.BroadcastFunction(+), but I’m not sure if it’s that simple.

The second error seems like it needs more urgent attention. If s = [1, 2, 3] is a normal vector, @set s[2:3] += [100, 100] works fine, so it seems like this should be supported for static vectors.

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