Without taking a position on the proposed change (I haven't thought it through yet), I will note the current behavior is consistent with the documentation.
Reading http://www.jsoftware.com/help/dictionary/d600n.htm we see that m"(-r) y is defined to be m"(0>.(#$y)-r)"_ y , so Raul's observation is justified [1], and then we see that f"n is f"(3$&.|. n) so your latter observation is justified (a relevant example is also given) [2]. Put another way: ] n=:3$&.|. N=: _1 1 NB. Rule 1: enforce exactly 3 ranks: mr,ldr,rdr 1 _1 1 ] r=: (0>n)}n,:_ NB. Rule 2: send negatives to infinity 1 _ 1 r-: f"N b.0. NB. Implementation consistent with documentation? 1 -Dan [1] The reason negative ranks are covered with unbounded ranks is precisely because their actual values depend on (the rank of) the inputs, which of course can vary from invocation to invocation, and in certain cases (like f"N b.0) aren't even present. And since "_ is a no-op (never changes the result of a verb), it can always serve as a placeholder (this is why it is reasonable that e.g. *:^:_1 or (* + %) have unbounded rank when queried with b. even though they're obviously & permanently scalar). Mnemonically, it's nice that _ even looks like a little placeholder ("Fill in the _____"). [2] I think it's been discussed in detail before (on these Forums or elsewhere), but off the top of my head, the reason for the &.|. Is so that the right dyadic rank is consistent with the monadic rank. This is because monads are often a special case of the dyads, ie monad = default&dyad (witness % or #. etc). More generally, ambivalent verbs often try to take the "same kind of argument" on the right, whether monad or dyad, and so of course use "the same kind of rank" on the right. This can feel weird in certain cases, like data fwrite filename instead of filename fwrite data , until you start recognizing and appreciating J's overall consistency & compare the expression to, e.g. fread filename. BTW, your proposed change would not be backwards compatible. But since it's a rare enough circumstance, that shouldn't be a barrier if we decide it is useful. Please excuse typos; composed on a handheld device. -----Original Message----- From: Zsbán Ambrus <[email protected]> Sender: [email protected] Date: Wed, 10 Nov 2010 11:40:46 To: Programming forum<[email protected]> Reply-To: Programming forum <[email protected]> Subject: Re: [Jprogramming] Atop u...@v with v of negative monadic rank On Wed, Nov 10, 2010 at 6:14 AM, Raul Miller <[email protected]> wrote: > ]"1 b.0 > 1 1 1 > ]"_1 b.0 >___ That alone wouldn't be bad if it's documented, but f=: ;"_1 1 'ab' f i.2 3 +-+-----+ |a|0 1 2| +-+-----+ |b|3 4 5| +-+-----+ 'ab' ]...@f i.2 3 +-+-----+ |a|0 1 2| +-+-----+ |b|0 1 2| +-+-----+ +-+-----+ |a|3 4 5| +-+-----+ |b|3 4 5| +-+-----+ f b. 0 1_ 1 (On j602-64 amd64-linux.) I hereby propose that this behaviour is changed so that the rank of f above is considered either (1_1 1) or (1__) -- while calling the verb as a diad should still behave the same as it does now. Ambrus ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
