I've been thinking about this, and I am slightly convinced. That said, I would be interested in seeing a real example where this matters.
Specifically: in this example you are getting an empty noun with a rank lower than what you should otherwise expect. That suggests one of two likely treatments: (a) The unintended shape causes an error. (b) The unintended shape gets treated as an empty result. (If the programmer has been coding defensively (which is to say not expecting deep understanding of the mechanisms of connected components) then I do not see how your proposal changes the picture.) It could of course - but that's why I'd like to see a real example. (Of course, none of this is an excuse for not testing code against boundary conditions.) Thanks, -- Raul On Fri, Dec 15, 2017 at 4:34 AM, Erling Hellenäs <[email protected]> wrote: > Hi all ! > > I will try to explain this example. > > $(i.5) (2 1$ =)"1 0 [i.2 > 2 2 1 > $(i.5) (2 1$ =)"1 0 [i.1 > 1 2 1 > $(i.5) (2 1$ =)"1 0 [i.0 > 0 2 1 > $(i.1) (2 1$ =)"1 0 [i.0 > 0 2 1 > $(i.0) (2 1$ =)"1 0 [i.0 > 0 > f=: 4 : 'try. 2 1$x=y catch. 2 1$_1 end.' > $(i.0) f"1 0 [i.0 > 0 2 1 > > As we can see , in this expression: > > $(i.0) (2 1$ =)"1 0 [i.0 > > the expression (2 1$ =) throws an error, which the interpreter hides and > replaces with i.0 > > As we can understand, taking a 0-cell from the right argument, i.0 , is not > possible, so what J does is to use a default element, 0, as the 0-cell > taken. This is needed to determine the type and shape of the result. > However, this is highly questionable behaviour, since the default element > might not be a valid value and with a valid value the result might well be > of another type and shape. It is also questionable because the calculation > should not occur and doing it anyway might well cause side effects like a > patients death or a plane crash. > > (i.0) (2 1$ =) [0 > |length error > | (i.0) (2 1$=)[0 > > This resulting length error is hidden. The questionable result i.0 replaces > it. > > With knowledge about this strange internal behaviour of J you can create a > function like f and get the result you want in the particular case. > > Without this knowledge you will probably not understand why you get i.0 as > the result. You will have a fuzzy understanding of how rank works. Rank, > which is often used implicitly and which is fundamental for the > understanding of J. > > The usage of the default element as 0-cell is something I think every J > programmer have to learn and remember. I think it should be described in the > dyadic rank dictionary page and in the dictionary pages of all verbs which > implicitly use dyadic rank, the non-scalar dydic verbs for which one rank is > 0, if any. > > I think the length error should not be hidden. > > Cheers, > > Erling Hellenäs > > > > > Den 2017-12-13 kl. 17:12, skrev Erling Hellenäs: >> >> Hi all ! >> >> It seems some related info did not make it into my blog and it is not >> needed in my manual. My tweets about this are advertently cryptic: >> >> -I found some interesting features of the real #J dyadic rank operator. >> >> -Let's say the rank is zero and the argument is empty, how do you find the >> resulting type and shape? >> >> -Nothing can not be scalar, which can be executed to find the rank, can >> it? >> >> -If you execute the verb on a scalar default object, what do you do if you >> get an error? Which rank and type will you use? >> >> More clearly: >> >> I have found that J determines the type and shape of the result when both >> arguments of the dyadic array operation helper program are empty by >> executing the verb against default objects of both arguments. If the result >> is an error, J hides this error. The result then gets another rank than it >> should. The rank is then not consistent with the rank obtained when the >> arguments are not empty. >> >> This means that if you have a theory of how rank works, the theory will be >> falsified by some of the results you get, which means your understanding >> will most probably be fuzzy. You have to test all cases in the terminal to >> verify that it indeed works when one or the other argument, or both, are >> empty. >> >> According to my notes, this is such a case: >> >> $(i.0) (2 1$ =)"1 0 [i.0 >> 0 >> $(i.1) (2 1$ =)"1 0 [i.1 >> 1 2 1 >> >> Cheers, >> >> Erling Hellenäs >> >> >> Den 2017-12-13 kl. 16:24, skrev Erling Hellenäs: >>> >>> This blogpost also contains related information. >>> https://erlhelinfotech.wordpress.com/2016/08/17/jwithatwist-scalar-operations/ >>> >>> /Erling >>> >>> >>> Den 2017-12-13 kl. 15:46, skrev Erling Hellenäs: >>>> >>>> It seems you didn't read the parts of my manual I referenced. /Erling >>>> >>>> >>>> Den 2017-12-13 kl. 14:39, skrev Raul Miller: >>>>> >>>>> On Wed, Dec 13, 2017 at 3:46 AM, Erling Hellenäs >>>>> <[email protected]> wrote: >>>>>> >>>>>> I doubt you can find reasonably accurate descriptions of this >>>>>> functionality >>>>>> (these four helper programs) anywhere else. >>>>> >>>>> This suggests to me that you have not read >>>>> >>>>> http://www.jsoftware.com/help/dictionary/dictb.htm >>>>> nor >>>>> http://www.jsoftware.com/help/dictionary/dicta.htm >>>>> >>>>> I am surprised how many people have not read the reference manual - >>>>> not just in the J community but among technical people in general. >>>>> >>>>> I really don't know what to make of this. >>>>> >>>> >>> >> >> ---------------------------------------------------------------------- >> 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
