Anonymous structs
Jacob Carlborg
doob at me.com
Wed Feb 13 02:35:06 PST 2013
On 2013-02-13 09:45, Era Scarecrow wrote:
> Then let's step back. You can make a scope block without having 'if'
> or any other statment that separates it.
>
> unittest {
> int x;
>
> {
> x++;//code block is valid
> }
>
> Now if you attach that to a variable it's effectively a delegate,
> function, or predicate; depending on syntax of how it's called.
>
> auto y = delegate void(){ x++; };
> auto y = (){ x++; }; //shortened to
> auto y = { x++; }; //if no calling variables gets shortened to..??
>
> Now if there's only type declarations and no instructions, it can be
> an anonymous struct (probably), but what if it has code? Is it a code
> block? The code gets defaulted to a function inside it? Illegal to do
> period? (at which point it breaks regular compatibility most likely).
My suggestion is for anonymous structs, nothing else. It can only
contain declarations of fields. I would thought that was pretty clear,
especially since the subject says "Anonymous structs" and not something
like "Anonymous delegates".
I also showed how the syntax is lowered into a regular named struct,
which would make things even more clear. But apparently not.
Is my English so bad or is it just the idea that is so bad?
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list