# @views bug or expected behaviour?

**URL:** <https://discourse.julialang.org/t/views-bug-or-expected-behaviour/68186>\
**Category:** General Usage\
**Created:** [September 15, 2021, 12:47am UTC](https://discourse.julialang.org/t/views-bug-or-expected-behaviour/68186 "2021-09-15T00:47:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pbellive](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbellive/32/3604_2.png) [@Pbellive](https://discourse.julialang.org/u/Pbellive)\
**Post date:** [September 15, 2021, 12:47am UTC](https://discourse.julialang.org/t/views-bug-or-expected-behaviour/68186/1 "2021-09-15T00:47:48Z")

</div>

Consider the code

```julia
n = 5
z = randn(ComplexF64, n)
x = zeros(n)
y = zeros(n)
i = 2
j = 4
@views x[i:j] , y[i:j] = reim(z[i:j])

```

In julia 1.6.1 this throws the error

```julia
ERROR: syntax: "i:j" is not a valid function argument name around REPL[7]:1

```

Removing the indexing on the LHS gets rid of the error. i.e. the following works:

```julia
@views xx,yy = reim(z[i:j])

```

This seems like a bug to me but before posting an issue I thought I’d ask about it here in case I’m missing the reason why I shouldn’t expect it to work. So, is this a bug, and if not why doesn’t it work?

Thanks, Patrick

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [September 15, 2021, 1:24am UTC](https://discourse.julialang.org/t/views-bug-or-expected-behaviour/68186/2 "2021-09-15T01:24:09Z")

</div>

The error message is pretty unhelpful, I agree, but I think `@views` is doing what you’d expect here. If you expand out the expected result of `@views`, you get:

```julia
julia> view(x, i:j), view(y, i:j) = reim(view(z, i:j))
ERROR: syntax: "i:j" is not a valid function argument name around REPL[21]:1
Stacktrace:
 [1] top-level scope
   @ REPL[21]:1

```

which also doesn’t work.

This doesn’t really have anything to do with views: It’s just the fact that you can’t use a function call as the left-hand side of an `=` assignment in Julia.

Well, actually, you _can_ do that, but that syntax already means something else:

```julia
view(x, i) = ... # this *defines* a new function named `view`

```

so when you try to do `view(x, ...), view(y, ...) = ...` you don’t get the result you’re hoping for.

The good news is that you don’t need to put the `view` annotation on the left-hand side anyway.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [September 15, 2021, 1:52am UTC](https://discourse.julialang.org/t/views-bug-or-expected-behaviour/68186/3 "2021-09-15T01:52:09Z")

</div>

tldr:

> [@rdeits](#):
>
> The good news is that you don’t need to put the `view` annotation on the left-hand side anyway.

* * *

Basically, it doesn’t make sense to do a non-view on the left-hand side when you’re assigning values into an array – what would that even mean? you copied a slice and you assigned into the copy and then nothing happens?

---

<div class="post-metadata">

**Author:** ![Pbellive](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbellive/32/3604_2.png) [@Pbellive](https://discourse.julialang.org/u/Pbellive)\
**Post date:** [September 15, 2021, 8:00pm UTC](https://discourse.julialang.org/t/views-bug-or-expected-behaviour/68186/4 "2021-09-15T20:00:23Z")

</div>

Thanks both of you. This makes sense.
