Unexpected value of expression involving assignment

Viewed 49

I saw this logic and wonder why the result is one rather than zero:

      P ← 1 1 0
      Q ← 0 0 1
      ∨/ P ∧← Q
1

On the other hand the following results in zero:

      P ← 1 1 0
      Q ← 0 0 1
      ∨/ P ← P ∧ Q
0

I'm using Dyalog APL 16.

1 Answers

The result of any assignment is the value to the right of the assignment arrow, so P ∧← Q returns Q while P ← P ∧ Q returns P ∧ Q which is also the new value assigned to P, per the documentation:

Assignment (Modified)   {R}←Xf←Y

(…)

R is the “pass-through” value, that is, the value of Y. If the result of the derived function is not assigned or used, there is no explicit result.

To get the performance benefit of in-place modification, while using the new value inline, you can write ∨/ P ⊣ P ∧← Q

Related