Re: Undefine mixed data

[email protected] (Ralph Mellor)
Newsgroups perl.perl6.users
Message-ID <CAPLR5ScDJy=UJzc4SJnkAYfKu5J-n2raw0cAJ3ZaDA477DpLzA@mail.gmail.com>
On Sat, Mar 18, 2023 at 6:28 PM Polgár Márton
<[email protected]> wrote:
>
> For what it's worth, I think most of these behaviors that sometimes
> even contradict each other (like the "freshly undefined" array being
> both .defined and .DEFINITE) are just design mistakes from a different time.

There are no mistakes here. There is no contradiction of the kind you suggest.

The design from a different time was great, and we're lucky enough to enjoy it.

But it took until a few years ago to deprecate the wrongly named
function `undefine`.

That's all. Please don't blow such a small thing up into something it's not.

> you cannot reasonably indicate for an array that it doesn't have
> valid content, as opposed to being empty by chance

If you mean indicate it's undefined, then here's one way:
```
my @array;
say @array.elems;      # 0
say @array.so;         # False
say @array.defined;    # True

say @array := Array:U; # (Array:U)
say @array.so;         # False
say @array.defined;    # False
```
If you mean something else, please be specific.

> it does no good, ever, that you get to store a Nil value ... in an array

Why do you think the `is default(Nil)` idiom for storing `Nil`s in `Scalar`s
is OK except when the `Scalar`s are inside an array?

I grant that, as jnthn put it in an SO discussing this:

> While there is the `is default(Nil)` trick, I'd strongly suggest using some
> other value as your sentinel. Trying to use a language feature in a
> situation where you don't want the primary behavior it exists to provide
> will generally not go smoothly.

So, it is not something most Rakoons are likely to ever want. But that's
the rule that proves the exception -- on rare occasions *some* Rakoons
*do* want to store a `Nil` in an array because it's not a sentinel but a
`Nil` representing a `Nil`.

For obvious reasons I'm not going to look for examples of this use in
`Array`s to share them in this thread. No matter how irritated I get about
what you write I would still want to give you a hug if I met you in RL, and
would ask that you just eat a hat or something.

----
love, ralph
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.