<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Wed, 28 Aug 2024 at 21:16, Nick Treleaven via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wednesday, 28 August 2024 at 10:41:25 UTC, Manu wrote:<br>
> On Wed, 28 Aug 2024 at 19:46, Nick Treleaven via Digitalmars-d <br>
> < <a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>> wrote:<br>
>> > struct T<br>
>> > {<br>
>> > S s;<br>
>> > int i;<br>
>> ><br>
>> > alias a = i; // works<br>
>> > alias b = s.x; // Doesn't work? Why?<br>
>> > }<br>
>><br>
>> `a` is a symbol alias. `b` would be an expression if it did <br>
>> what you want. Instead it's the same as `S.x`, which needs an <br>
>> instance of S to use it at runtime.<br>
>><br>
><br>
> Not necessarily; it doesn't need to carry around the <br>
> expression; it could evaluate the resolve the expression on the <br>
> spot.<br>
<br>
It resolves to the field declaration `x`, which knows nothing <br>
about `s` - because `s.x` is not a declaration.</blockquote><div><br></div><div>Right... that's that bug. And needs to be fixed.<br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> It might confuse <br>
the concept of aliases if you allow them to refer to some <br>
sub-part of a declaration.<br></blockquote><div><br></div><div>Definitely no; it will distinctly UN-confuse the concept of aliases.</div><div>It's been requested endlessly since forever, it's obviously how people expect it to work.</div><div>Everyone I've introduced D to has found themself here in the first few days, and it just messes everything up.</div><div>The wonky edge cases and work-arounds are a clear sign it's all gone off the rails.<br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
You could instead write:<br>
```d<br>
ref b() => s.x;<br>
```<br></blockquote><div><br></div><div>Not the same thing at all... it's also an admission of defeat, and makes D look broken.</div><div>The path of exploration that leads to this hack is a really bad experience, and it does not do us any favours in terms of optics, or language satisfaction.<br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
>> `tupleof` is a symbol sequence of implicit ref declarations.<br>
>><br>
><br>
> What's a 'ref'?<br>
<br>
<a href="https://dlang.org/changelog/pending.html#dmd.reflocal" rel="noreferrer" target="_blank">https://dlang.org/changelog/pending.html#dmd.reflocal</a><br></blockquote><div><br></div><div>Yeah, I can't wait for the next release to land; we've been waiting literally forever for this!</div><div>That said, it doesn't really answer my question; what IS a ref? Nobody really knows; it's not really a thing that the language can properly express.</div><div><br></div><div>For instance, the evidence here: __traits(getParamterStorafeClasses, function, paramterByIntegerIndex)</div><div>How would you expect to detect if something is ref, or scope, or whatever? Of course, what you expect is a STRING LITERAL, which you can compare to a string of the name of the storage class.</div><div>There's no stronger evidence that storage classes are themselves such a broken idea that exist way outside of the language than passing around string literals to tell you a fact about some declaration.<br></div><div>C++ puts these things in the type, and while that creates some awkward cases, it's infinitely better than what we have in D in terms of expressiveness and flexibility in terms of meta programming. Ref as part of a type means it can participate in type-like expressions, inferences, etc.<br></div><div><br></div><div>What's kinda funny, is that your link to the cool ref-local feature (finally!) above will be shortly followed with "how do I detect if a local is a reference?" ... there's no __traits(getLocalVariableStorageClass, ...)</div><div><br></div><div>So I still don't really know; what IS a ref? It's astonishing that s.tupleof is a sequence of ref's as you say... does anything else in the language have a semantic like that? How could I synthesise something like that from anything else if I wanted to?<br></div></div></div>