robpike/ivy

possible order of evaluation bug

rsc opened this issue · 1 comments

rsc commented

Here is a way to test order of evaluation.

# Order of evaluation
tags = 0 rho 0
op f tag = tags; tags = tags, tag; 1
op order x = x = tags; tags = 0 rho 0; x
m = 1 1 rho 0
order (f 1) + (f 2)
order m[f 1; f 2]
order +/ (f 1) (f 2)
	2 1
	2 1
	1 2

It shows that in (f 1) + (f 2), (f 2) runs first.
And in m[f 1; f 2], f 2 runs first, which I preserved from the binary case.
But it also shows that in +/ (f 1) (f 2) and g (f 1) (f 2), (f 1) runs first.

This confused me because to use a complex
expression multiple times,
the idiom from APL is something like

m+m=complex thing

but it turns out to use it multiple times in a vector its the other way around:

+/ (m=complex thing) m 

Is this correct?
Is it documented somewhere?

rsc commented

Occurred to me I could look at TryAPL, which behaves differently from Ivy. So probably this is a bug?

It's weirder than I thought, too. TryAPL:

      x ← 1
      x (x←2)
2 2
      (x←3) x
3 2

Ivy:

x=1

x (x=2)
2 2

(x=3) x
3 3

(x=4) x (x=5)
4 5 5