digitalmars.D - What about an identifier that is an mixin
- =?UTF-8?B?QW5kcsOp?= Puel (21/21) Jan 13 2017 One thing that I miss sometimes when doing meta programming is
- pineapple (3/5) Jan 13 2017 I'm not sure that this is the kind of implementation detail that
- ketmar (10/12) Jan 13 2017 it hides the fact that mixin is used, which may be undesirable.
-
Daniel =?iso-8859-1?b?S2964Ws=?= via Digitalmars-d
(17/44)
Jan 13 2017
Andr=C3=A9 Puel via Digitalmars-d
napsal P... - =?UTF-8?B?QW5kcsOp?= Puel (11/53) Jan 13 2017 Could you elaborate on why you consider it important to be able
- Daniel Kozak (18/23) Jan 13 2017 because it is something really different, so it is nice to know
- =?UTF-8?B?QW5kcsOp?= Puel (8/34) Jan 13 2017 Yes, please, elaborate on that. Why is it really different? What
- Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d (23/66) Jan 15 2017 I do not like C macros.
- Daniel =?iso-8859-1?b?S2964Ws=?= via Digitalmars-d (6/52) Jan 13 2017 Right now you can even use
- Bauss (23/75) Jan 15 2017 That's not true.
- ag0aep6g (7/30) Jan 16 2017 The point is that you can mix in non-mixin templates just fine:
- Daniel =?iso-8859-1?b?S2964Ws=?= via Digitalmars-d (6/58) Jan 13 2017 =E2=88=B629 :
One thing that I miss sometimes when doing meta programming is being able to hide that a function should be called with mixin. For example (pardon my lack of creativity): // Instead of string declare_a() { return "int a;" } int func() { mixin(declare_a); return a; } // Could we have? mixin declare_a() { return "int a;"; } int func() { declare_a; return a; } I think this could be useful when one is creating Idiom and Patterns, you could hide implementations details.
Jan 13 2017
On Friday, 13 January 2017 at 21:15:32 UTC, André Puel wrote:I think this could be useful when one is creating Idiom and Patterns, you could hide implementations details.I'm not sure that this is the kind of implementation detail that ought to be hidden
Jan 13 2017
On Friday, 13 January 2017 at 21:15:32 UTC, André Puel wrote:I think this could be useful when one is creating Idiom and Patterns, you could hide implementations details.it hides the fact that mixin is used, which may be undesirable. otherwise, template mixins will do: mixin template declare_a() { int a; // or any code, even `mixin("int a;");` } int func() { mixin declare_a; return a; }
Jan 13 2017
Andr=C3=A9 Puel via Digitalmars-d <digitalmars-d puremagic.com> napsal P=C3= =A1,=20 led 13, 2017 v 10=E2=88=B615 :One thing that I miss sometimes when doing meta programming is being=20 able to hide that a function should be called with mixin. =20 For example (pardon my lack of creativity): =20 // Instead of string declare_a() { return "int a;" } =20 int func() { mixin(declare_a); return a; } =20 // Could we have? mixin declare_a() { return "int a;"; } =20 int func() { declare_a; return a; } =20 I think this could be useful when one is creating Idiom and Patterns,=20 you could hide implementations details.You can do this: mixin template declare_a() { int a; } int func() { mixin declare_a; return a; } but there is no way to exclude mixin before calling declare_a, there is=20 a good reason for that (it is really important to be able to tell when=20 you use mixin and when not) =
Jan 13 2017
On Friday, 13 January 2017 at 21:29:28 UTC, Daniel Kozák wrote:André Puel via Digitalmars-d <digitalmars-d puremagic.com> napsal Pá, led 13, 2017 v 10∶15 :Could you elaborate on why you consider it important to be able to tell when you use mixin and when not? I know C macro is a mess, but in C you don't know if you are calling a function or if it is a macro. In D, you don't know if a member is a function call or an attribute when you access it without parenthesis: myObj.a; //Is it a function call or an attribute? There are these cases where the one developing a library/framework want to lie to the programmer using it. It makes the feature seamless.One thing that I miss sometimes when doing meta programming is being able to hide that a function should be called with mixin. For example (pardon my lack of creativity): // Instead of string declare_a() { return "int a;" } int func() { mixin(declare_a); return a; } // Could we have? mixin declare_a() { return "int a;"; } int func() { declare_a; return a; } I think this could be useful when one is creating Idiom and Patterns, you could hide implementations details.You can do this: mixin template declare_a() { int a; } int func() { mixin declare_a; return a; } but there is no way to exclude mixin before calling declare_a, there is a good reason for that (it is really important to be able to tell when you use mixin and when not)
Jan 13 2017
On Friday, 13 January 2017 at 22:12:55 UTC, André Puel wrote:Could you elaborate on why you consider it important to be able to tell when you use mixin and when not?because it is something really different, so it is nice to know when you call something and when you mixin some code into curent scope. Btw. I was on a same side as you are now (I am still in some way, I would prefer some shortcuts)In D, you don't know if a member is a function call or an attribute when you access it without parenthesis: myObj.a; //Is it a function call or an attribute?Not completly true: class MyClass { int a; void b() {} } void main() { auto myObj = new MyClass; myObj.a; // this does not compile myObj.b; }
Jan 13 2017
On Friday, 13 January 2017 at 23:13:43 UTC, Daniel Kozak wrote:On Friday, 13 January 2017 at 22:12:55 UTC, André Puel wrote:Yes, please, elaborate on that. Why is it really different? What are your thoughts on C macros?Could you elaborate on why you consider it important to be able to tell when you use mixin and when not?because it is something really different, so it is nice to know when you call something and when you mixin some code into curent scope.Btw. I was on a same side as you are now (I am still in some way, I would prefer some shortcuts)I meant the property pattern. You access an attribute and it could be a direct access in the memory or it could be a request to a remote database. One happens instantly, the other got a lot of complex things in the way. You could even get a thrown exception by just accessing an "attribute".In D, you don't know if a member is a function call or an attribute when you access it without parenthesis: myObj.a; //Is it a function call or an attribute?Not completly true: class MyClass { int a; void b() {} } void main() { auto myObj = new MyClass; myObj.a; // this does not compile myObj.b; }
Jan 13 2017
V Sat, 14 Jan 2017 01:28:51 +0000 André Puel via Digitalmars-d <digitalmars-d puremagic.com> napsáno:On Friday, 13 January 2017 at 23:13:43 UTC, Daniel Kozak wrote:I do not like C macros. It is different because when anyone see something like this: someNameOfFunction(); He or she would expect that this call something and it could not interact with current scope (declare new local variables, change theirs values and so on). but if we allow use same call convention for mixins we end up with something like this string someMixin() { return `a = 5;`; } void main() { import std.stdio; int a = 4; someMixin(); writeln(a); // wow 5 insted of 4 } right now when I see mixin(someMixin()); I know I need to introspect someMixin to be sure what can happendOn Friday, 13 January 2017 at 22:12:55 UTC, André Puel wrote:Yes, please, elaborate on that. Why is it really different? What are your thoughts on C macros?Could you elaborate on why you consider it important to be able to tell when you use mixin and when not?because it is something really different, so it is nice to know when you call something and when you mixin some code into curent scope.Btw. I was on a same side as you are now (I am still in some way, I would prefer some shortcuts)I meant the property pattern. You access an attribute and it could be a direct access in the memory or it could be a request to a remote database. One happens instantly, the other got a lot of complex things in the way. You could even get a thrown exception by just accessing an "attribute".In D, you don't know if a member is a function call or an attribute when you access it without parenthesis: myObj.a; //Is it a function call or an attribute?Not completly true: class MyClass { int a; void b() {} } void main() { auto myObj = new MyClass; myObj.a; // this does not compile myObj.b; }
Jan 15 2017
Daniel Koz=C3=A1k <kozzi11 gmail.com> napsal P=C3=A1, led 13, 2017 v 10=E2= =88=B629 :Andr=C3=A9 Puel via Digitalmars-d <digitalmars-d puremagic.com> napsal=20 P=C3=A1, led 13, 2017 v 10=E2=88=B615 :Right now you can even use template declare_a() {...} there is no difference between template and mixin template =One thing that I miss sometimes when doing meta programming is being=20 able to hide that a function should be called with mixin. =20 For example (pardon my lack of creativity): =20 // Instead of string declare_a() { return "int a;" } =20 int func() { mixin(declare_a); return a; } =20 // Could we have? mixin declare_a() { return "int a;"; } =20 int func() { declare_a; return a; } =20 I think this could be useful when one is creating Idiom and=20 Patterns, you could hide implementations details.=20 You can do this: =20 mixin template declare_a() { int a; } =20 int func() { mixin declare_a; return a; } =20 but there is no way to exclude mixin before calling declare_a, there=20 is a good reason for that (it is really important to be able to tell=20 when you use mixin and when not)
Jan 13 2017
On Friday, 13 January 2017 at 21:32:49 UTC, Daniel Kozák wrote:Daniel Kozák <kozzi11 gmail.com> napsal Pá, led 13, 2017 v 10∶29 :That's not true. Templates do not carry context with them, they only have their own scope available. Where as mixin templates can access every member that is in their scope. Consider: template SetXCTFE_Template(int value) { void SetXCTFE_Template() { x = value; } } mixin template SetXCTFE_Mixin_Template(int value) { void handle() { x = value; } } void main() { int x; x = SetXCTFE_Template!10; // Not ok ... mixin SetXCTFE_Mixin_Template!10; // ok ... handle(); // ok ... }André Puel via Digitalmars-d <digitalmars-d puremagic.com> napsal Pá, led 13, 2017 v 10∶15 :Right now you can even use template declare_a() {...} there is no difference between template and mixin templateOne thing that I miss sometimes when doing meta programming is being able to hide that a function should be called with mixin. For example (pardon my lack of creativity): // Instead of string declare_a() { return "int a;" } int func() { mixin(declare_a); return a; } // Could we have? mixin declare_a() { return "int a;"; } int func() { declare_a; return a; } I think this could be useful when one is creating Idiom and Patterns, you could hide implementations details.You can do this: mixin template declare_a() { int a; } int func() { mixin declare_a; return a; } but there is no way to exclude mixin before calling declare_a, there is a good reason for that (it is really important to be able to tell when you use mixin and when not)
Jan 15 2017
On 01/16/2017 08:52 AM, Bauss wrote:On Friday, 13 January 2017 at 21:32:49 UTC, Daniel Kozák wrote:[...]The point is that you can mix in non-mixin templates just fine: mixin SetXCTFE_Template!10; // ok In that regard, templates and mixin templates behave the same. The difference between them is that you can't instantiate a mixin template without `mixin`.there is no difference between template and mixin templateThat's not true. Templates do not carry context with them, they only have their own scope available. Where as mixin templates can access every member that is in their scope. Consider: template SetXCTFE_Template(int value) { void SetXCTFE_Template() { x = value; } } mixin template SetXCTFE_Mixin_Template(int value) { void handle() { x = value; } } void main() { int x; x = SetXCTFE_Template!10; // Not ok ... mixin SetXCTFE_Mixin_Template!10; // ok ... handle(); // ok ... }
Jan 16 2017
Daniel Koz=C3=A1k <kozzi11 gmail.com> napsal P=C3=A1, led 13, 2017 v 10=E2= =88=B632 :Daniel Koz=C3=A1k <kozzi11 gmail.com> napsal P=C3=A1, led 13, 2017 v 10==E2=88=B629 :in this context, AFAIK you can not use mixin template like a normal=20 template but you can use non mixin template like a mixin template =Andr=C3=A9 Puel via Digitalmars-d <digitalmars-d puremagic.com> napsal=20 P=C3=A1, led 13, 2017 v 10=E2=88=B615 :=20 Right now you can even use template declare_a() {...} =20 there is no difference between template and mixin templateOne thing that I miss sometimes when doing meta programming is=20 being able to hide that a function should be called with mixin. =20 For example (pardon my lack of creativity): =20 // Instead of string declare_a() { return "int a;" } =20 int func() { mixin(declare_a); return a; } =20 // Could we have? mixin declare_a() { return "int a;"; } =20 int func() { declare_a; return a; } =20 I think this could be useful when one is creating Idiom and=20 Patterns, you could hide implementations details.=20 You can do this: =20 mixin template declare_a() { int a; } =20 int func() { mixin declare_a; return a; } =20 but there is no way to exclude mixin before calling declare_a, there=20 is a good reason for that (it is really important to be able to tell=20 when you use mixin and when not)
Jan 13 2017