Dear Fred, While your code does help in one area, it has a problem in another, i.e.: gg←,'' 'a' 'b' ⍴gg 3
Your code says there are three but to the programmer there are only two. The '' is just there to make the rest work. I suppose you can just remember that and change your indexes everywhere and hope someone else reading the code gets it. Also, in: ( unbox unbox unbox box box box 6 ) ≡ ⊃ ⊃ ⊃ ⊂ ⊂ ⊂ 6 They are not equivalent at all. Each box adds additional levels of nesting as the programmer is specifying. Each ⊂ above is a null function. This is actually the main point. box always gives you an additional level of nesting regardless of data. ⊂ always gives you an additional level of nesting unless your data happens to be a scalar. What you end up with is dependent on the data. It is almost like saying that: x times y gives the result of multiplying x by y, unless x is 88 then we add. The operation shouldn't be dependent on the data. Additionally, you would have to either encapsulate your idiom into a function or remember the extra steps everywhere - and remember when to use it and when not to use it. I am sure there are many ways to skin a cat, or solve this problem. I think mine is cleaner. Thanks for your input! Blake On Mon, May 19, 2014 at 10:34 PM, Frederick H. Pitts <fred.pi...@comcast.net > wrote: > Blake, > > Since box and unbox are implemented directly in terms of enclose > and > disclose, I have to believe that the latter can handle the parameters > you require and in a less verbose fashion. > > Consider the following code: > > gg ← ,'' 'a' 'b' > gg > ┌→─────┐ > │┌⊖┐ ab│ > ││ │ │ > │└─┘ │ > └∊─────┘ > hh ← ,'' 'ab' > hh > ┌→───────┐ > │┌⊖┐ ┌→─┐│ > ││ │ │ab││ > │└─┘ └──┘│ > └∊───────┘ > > If the first element of a nested array is a vector, any vector, > subsequent scalar character elements remain scalar and are not coalesced > into a vector. hh is presented to highlight the difference between a > sequence of scalar character elements and a character vector. There are > 3 elements in gg and only 2 in hh. I'm of the opinion that box/unbox > work because the box function stuffs a vector in the first element of > the nested array. If not, sequential homogeneous scalars are going to > be coalesced to form a vector element. A requirement for a nested array > to exist is that it contain at least one vector element. The remaining > elements can be scalar. enclose is not going to produce a nested array > unless a vector element is supplied and if one is not supplied, enclose > will attempt to create one. > > Please consider the attached code. It demonstrates that enclose > (actually implicit enclose), dyadic pick and parallel assignment can > more succinctly do what the box/unbox pair do, but admittedly at the > slight complication of having to supply and account for the vector first > element in the nested array and its nested array elements. That > complication seems a small price to pay for not having to box and unbox > every element of a nested array. > > Regards, > > Fred > Retired Chemical Engineer > >