Re: Pass by Reference
- Posted by dcuny Jan 14, 2015
- 2082 views
petelomax said...
- P_REG, size, 1..8|16
- P_VAR, size, N, type
- P_MEM, size, scale, index, base, offset
- P_LBL, lblidx
- P_IMM, atom
With disparate values, why would you want to use multiple returns here? Wouldn't this make more sense (ignoring keywords, of course):
sequence result = get_operand() switch result[1] do case P_REG then { op, size, flags } = result case P_VAR then { op, size, n, type } = result case P_MEM then { op, size, scale, index, base, offset } = result case P_LBL then { op, lblidx } = result case P_IMM then { op, atom } = result end case
When different kinds of things are returned, using a sequence and the de-sequence operation makes sense. I'm certainly not advocating getting rid of that.
petelomax said...
PS: In Phix, you can say {a,b[1],{c[2..3],{d,?,e[4]}}} = f() no problem, if you want to. Pick a compile-time error out of that.
No compile time error to be had, if f() is returning a single value. No runtime error, either... Assuming f() is returning a sequence.
On the other hand, if you'd written:
a,b[1],{c[2..3],{d,?,e[4]}} = f()
and f() doesn't returns two values, you've got a compile time error.
- David