poke-devel
[Top][All Lists]
Advanced

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

Re: [RFC] Syntax for struct type constructors


From: Mohammad-Reza Nabipoor
Subject: Re: [RFC] Syntax for struct type constructors
Date: Thu, 4 Mar 2021 22:21:26 +0330

Hi, Jose.

On Mon, Mar 01, 2021 at 10:03:55PM +0100, Jose E. Marchesi wrote:
> 
> Hi people!
> 
> Next feature I will implement in poke is support for having arguments in
> struct types.  Like this:
> 
> type Packet =
>   struct (int control, int datasize = 256)
>   {
>     byte ctrl = control;
>     byte[datasize] payload;
>   };
> 
> I feel good with the above syntax: it in intuitive and clear.
> 
> [...]
> 
> 2) To use angle brackets, like in:
> 
>    Packet<2, 1024>
>    Packet<2> /* datasize is optional */
> 

Is this valid?

```poke
var ctl = 100;
var pkt = Packet<ctl>{};

ctl = 200;

assert (pkt.ctrl == 100); // I think this is the case, because `ctl` will be 
copied,
                          // but the story will be different for composite types
// or,
// assert (pkt.ctrl == 200); // ?!
```


Regards,
Mohammad-Reza


reply via email to

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