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: Jose E. Marchesi
Subject: Re: [RFC] Syntax for struct type constructors
Date: Thu, 04 Mar 2021 19:58:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> 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); // ?!
> ```

Passing arguments to the type constructors works exactly the same than
passing arguments to functions.

So yes, if the value is composite and you modify it, it will be visible
inside the struct type.

This is similar to what we have now in type arrays:

(poke) var N = 2
(poke) type Matrix = int[N][N]
(poke) Matrix ()
[[0x0,0x0],[0x0,0x0]]
(poke) N = 3
(poke) Matrix ()
[[0x0,0x0,0x0],[0x0,0x0,0x0],[0x0,0x0,0x0]]




reply via email to

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