<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 28 Aug 2024 at 19:46, 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 Sunday, 25 August 2024 at 05:07:43 UTC, Manu wrote:<br>
> Like, from my example above, what even IS `s.tupleof`? It's <br>
> some kind of<br>
> list of what kind of thing? Direct symbol references to members <br>
> of a live<br>
> instance?<br>
<br>
It's a symbol sequence of references to fields.<br>
<br>
```d<br>
import std;<br>
<br>
struct S<br>
{<br>
     int i;<br>
     char c;<br>
}<br>
<br>
void main()<br>
{<br>
     S s = {2, 'c'};<br>
     ref si = s.i;<br>
     ref sc = s.c;<br>
     alias tupleof = AliasSeq!(si, sc); // same as s.tupleof<br>
     tupleof[0]++;<br>
     s.writeln();<br>
     assert(s.i == 3);<br>
<br>
     // this actually works<br>
     alias a = tupleof[0];<br>
     a++;<br>
     assert(s.i == 4);<br>
}<br>
```<br>
<br>
So `alias e = s.tupleof[0];` could be made to work.<br>
<br>
See also: <a href="https://dlang.org/spec/template.html#lvalue-sequences" rel="noreferrer" target="_blank">https://dlang.org/spec/template.html#lvalue-sequences</a>.<br>
<br>
BTW I'd like to make sequences a separate spec page from <br>
templates really.<br>
<br>
> If s.tupleof can populate a list with that kind of thing, why <br>
> doesn't this<br>
> work:<br>
><br>
> struct S<br>
> {<br>
>   int x, y;<br>
> }<br>
><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 what <br>
you want. Instead it's the same as `S.x`, which needs an instance <br>
of S to use it at runtime.<br></blockquote><div><br></div><div>Not necessarily; it doesn't need to carry around the expression; it could evaluate the resolve the expression on the spot.<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">
<br>
> alias b = s.tupleof[0]; // this emits a surprising error <br>
> message:<br>
><br>
> error : alias `b` cannot alias an expression `AliasSeq!(s.x, <br>
> s.y)[0]`<br>
> So, that 'list' I mention; does this error message imply that <br>
> this list given by `tupleof` is an AliasSeq? What exactly IS an <br>
> AliasSeq? What is the actual set of things that it can hold?<br>
<br>
Symbols (declarations) and compile-time values. S.x is a <br>
declaration, s.x is a runtime value.<br>
<br>
`tupleof` is a symbol sequence of implicit ref declarations.<br></blockquote><div><br></div><div>What's a 'ref'?<br></div></div></div>