Oh, and I should point out this too:

      ⍴(box 'k'),box 'v'
┌→┐
│2│
└─┘
      ⍴'kv'
┌→┐
│2│
└─┘

Blake




On Sat, May 17, 2014 at 9:59 PM, Blake McBride <blake1...@gmail.com> wrote:

> Greetings,
>
> I suppose my examples were meant to show that my box and unbox function as
> I hoped, and that they functioned consistently with all data
> configurations.  I wasn't intending to point out the benefits.  I suppose I
> thought that might be clear from my earlier emails.  In response to you,
> however, I will now try to demonstrate the differences and explain why I
> like mine better.
>
> I use nested arrays to contain groups of related data - like structures in
> C.  In C, the programmer can determine the level of nesting and the
> structure of the data they wish to maintain.  One structure can be nested
> in anyway, and to any depth, as defined by the programmer.  Except for
> pointers, data items don't get defined at one level and than magically
> appear at another place in the defined structure.  You can predict how
> things will be represented.
>
> The fact that APL2 is defined such that ⊂ and ⊃ are defined such that they
> don't add or subtract  levels of nesting means that I get different data
> representations based on different data.  The best example is I ask a user
> to enter a name.  The code operates differently depending on whether the
> user enter a single character or multiple characters.
>
> Let me give an example that was I problem I had that sparked this whole
> thing.  I wanted to write a function that had a right hand argument that
> could either be a single item (a key) or two items (a key and a value).  I
> wanted to use the first item if two were passed, and the single item if a
> single item was passed.  So, the user could pass me a key, or a key value
> nested array pair.  Let's see what they look like:
>
>       'key' 'value'
> ┌→────────────┐
> │┌→──┐ ┌→────┐│
> ││key│ │value││
> │└───┘ └─────┘│
> └∊────────────┘
>       'key'
> ┌→──┐
> │key│
> └───┘
>       ≡'key' 'value'
> ┌─┐
> │2│
> └─┘
>       ≡'key'
> ┌─┐
> │1│
> └─┘
>
> Cool, I can tell if the user passed in a key value pair, or just a key.
>  But wait:
>
>
>       'k' 'v'
> ┌→─┐
> │kv│
> └──┘
>       'kv'
> ┌→─┐
> │kv│
> └──┘
>       ≡'k' 'v'
> ┌─┐
> │1│
> └─┘
>       ≡'kv'
> ┌─┐
> │1│
> └─┘
>
> Look at that!  I can't tell the difference between 'kv' single key, or the
> key value pair 'k' 'v' !!
>
> Now, I've already shown that my box/unbox can pack and unpack or group and
> ungroup arbitrary arrays like ⊂ ⊃.  Let's see if my box/unbox have the same
> problem as ⊂ ⊃.
>
>       ≡(box 'k'),box 'v'
> ┌─┐
> │3│
> └─┘
>       ≡'kv'
> ┌─┐
> │1│
> └─┘
>
> Ahh.  My box/unbox can group/ungroup like ⊂ and ⊃, but I can now tell
> which it is!  I can tell the difference between two independent characters,
> and a single character vector!!
>
> Also, since my box/unbox will box/unbox anything (i.e. including scalars),
> my program controls levels of nesting - not my data!
>
> Does that answer your question?
>
> Blake
>
>
>
> On Fri, May 16, 2014 at 9:07 PM, Frederick H. Pitts <
> fred.pi...@comcast.net> wrote:
>
>> Hello Blake,
>>
>>         Please present at least one use case where box/unbox behavior
>> differs
>> from ⊂/⊃ behavior.  For all the use cases you present in your email, I
>> do not believe there is a difference.
>>
>> Regards,
>>
>> Fred Pitts
>> Retired Chemical Engineer
>>
>> On Tue, 2014-05-13 at 09:00 -0500, Blake McBride wrote:
>> > I wrote two APL functions that operate like ⊃ and ⊂ packing an APL1
>> > array into a scalar and unpacking it back into its APL1 array.  It
>> > works as Iverson preferred, and is simple to understand and use.
>> >  There are no exceptions to what can be nested (i.e. scalars can be
>> > recursively nested).  And there are no data transformations, i.e.
>> > unboxing always gives you back what you boxed.
>> >
>> >
>> > These functions return an APL2 nested scalar that can be concatenated
>> > and used like other APL2 nested arrays - you just need to use
>> > box/unbox rather than ⊂ and ⊃ to box / unbox them.
>> >
>> >
>> > Here are the functions, examples to follow:
>> >
>> >
>> >       ∇box[⎕]∇
>> > [0] z←box x
>> > [1] z←⊂(⊂⍴x),⊂,x
>> >
>> >       ∇unbox[⎕]∇
>> > [0] z←unbox x
>> > [1] z←(⊃x[⎕IO])⍴⊃(x←⊃x)[⎕IO+1]
>> >
>> >
>> >
>> >       ]boxing 8
>> >       unbox box ,6
>> > ┌→┐
>> > │6│
>> > └─┘
>> >       unbox box 6
>> > ┌─┐
>> > │6│
>> > └─┘
>> >       unbox box ''
>> > ┌⊖┐
>> > │ │
>> > └─┘
>> >       unbox box ⍳3
>> > ┌→────┐
>> > │1 2 3│
>> > └─────┘
>> >       unbox box 0⍴0
>> > ┌⊖┐
>> > │0│
>> > └─┘
>> >       unbox box 'f'
>> > ┌─┐
>> > │f│
>> > └─┘
>> >       ⍴box ⍳3
>> > ┌⊖┐
>> > │0│
>> > └─┘
>> >       unbox unbox unbox box box box 6
>> > ┌─┐
>> > │6│
>> > └─┘
>> >       x←(box ''),(box 6), box ⍳3
>> >       ⍴x
>> > ┌→┐
>> > │3│
>> > └─┘
>> >       unbox x[1]
>> > ┌⊖┐
>> > │ │
>> > └─┘
>> >       unbox x[2]
>> > ┌─┐
>> > │6│
>> > └─┘
>> >       unbox x[3]
>> > ┌→────┐
>> > │1 2 3│
>> > └─────┘
>> >
>> > These functions, while not a replacement for ⊂ and ⊃, they do provide
>> > functionality that is sometimes preferred.
>> >
>> >
>> > Thanks.
>> >
>> >
>> > Blake
>> >
>> >
>>
>>
>>
>

Reply via email to