poke-devel
[Top][All Lists]
Advanced

[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: Mohammad-Reza Nabipoor
Subject: Re: [RFC] A new mechanism to access the active field of unions
Date: Fri, 5 Mar 2021 00:51:44 +0330

Hi, Jose.

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.


> 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.
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).

If you do so, "you're acting exactly like C++ committee here" :P
(I'm sorry for being rude here :D)


Regards,
Mohammad-Reza


reply via email to

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