Brian Schott asked:
>  Is the following behavior predictable 
>  from the Dictionary? 

Yes.  The fundamental rule to keep in mind is the shapes of arguments to the 
dyad must share a common prefix with respect to the
rank of that dyad.  The dyad  +  has ranks  0 0  so its frames include the 
entire shapes of its arguments.  Hence, the shape of
one of its arguments must be a (possibly total) prefix of the shape of the 
other.

In your example cases:

           NB.  Brian's example arguments
           a=:      '' ; 1
           a=:  a,: '' ;~ 1
           a=:  a,  '' ; ''
           a=:  a,  1  ; i.0
           a=:  a,  1  ; i.0 0
           a=:  a,  1 2;i.0 0
           a=:  a,  '' ;1 2
           a=:  a,      10 ;1 2
           
           NB.  Display of examples attempted
           egs =: 4 : ' ''('',(5!:5<''x''),'') + '',5!:5<''y'' '&.>/"1  

           NB.  Display whether the attempted addition
           NB.  succeeded or failed.
           add =:  'ok'"_@:+ :: ('err'"_)&.>/"1

           NB.  Determines whether shapes share a common prefix
           NB.  wrt rank of  +  (i.e.  0 0 0 )
           pfx =:  [: ([: -:&.>/ <.&#&>/ {.&.> ])"1 $&.>           
           
           NB.  Correspondence:  3 columns 
           NB.  0.  example sentence
           NB.  1.  result (ok or err)
           NB.  2.  do arguments share a prefix?
           cor =:  egs ,. add ,. pfx
           
           cor a
        +-------------+---+-+
        |('') + 1     |ok |1|
        +-------------+---+-+
        |(1) + ''     |ok |1|
        +-------------+---+-+
        |('') + ''    |ok |1|
        +-------------+---+-+
        |(1) + i.0    |ok |1|
        +-------------+---+-+
        |(1) + i.0 0  |ok |1|
        +-------------+---+-+
        |(1 2) + i.0 0|err|0|
        +-------------+---+-+
        |('') + 1 2   |err|0|
        +-------------+---+-+
        |(10) + 1 2   |ok |1|
        +-------------+---+-+
           
-Dan

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to