Jump to page: 1 24  
Page
Thread overview
Trip notes from Israel
May 22, 2017
Suliman
May 22, 2017
Adam D. Ruppe
May 22, 2017
Adam D. Ruppe
May 22, 2017
Timon Gehr
May 22, 2017
Quentin Ladeveze
May 22, 2017
Sebastiaan Koppe
May 22, 2017
Johan Engelen
May 23, 2017
Iain Buclaw
May 23, 2017
kinke
May 23, 2017
Johan Engelen
May 23, 2017
Stefan Koch
May 23, 2017
Stefan Koch
Generating checked integral operations [WAS: Trip notes from Israel]
May 23, 2017
Stefan Koch
May 23, 2017
Stefan Koch
May 23, 2017
Stefan Koch
May 22, 2017
cym13
May 26, 2017
Meta
May 26, 2017
Joakim
May 27, 2017
Laeeth Isharc
May 27, 2017
Meta
May 26, 2017
Adam D. Ruppe
May 26, 2017
Paolo Invernizzi
May 23, 2017
Swoorup Joshi
May 24, 2017
bpr
May 24, 2017
Jacob Carlborg
May 22, 2017
http://dlang.org/blog/2017/05/22/introspection-introspection-everywhere/ -- Andrei
May 22, 2017
On 05/22/2017 11:05 AM, Andrei Alexandrescu wrote:
> http://dlang.org/blog/2017/05/22/introspection-introspection-everywhere/ -- Andrei

Submitted to reddit as well: https://www.reddit.com/r/programming/comments/6cntso/from_the_d_blog_introspection_introspection/ -- Andrei
May 22, 2017
On Monday, 22 May 2017 at 15:05:24 UTC, Andrei Alexandrescu wrote:
> mixin is a statement so it needs a terminator, hence
> the semicolon at the very end. In turn, mixin takes
> a string (the concatenation of variable op

That actually depends on context! The mixin statement needs statements, but the mixin expression takes expressions. Same mixin keyword, but if it is in the context of a statement it is a statement and in the context of an expression, it is an expression.

---
void main() {
	int payload;
        mixin("++payload;"); // statement, ; required
	int b = mixin("++payload"); // expression, ; would be wrong there and cause an error!
}
---

http://dlang.org/spec/expression.html#MixinExpression
http://dlang.org/spec/statement.html#MixinStatement
May 22, 2017
On 05/22/2017 11:23 AM, Adam D. Ruppe wrote:
> On Monday, 22 May 2017 at 15:05:24 UTC, Andrei Alexandrescu wrote:
>> mixin is a statement so it needs a terminator, hence
>> the semicolon at the very end. In turn, mixin takes
>> a string (the concatenation of variable op
> 
> That actually depends on context! The mixin statement needs statements, but the mixin expression takes expressions. Same mixin keyword, but if it is in the context of a statement it is a statement and in the context of an expression, it is an expression.
> 
> ---
> void main() {
>      int payload;
>          mixin("++payload;"); // statement, ; required
>      int b = mixin("++payload"); // expression, ; would be wrong there and cause an error!
> }
> ---
> 
> http://dlang.org/spec/expression.html#MixinExpression
> http://dlang.org/spec/statement.html#MixinStatement

Yah, didn't want to overload the article (or the discussion) with the expression/statement distinction. -- Andrei
May 22, 2017
On 05/22/2017 11:26 AM, Andrei Alexandrescu wrote:
> On 05/22/2017 11:23 AM, Adam D. Ruppe wrote:
>> On Monday, 22 May 2017 at 15:05:24 UTC, Andrei Alexandrescu wrote:
>>> mixin is a statement so it needs a terminator, hence
>>> the semicolon at the very end. In turn, mixin takes
>>> a string (the concatenation of variable op
>>
>> That actually depends on context! The mixin statement needs statements, but the mixin expression takes expressions. Same mixin keyword, but if it is in the context of a statement it is a statement and in the context of an expression, it is an expression.
>>
>> ---
>> void main() {
>>      int payload;
>>          mixin("++payload;"); // statement, ; required
>>      int b = mixin("++payload"); // expression, ; would be wrong there and cause an error!
>> }
>> ---
>>
>> http://dlang.org/spec/expression.html#MixinExpression
>> http://dlang.org/spec/statement.html#MixinStatement
> 
> Yah, didn't want to overload the article (or the discussion) with the expression/statement distinction. -- Andrei

Updated the post, it's an interesting point after all. Thanks! -- Andrei
May 22, 2017
On Monday, 22 May 2017 at 15:26:26 UTC, Andrei Alexandrescu wrote:
> Yah, didn't want to overload the article (or the discussion) with the expression/statement distinction. -- Andrei

Yeah, the details might be too much for a general audience (and I realize you know this, I'm commenting more for other readers who might be interested), but I do think this illustrates an important point for anyone who wants to use mixin: it is similar to, but not exactly like copy/pasting code into the source.

mixin parses a piece of code, then pastes the *AST node*, not the source code, into the tree where the mixin is found. That's why the semicolon is required in the statement context - it needs a complete branch that actually fits the AST at the moment, not just a string that is pasted into the source code at the location.

So similar enough to copy/paste to get someone quickly started playing with code generation, but this key difference is needed to really understand it.
May 22, 2017
On Monday, 22 May 2017 at 15:05:24 UTC, Andrei Alexandrescu wrote:
> http://dlang.org/blog/2017/05/22/introspection-introspection-everywhere/ -- Andrei

It was really an entertaining and interesting post, thank you.
May 22, 2017
On Monday, 22 May 2017 at 15:12:42 UTC, Andrei Alexandrescu wrote:
> On 05/22/2017 11:05 AM, Andrei Alexandrescu wrote:
>> http://dlang.org/blog/2017/05/22/introspection-introspection-everywhere/ -- Andrei
>
> Submitted to reddit as well: https://www.reddit.com/r/programming/comments/6cntso/from_the_d_blog_introspection_introspection/ -- Andrei

Perfect! I have been in Weka.IO in this january too! Big thanks guys!
May 22, 2017
On 22.05.2017 17:38, Adam D. Ruppe wrote:
> On Monday, 22 May 2017 at 15:26:26 UTC, Andrei Alexandrescu wrote:
>> Yah, didn't want to overload the article (or the discussion) with the
>> expression/statement distinction. -- Andrei
>
> Yeah, the details might be too much for a general audience (and I
> realize you know this, I'm commenting more for other readers who might
> be interested), but I do think this illustrates an important point for
> anyone who wants to use mixin: it is similar to, but not exactly like
> copy/pasting code into the source.
>
> mixin parses a piece of code, then pastes the *AST node*, not the source
> code, into the tree where the mixin is found. That's why the semicolon
> is required in the statement context - it needs a complete branch that
> actually fits the AST at the moment, not just a string that is pasted
> into the source code at the location.
>
> So similar enough to copy/paste to get someone quickly started playing
> with code generation, but this key difference is needed to really
> understand it.

The grammar has:

expression;

as a statement.

mixin(...)

as an expression

and

mixin(...);

as a statement

Hence,

mixin(...);

is actually grammatically ambiguous and the behaviour of the compiler is somewhat arbitrary.

The compiler could easily compensate for the ambiguity during semantic and not require the terminating semicolon when parsing the string of a mixin statement.
May 22, 2017
On Monday, 22 May 2017 at 15:05:24 UTC, Andrei Alexandrescu wrote:
> http://dlang.org/blog/2017/05/22/introspection-introspection-everywhere/ -- Andrei

Wow, that was really good. Love to read more of your trip notes.
« First   ‹ Prev
1 2 3 4