bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] box and unbox that work uniformly and without exceptions


From: Frederick H. Pitts
Subject: Re: [Bug-apl] box and unbox that work uniformly and without exceptions
Date: Mon, 19 May 2014 22:34:48 -0500

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


On Mon, 2014-05-19 at 06:36 -0500, Blake McBride wrote:
> Dear Fred,
> 
> 
> Thanks for taking the time and effort to provide your feedback.  I
> looked at your example.
> 
> 
> I gave my example in simple terms in the hopes that the full extent of
> the idea would be understood.  In my explanation of the problem, I
> should have made it clear that the key can be any character scalar or
> vector except ''.  So, the key can have spaces or any other ⎕AV
> character.  In fact, the key ken even be just a space.
> 
> 
> The value can be any character or numeric scalar, array, or nested
> array containing anything including ''.
> 
> 
> Given the above, neither ⊃ and ⊂, nor your code can handle those
> parameters.  Box / unbox can.
> 
> 
> Thanks.
> 
> 
> Blake
> 
> 
> 
> 
> 
> 
> 
> 
> On Sun, May 18, 2014 at 10:07 PM, Frederick H. Pitts
> <address@hidden> wrote:
>         Hello Blake,
>         
>                 After having asked you to present a use case where the
>         behavior of
>         box/unbox differs from enclose/disclose and you graciously
>         replied, I
>         felt obligated to spend a little time studying the issue.  I
>         did that
>         and have come to the conclusion that both boxed and nested
>         arrays are
>         overkill for the use case.  The key-value pair text (separated
>         by a
>         blank) or key text can be supplied in a character vector which
>         can
>         easily be parsed for the presence of one or two words.  See
>         the attached
>         blake1.apl.gz for a demonstration.
>         
>                 I would like to make the observation that nested
>         arrays must not be too
>         bad.  After all, the revised code to fix their shortcomings
>         only took 5
>         lines written in terms of nested arrays.
>         
>         Regards,
>         
>         Fred
>         Retired Chemical Engineer
>         On Sat, 2014-05-17 at 22:20 -0500, Blake McBride wrote:
>         
>         > Lastly,
>         >
>         >
>         >       ⍴(box 'abc'),box 'def'
>         > ┌→┐
>         > │2│
>         > └─┘
>         >
>         >
>         > Blake
>         
>         
>         
> 
> 

Attachment: boxing.apl.gz
Description: GNU Zip compressed data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]