digitalmars.D - Attributes on parameters in functions.
- TheFlyingFiddle (33/33) Oct 30 2015 In other languages that have Attributes (Java and C# atleast)
- Meta (3/37) Oct 30 2015 Some people wanted it when UDAs were first added to D but Walter
- Timon Gehr (2/10) Oct 30 2015 http://forum.dlang.org/thread/k7afq6$2832$1@digitalmars.com?page=14
- Jacob Carlborg (4/17) Oct 31 2015 https://github.com/D-Programming-Language/dmd/pull/4783
- TheFlyingFiddle (4/24) Oct 31 2015 This looks very promising I hope something like this get's pulled
I can do stuff like this: (Java) //com.bar.java interface Bar { /*stuff*/ } //com.foo.java class Foo { Foo( Bar int a) { //some stuff } } I don't seem to be able to do this in D. That is I cannot do this: enum Bar; void foo( Bar int a) { /* stuff */ } //Error: basic type expected, not Is there a reason that attributes cannot be used on parameters in functions? My current use-case for this is that I would like to use UDA's for pattern matching. auto value = Tuple!(int, "x", int, "y")(1,1); value.match!( ( (0,1) int a, (0,1) int b) => ..., ( isPrime int a, int b) => ..., ( (x => (x % 2)) int a, int b) => ..., ( Bind!"y" int a) => ...); Basically match to the first lambda if "x" == 0 | 1 and "y" == 0 | 1, to the second if a "x" is prime third if "x" is odd, else explicitly bind "y" to a. I know I can technically do. Match! or M! instead of the symbol to achieve the same effect which is probably what I will end up doing but it would be nice if we could use attributes in function parameters.
Oct 30 2015
On Friday, 30 October 2015 at 21:28:09 UTC, TheFlyingFiddle wrote:I can do stuff like this: (Java) //com.bar.java interface Bar { /*stuff*/ } //com.foo.java class Foo { Foo( Bar int a) { //some stuff } } I don't seem to be able to do this in D. That is I cannot do this: enum Bar; void foo( Bar int a) { /* stuff */ } //Error: basic type expected, not Is there a reason that attributes cannot be used on parameters in functions? My current use-case for this is that I would like to use UDA's for pattern matching. auto value = Tuple!(int, "x", int, "y")(1,1); value.match!( ( (0,1) int a, (0,1) int b) => ..., ( isPrime int a, int b) => ..., ( (x => (x % 2)) int a, int b) => ..., ( Bind!"y" int a) => ...); Basically match to the first lambda if "x" == 0 | 1 and "y" == 0 | 1, to the second if a "x" is prime third if "x" is odd, else explicitly bind "y" to a. I know I can technically do. Match! or M! instead of the symbol to achieve the same effect which is probably what I will end up doing but it would be nice if we could use attributes in function parameters.Some people wanted it when UDAs were first added to D but Walter didn't see any reason to so he didn't.
Oct 30 2015
On 10/31/2015 02:02 AM, Meta wrote:On Friday, 30 October 2015 at 21:28:09 UTC, TheFlyingFiddle wrote:http://forum.dlang.org/thread/k7afq6$2832$1 digitalmars.com?page=14... I know I can technically do. Match! or M! instead of the symbol to achieve the same effect which is probably what I will end up doing but it would be nice if we could use attributes in function parameters.Some people wanted it when UDAs were first added to D but Walter didn't see any reason to so he didn't.
Oct 30 2015
On 2015-10-30 22:28, TheFlyingFiddle wrote:I can do stuff like this: (Java) //com.bar.java interface Bar { /*stuff*/ } //com.foo.java class Foo { Foo( Bar int a) { //some stuff } } I don't seem to be able to do this in D. That is I cannot do this:https://github.com/D-Programming-Language/dmd/pull/4783 -- /Jacob Carlborg
Oct 31 2015
On Saturday, 31 October 2015 at 12:45:13 UTC, Jacob Carlborg wrote:On 2015-10-30 22:28, TheFlyingFiddle wrote:This looks very promising I hope something like this get's pulled eventually.I can do stuff like this: (Java) //com.bar.java interface Bar { /*stuff*/ } //com.foo.java class Foo { Foo( Bar int a) { //some stuff } } I don't seem to be able to do this in D. That is I cannot do this:https://github.com/D-Programming-Language/dmd/pull/4783
Oct 31 2015