There's a simple reason why, for instance, >,<2 is ,2. This is that the
verb > has rank 0--it operates only on scalars.
When we feed a list to >, J automatically sees that the rank of the list
(1) is greater than the rank of the verb (0), so it applies > to each
element of the list and then combines the results back into a list. This
is true even of a list of shape 1. The verb > itself only "knows" how to
unbox a single box and could not change this behavior without special
code in the J interpreter.
The same principle works on any shape of box.
$> 1$<2
1
$> 1 1$<2
1 1
$> 5 2 4$<2
5 2 4
$> 5 2 4 $ <3 3$2
5 2 4 3 3
Marshall
On Wed, Oct 02, 2013 at 06:45:19AM -0700, Pascal Jasmin wrote:
> To be clearer, I see more of a problem with > than with }. or {: here.
>
> I understand the reasons for:
>
> > 2; < 2 4 $ i.8
> 2 0 0 0
> 0 0 0 0
>
> 0 1 2 3
> 4 5 6 7
> $ > 2; < 2 4 $ i.8
> 2 2 4
> $ {: > 2; < 2 4 $ i.8
> 2 4
> $ }. > 2; < 2 4 $ i.8
> 1 2 4
>
> I guess that I should completely understand why $2 is not 0 or 1, but I can
> let my pretty little head just consider that a list of 1 and a scalar must be
> different:
>
> $ <2
>
> $ 2
>
> # $ 2
> 0
> $ 2 1
> 2
> $ ,<2
> 1
> $ (i.0),<2
> 1
>
>
> $ >,<2
> 1
>
> I guess that if I can understand the above, I should also understand:
>
> {. > (i.0),<2
> 2
> {. >}. (i.0),<2
> ┌┐
> ││
> └┘
>
> A very good reason for that behaviour is that code that scans a list, should
> expect list items throughout. But there is code such as { {. / that already
> work identically on scalars and 1 element lists.
>
> A naive question is should > also have that capability. To answer myself, I
> can see the reason not to. List items can be avoided whenever list items are
> possible, so the programmer should avoid them when not necessary. Still
> there can be gotchas.
>
> ;/ (i.0),<2
> ┌─┐
> │2│
> └─┘
> ; (i.0),<2
> 2
> $ ; (i.0),<2
> 1
>
>
> ----- Original Message -----
> From: Ric Sherlock <[email protected]>
> To: Programming JForum <[email protected]>
> Cc:
> Sent: Wednesday, October 2, 2013 7:08:28 AM
> Subject: Re: [Jprogramming] strange difference between }. and {:
>
> I think of the distinction as follows:
> }. drops the first item from a list. The result is the rest of the list,
> however many items that may be.
>
> {: takes the last item from a list. The result is a single item, not a list.
>
> Seems logical to me.
>
>
> On Wed, Oct 2, 2013 at 5:17 PM, Pascal Jasmin <[email protected]>wrote:
>
> > I am taking the shape after I have opened the item. I'd expect it (the
> > insides) to be the same whether I got the item from }. or {:
> >
> >
> >
> > ----- Original Message -----
> > From: Roger Hui <[email protected]>
> > To: Programming forum <[email protected]>
> > Cc:
> > Sent: Wednesday, October 2, 2013 12:00:27 AM
> > Subject: Re: [Jprogramming] strange difference between }. and {:
> >
> > Not so strange. }. and {: are not equivalent, even on 2-element lists.
> >
> >
> > On Tue, Oct 1, 2013 at 8:56 PM, Pascal Jasmin <[email protected]
> > >wrote:
> >
> > > $ >@}. 2; < 2 4 $ i.8
> > > 1 2 4
> > > $ >@{: 2; < 2 4 $ i.8
> > > 2 4
> > > ----------------------------------------------------------------------
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm