Closed fzipp closed 1 year ago
Unfortunately, the implementation of disclose depends on the origin.
Isn't there a way to programmatically query whether the origin is 0 or 1 ? In which case the implementation of disclose
could be made in pure ivy.
Isn't there a way to programmatically query whether the origin is 0 or 1 ?
You can query the origin via the )origin
command, but that's not an expression.
I tried iota 1
and (0 iota 1)+1
(*) to get the origin, but both return a vector of length 1, not a scalar, so I can't use them as the index for disclose.
*) because A iota B
returns origin-1 if B not found in A
What's missing first is the equivalent of the quad "operator", and I've been thinking about a good way to provide that. I actually had a prototype working but want to proceed carefully.
Thanks for the response. I assume you mean something like ⎕IO
(index origin).
It just came to me that I can get the origin as a scalar if I add up the result of iota 1
.
The implementations of enclose and disclose in my lib.ivy
are now:
op enclose a = 1 take a 0
op disclose a = a[+/iota 1]
Clever!
@robpike first
does not yet work as expected:
first first box box 3 3 rho iota 9
((0 1 2||
||3 4 5||
||6 7 8))
Expected:
first first box box 3 3 rho iota 9
0 1 2
3 4 5
6 7 8
The documentation I can find is unclear. Maybe the next round will be correct by your understanding.
Thank you, I'm happy with it now.
Glad to hear it. Thanks for the bug reports.
One can implement equivalent operations to APL's monadic ⊂ and ⊃ like this:
Unfortunately, the implementation of
disclose
depends on the origin. Would it perhaps make sense to provide them as builtins?Other names could be
box
ornest
for enclose, andfirst
for disclose.