Eigenstate: myrddin-dev mailing list

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

Re: union member already defined?


The scoping rules are those of C's enums, rather than C's unions.

In contrast, Rust scopes it's enums, which are functionally very similar to Myrddin's unions, like C's unions but the tradeoff is that you have to namespace variants when using them. For example, if you have a package named "tok" and a type named "Tok" which includes a variant named "Eq", in Myrddin referring to this from outside that package would be "`tok.Eq" while in Rust it would be "tok::Tok::Eq". Of course there are also cases where Rust's scoping rules might look cleaner, e.g. "`Fooa" vs "Foo::A", but in my experience those are less common, especially when real names are used.

 ---- On Sun, 29 Jul 2018 04:50:28 -0700 theos <theosjp@xxxxxxxxx> wrote ---- 
 > hi iriri - 
 >  
 > thanks for the hello and welcome.  yes, i find what you guys have been 
 > putting together really amazing. 
 >  
 > regarding the union - hmm... interesting.  i've had noticed that the 
 > code compiled when i made the tags unique, but i thought that this cant 
 > be right. 
 >  
 > do you know what the motivation was to scope it this way compared to c? 
 >  
 > thanks, 
 > theo 
 >  
 > On 07/29/2018 09:43 AM, iriri wrote: 
 > > Union tags must be unique within a given namespace. 
 > >  
 > > type u1 = 
 > >      `A1 int 
 > >      `B1 flt64 
 > > ;; 
 > >  
 > > type u2 = 
 > >      `A2 flt64 
 > >      `B2 char 
 > > ;; 
 > >  
 > >   ---- On Sat, 28 Jul 2018 02:21:33 -0700 theos <theosjp@xxxxxxxxx> wrote ---- 
 > >   > hi, 
 > >   > 
 > >   > i started to learn myrddin recently and was going through the tutorial. 
 > >   > i am getting - somewhat unexpected - an "already defined" error for the 
 > >   > below union example. this is with the latest version on linux. 
 > >   > 
 > >   > is this supposed to be this way?  and if so what am i doing wrong? 
 > >   > 
 > >   > % mbld -R u2.myr 
 > >   > u2.myr:2: `a already defined on u2.myr:7 
 > >   > FAIL: 6m u2.myr 
 > >   > 
 > >   > % 6m u2.myr 
 > >   > u2.myr:2: `a already defined on u2.myr:7 
 > >   > 
 > >   > % cat u2.myr 
 > >   > type u1 = union 
 > >   >          `a int 
 > >   >          `b flt 
 > >   > ;; 
 > >   > 
 > >   > type u2 = union 
 > >   >          `a flt 
 > >   >          `b char 
 > >   > ;; 
 > >   > 
 > >   > const main = { 
 > >   > 
 > >   > } 
 > >   > 
 > >   > its error-ing out in stab.c - i've poked a bit around in putucon and 
 > >   > gram.y, but had to confess to myself that i dont really know what i am 
 > >   > looking for/at. 
 > >   > 
 > >   > Breakpoint 3, putucon (st=0x5555557d1070, uc=0x5555557dc460) at stab.c:495 
 > >   > 495                     lfatal(old->loc, "`%s already defined on %s:%d", 
 > >   > (gdb) bt 
 > >   > #0  putucon (st=0x5555557d1070, uc=0x5555557dc460) at stab.c:495 
 > >   > #1  0x0000555555578d30 in installucons (st=0x5555557d1070, 
 > >   > t=0x5555557dc6a0) at gram.y:1252 
 > >   > #2  0x0000555555574484 in yyparse () at gram.y:248 
 > >   > #3  0x0000555555563e3b in main (argc=2, argv=0x7fffffffe728) at main.c:276 
 > >   > 
 > >   > thank you, 
 > >   > theo. 
 > >   > 
 > >   > 
 > >   > 
 > >  
 > >  
 > >  
 >  
 > 



References:
union member already defined?theos <theosjp@xxxxxxxxx>
Re: union member already defined?iriri <iri@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Re: union member already defined?theos <theosjp@xxxxxxxxx>