Re: Emulation macros and pattern matching on D

2015-06-05 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 5 June 2015 at 20:14:51 UTC, Steven Schveighoffer wrote: On 6/5/15 4:03 PM, Dennis Ritchie wrote: It would be very good, because many have long been trying to implement this functionality handmade :) http://www.prowiki.org/wiki4d/wiki.cgi?DanielKeep/shfmt Yes, unfortunately that v

Re: Emulation macros and pattern matching on D

2015-06-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/5/15 4:03 PM, Dennis Ritchie wrote: On Friday, 5 June 2015 at 19:08:19 UTC, Steven Schveighoffer wrote: It's just so I didn't have to escape the quotes :D Otherwise it looks like this: return "writefln(\"mode " ~ mode ~ ": %s\", " ~ value ~ ");" But such an option is possible to do work

Re: Emulation macros and pattern matching on D

2015-06-05 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 5 June 2015 at 19:08:19 UTC, Steven Schveighoffer wrote: It's just so I didn't have to escape the quotes :D Otherwise it looks like this: return "writefln(\"mode " ~ mode ~ ": %s\", " ~ value ~ ");" But such an option is possible to do work? : D return `writefln(q"["mode]" ` ~ mod

Re: Emulation macros and pattern matching on D

2015-06-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/5/15 11:52 AM, Dennis Ritchie wrote: On Friday, 5 June 2015 at 14:31:19 UTC, anonymous wrote: You messed up the quotes. You might be mistaking backticks for something special, but they're basically just quotes. Yes, the sample program really made me think that gravis (backticks) - is some

Re: Emulation macros and pattern matching on D

2015-06-05 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 5 June 2015 at 14:31:19 UTC, anonymous wrote: You messed up the quotes. You might be mistaking backticks for something special, but they're basically just quotes. Yes, the sample program really made me think that gravis (backticks) - is something special...

Re: Emulation macros and pattern matching on D

2015-06-05 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 5 June 2015 at 14:23:15 UTC, Steven Schveighoffer wrote: On 6/5/15 10:15 AM, Dennis Ritchie wrote: Thanks. It looks really simple, but I still do not understand the concept of using mixins in full. I do not understand why in this line: return `writefln("mode ` ~ mode ~ `: %s", ` ~

Re: Emulation macros and pattern matching on D

2015-06-05 Thread anonymous via Digitalmars-d-learn
On Friday, 5 June 2015 at 14:15:09 UTC, Dennis Ritchie wrote: For example, why here I can simply write: void main() { int b = 5; mixin(`int a = b;`); assert(a == 5); } This becomes: int b = 5; int a = b; assert(a == 5); Why should not I write like this: void main()

Re: Emulation macros and pattern matching on D

2015-06-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/5/15 10:15 AM, Dennis Ritchie wrote: On Friday, 5 June 2015 at 13:13:15 UTC, Steven Schveighoffer wrote: string foo(string mode, string value) { return `writefln("mode ` ~ mode ~ `: %s", ` ~ value ~ `);`; } void main() { mixin(foo("Y", "3")); mixin(foo("X", "2")); } Thanks. It l

Re: Emulation macros and pattern matching on D

2015-06-05 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 5 June 2015 at 13:13:15 UTC, Steven Schveighoffer wrote: string foo(string mode, string value) { return `writefln("mode ` ~ mode ~ `: %s", ` ~ value ~ `);`; } void main() { mixin(foo("Y", "3")); mixin(foo("X", "2")); } Thanks. It looks really simple, but I still do not unde

Re: Emulation macros and pattern matching on D

2015-06-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/5/15 9:01 AM, Dennis Ritchie wrote: Macros and operation of pattern matching `=>` in Rust I can write something like this: macro_rules!foo { (x => $e:expr) => (println!("mode X: {}", $e)); (y => $e:expr) => (println!("mode Y: {}", $e)); } fn main() { foo!(y => 3); // mode Y:

Emulation macros and pattern matching on D

2015-06-05 Thread Dennis Ritchie via Digitalmars-d-learn
Macros and operation of pattern matching `=>` in Rust I can write something like this: macro_rules!foo { (x => $e:expr) => (println!("mode X: {}", $e)); (y => $e:expr) => (println!("mode Y: {}", $e)); } fn main() { foo!(y => 3); // mode Y: 3 foo!(x => 2); // mode X: 2 } How is