My main motivation for the proposal is related to a favorite adverb:
Y =: (&({::))(@:])
but it turns out that
X =: (&(>@{))(@[)
is faster and has the convenience of easily selecting multiple items from what
is usually a record format for either argument, as well as not failing on a
scalar argument.
so >@{ is a better {:: for many common applications.
________________________________
From: Raul Miller <[email protected]>
To: Programming forum <[email protected]>
Sent: Wednesday, September 19, 2018 11:31 AM
Subject: Re: [Jprogramming] should 0 {:: scalar return that scalar instead of
being a length error?
If we're going to talk about composites, and unboxing the first item,
I would imagine that things like >@{. should be considered.
Note that this approach has another advantage - we don't have to worry
about whether the word to its left is numeric (which can happen if
this verb gets used in an adverbial or conjunctive context).
Thanks,
--
Raul
On Wed, Sep 19, 2018 at 11:23 AM 'Pascal Jasmin' via Programming
<[email protected]> wrote:
>
> ''&{:: doesn't do the same as 0&{:: in the general case though.
>
>
> In favour of the proposal, think of how difficult life/J would be if {. }. {:
> }: didn't "work" with scalars.
>
> from the dictionary entry to take
>
> "if y is an atom, it is replaced by ((#x)$1)$y"
>
> 2 2 {. 4 NB. 2 2 {. 1 1 $ 4
> 4 0
>
> 0 0
>
> where atoms get special boosted powers compared to "undershaped" lists
>
> 2 2 {. 4 4
> |length error
>
>
> 2 2 {. ,: 4 4
> 4 4
> 0 0
>
>
> An argument against the proposal is that virtually all length errors have a
> sensible alternative result. And "fixing" this one enhances the argument for
> fixing all of them.
>
> 2 3 u 1 2 3 could be equivalent to u/@:,:
> ________________________________
> From: Raul Miller <[email protected]>
> To: "[email protected]" <[email protected]>
> Sent: Wednesday, September 19, 2018 10:06 AM
> Subject: Re: [Jprogramming] should 0 {:: scalar return that scalar instead of
> being a length error?
>
>
>
> Note also that ‘’ {:: 0 works, and also the typical case left argument for
> {:: might be a boxed list.
>
> —
> Raul
>
> On Tuesday, September 18, 2018, Henry Rich <[email protected]> wrote:
>
> > By all means put it on the list.
> >
> > You are selecting along 1 axis from an argument that has 0 axes, which
> > makes the length error reasonable.
> >
> > The question is, why does 0 { 0 not fail? Answer: because of the fine
> > print in the definition. (0 { y) selects item number 0, and an atom has a
> > single item, itself.
> >
> > (<0) { 5 fails, rightly, for the same reason 0 {:: 5 fails.
> >
> > It is important to get these edge cases right, and there's most often only
> > one right way, so my assumption is that Roger did it the right way. I'll
> > have to think it over.
> >
> > Henry Rich
> >
> >
> >
> > On 9/18/2018 8:05 PM, 'Pascal Jasmin' via Programming wrote:
> >
> >> I can add to request list.
> >>
> >> The argument for is that it is a source of "needless" errors. The error
> >> applies also if there is a nested box structure, but the top level is an
> >> atom.
> >>
> >> Perhaps there is a performance reason against it.
> >>
> >> I would doubt that existing code in the wild relies on the error for any
> >> other purpose than to convert the scalar into a list of 1 item.
> >> ----------------------------------------------------------------------
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> >>
> >
> >
> > ---
> > This email has been checked for viruses by AVG.
> > https://www.avg.com
>
> >
> > ----------------------------------------------------------------------
> > 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