digitalmars.D - Inline Operator from Function.
- Jonathan Levi (14/14) Jan 24 2019 I know this was not an intentional feature of d, but it is a cool
- Neia Neutuladh (21/28) Jan 24 2019 Consider also:
- Neia Neutuladh (5/6) Jan 24 2019 Er, that should obviously be:
- Mike Parker (3/4) Jan 24 2019 2007 it seems, assuming FeepingCreature == downs:
- Neia Neutuladh (2/9) Jan 24 2019 Apologies for the misattribution, and thank you for correcting me.
- Mike Parker (3/14) Jan 25 2019 I wasn't correcting, but genuinely curious if it was the same
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (5/22) Jan 25 2019 From https://forum.dlang.org/post/imqv4k$7kv$2@digitalmars.com:
- bauss (2/33) Jan 25 2019 Now that's a hack I can support.
I know this was not an intentional feature of d, but it is a cool quirk. If you want to use a function that takes two arguments like a infix binary operator (similar to the back ticks in Haskell "`fun`") you can but a "." before and a "=" after. c = (a .fun= b); Example of it working (https://run.dlang.io/is/rr7ChO) import std.stdio; void main() { writeln(5 .mul= 2); } int mul(int a, int b) { return a*b; }
Jan 24 2019
On Fri, 25 Jan 2019 03:45:36 +0000, Jonathan Levi wrote:I know this was not an intentional feature of d, but it is a cool quirk. If you want to use a function that takes two arguments like a infix binary operator (similar to the back ticks in Haskell "`fun`") you can but a "." before and a "=" after. c = (a .fun= b);Consider also: struct Operator(alias fn) if (Parameters!fn.length == 2) { Curry opBinaryRight(string op)(Parameters!fn[0] arg) if (op == "/") { return Curry(arg); } struct Curry { Parameters!fn[0] arg; auto opBinaryRight(string op)(Parameters!fn[1] arg2) if (op == "/") { return fn(arg, arg2); } } } To use it: alias min = Operator!((a, b) => a < b ? a : b); writeln(1 /min/ 2); Credit to FeepingCreature for inventing this 5-10 years ago.
Jan 24 2019
On Fri, 25 Jan 2019 03:52:23 +0000, Neia Neutuladh wrote:alias min = Operator!((a, b) => a < b ? a : b);Er, that should obviously be: enum min = Operator!(...).init; Or use a static function for the operator overload. It's a land of lawlessness here, do whatever you like.
Jan 24 2019
On Friday, 25 January 2019 at 03:52:23 UTC, Neia Neutuladh wrote:Credit to FeepingCreature for inventing this 5-10 years ago.2007 it seems, assuming FeepingCreature == downs: https://forum.dlang.org/post/fg15ev$12uh$1 digitalmars.com
Jan 24 2019
On Fri, 25 Jan 2019 05:04:41 +0000, Mike Parker wrote:On Friday, 25 January 2019 at 03:52:23 UTC, Neia Neutuladh wrote:Apologies for the misattribution, and thank you for correcting me.Credit to FeepingCreature for inventing this 5-10 years ago.2007 it seems, assuming FeepingCreature == downs: https://forum.dlang.org/post/fg15ev$12uh$1 digitalmars.com
Jan 24 2019
On Friday, 25 January 2019 at 05:20:37 UTC, Neia Neutuladh wrote:On Fri, 25 Jan 2019 05:04:41 +0000, Mike Parker wrote:I wasn't correcting, but genuinely curious if it was the same person :-)On Friday, 25 January 2019 at 03:52:23 UTC, Neia Neutuladh wrote:Apologies for the misattribution, and thank you for correcting me.Credit to FeepingCreature for inventing this 5-10 years ago.2007 it seems, assuming FeepingCreature == downs: https://forum.dlang.org/post/fg15ev$12uh$1 digitalmars.com
Jan 25 2019
On Friday, 25 January 2019 at 08:51:55 UTC, Mike Parker wrote:On Friday, 25 January 2019 at 05:20:37 UTC, Neia Neutuladh wrote:From https://forum.dlang.org/post/imqv4k$7kv$2 digitalmars.com: On Monday, 28 March 2011 at 21:38:29 UTC, FeepingCreature wrote:On Fri, 25 Jan 2019 05:04:41 +0000, Mike Parker wrote:I wasn't correcting, but genuinely curious if it was the same person :-)On Friday, 25 January 2019 at 03:52:23 UTC, Neia Neutuladh wrote:Apologies for the misattribution, and thank you for correcting me.Credit to FeepingCreature for inventing this 5-10 years ago.2007 it seems, assuming FeepingCreature == downs: https://forum.dlang.org/post/fg15ev$12uh$1 digitalmars.comI was d|owns but that name was stupid.-- Simen
Jan 25 2019
On Friday, 25 January 2019 at 03:52:23 UTC, Neia Neutuladh wrote:On Fri, 25 Jan 2019 03:45:36 +0000, Jonathan Levi wrote:Now that's a hack I can support.I know this was not an intentional feature of d, but it is a cool quirk. If you want to use a function that takes two arguments like a infix binary operator (similar to the back ticks in Haskell "`fun`") you can but a "." before and a "=" after. c = (a .fun= b);Consider also: struct Operator(alias fn) if (Parameters!fn.length == 2) { Curry opBinaryRight(string op)(Parameters!fn[0] arg) if (op == "/") { return Curry(arg); } struct Curry { Parameters!fn[0] arg; auto opBinaryRight(string op)(Parameters!fn[1] arg2) if (op == "/") { return fn(arg, arg2); } } } To use it: alias min = Operator!((a, b) => a < b ? a : b); writeln(1 /min/ 2); Credit to FeepingCreature for inventing this 5-10 years ago.
Jan 25 2019