Swapping the argument does not appear to influence the shape of the result.
The results themselves are different,
UV=:0,(,-@|.)=i.3
foo=: {{ x+ y{UV }}
oof=: {{ y+ x{UV }}
0 0 0 (]F:.foo -: ]F:.foo~) 3 2 _3
0
0 0 0 (]F:.oof -: ]F:.oof~) 3 2 _3
0
That said, focusing on the variant which you described as providing
the desired behavior:
0 0 0 ]F:.oof 3 2 _3
0 0 1
0 1 1
0 1 0
This corresponds to:
3 oof 0 0 0
0 0 1
2 oof 3 oof 0 0 0
0 1 1
_3 oof 2 oof 3 oof 0 0 0
0 1 0
Which, in turn, somewhat matches the value selection mechanism of J's scan:
<\ 3 2 _3
+-+---+------+
|3|3 2|3 2 _3|
+-+---+------+
The difference between fold and scan being that fold reuses the result
of the previous evaluation while scan does not.
I hope this makes sense,
--
Raul
On Tue, Sep 7, 2021 at 2:09 AM R.E. Boss <[email protected]> wrote:
>
> [UV=:0,(,-@|.)=i.3
>
> 0 0 0
>
> 1 0 0
>
> 0 1 0
>
> 0 0 1
>
> 0 0 _1
>
> 0 _1 0
>
> _1 0 0
>
>
> foo=: {{ x+ y{UV }} NB. constructed conform the diagram on
> https://code.jsoftware.com/wiki/Vocabulary/fcap
>
>
>
> $0 0 0 (]F:. foo) 3 2 _3
>
> 3 3 3 3 3
>
> $0 0 0 (]F:. foo)~ 3 2 _3
>
> 3 3 3 3 3
>
>
> foo=: {{ y+ x{UV }} NB. y and x are swapped, counterintuitive
>
>
>
> $0 0 0 (]F:. foo) 3 2 _3
>
> 3 3
>
> 0 0 0 (]F:. foo) 3 2 _3 NB. this is the desired behaviour
>
> 0 0 1
>
> 0 1 1
>
> 0 1 0
>
> $0 0 0 (]F:. foo)~ 3 2 _3
>
> 3 3
>
> Also remarkable is that swapping the arguments seems not to influence the
> result.
> Any clarification?
>
>
> R.E. Boss
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm