[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC] A new mechanism to access the active field of unions
From: |
Jose E. Marchesi |
Subject: |
Re: [RFC] A new mechanism to access the active field of unions |
Date: |
Fri, 05 Mar 2021 09:33:35 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> On Thu, Mar 04, 2021 at 09:01:51PM +0100, Jose E. Marchesi wrote:
>>
>> >
>> > So, to summarize:
>> >
>> >
>> > VAL isa TYPE
>> >
>> > Checks whether VAL is of type TYPE.
>> > This already works.
>> >
>> > VAL isa IDENTIFIER
>> >
>> > Checks whether VAL is an union value _and_ has a field named
>> > IDENTIFIER.
>> >
>> > VAL isa STR
>> >
>> > Checks whether VAL is an union value _and_ has a field named STR.
>> >
>> > If reusing `isa' like that is confusing, we can come with a new syntax
>> > for the second and third usages, like:
>> >
>> > VAL?.IDENTIFIER
>> > VAL?."STR"
>> >
>> > or something like that...
>>
>
> I think the most general form is `VAL keyword STR`. (keyword can be `isa` or
> something better)
>
> My reason:
>
> ```poke
> var field = "field1";
> var isa1 = u isa "field1";
> var isa2 = u isa field;
>
> assert (isa1 && isa2);
> ```
>
> If we choose the `VAL keyword IDENTIFIER`, we will lose the power to save
> the field name in a variable.
Yes, the `VAL keyword STRING' is more general.
Still, I was thinking on supporting _both_, since for most cases the
user will want to specify a constant name, and it is faster and easier
to just write an identifier.
>
>> Gotta say that my favorite option for now is to overload `isa'.
>>
>
>
> I don't think it's a good idea to give `isa` a completely different
> syntax and semantics.
Yes I can see why.
> In fact you're just *implicitly* adding a new keyword to the language,
> it's just not obvious (An `isa` for types, and another one for unions
> which accepts an identifier on the RHS).
I don't think that the propety of "being a keyword" is accumulative,
i.e. `if' is no more (nor less) keyword than `else', unless you accept
the possibility of removing certain uses from the language at some
point.
In any case, the alternative is to add a new keyword to the language
"explicitly" :(
Unless... we adopt the attribute syntax and support only the STR
version:
VAL'holds("foo")
> If you do so, "you're acting exactly like C++ committee here" :P
> (I'm sorry for being rude here :D)
What!?! You... I demand satisfaction! Choose your weapon.
Re: [RFC] A new mechanism to access the active field of unions, Dan Čermák, 2021/03/05