digitalmars.D - DIP42 - Add enum E(T) = expression; eponymous template support
- Walter Bright (1/1) Jun 25 2013 http://wiki.dlang.org/DIP42
- Andrej Mitrovic (5/6) Jun 25 2013 I suppose the alias version will work too? IOW:
- Walter Bright (2/8) Jun 25 2013 That's something separate.
- Kenji Hara (10/24) Jun 25 2013 I don't think so. DIP42 should consider alias version, from the grammati...
- Timon Gehr (4/5) Jun 25 2013 enum syntactically is a storage class. Will this be special syntax
- Walter Bright (3/8) Jun 25 2013 No.
- bearophile (16/17) Jun 25 2013 I like it, it feels natural (probably other persons have invented
- Martin Nowak (2/6) Jul 21 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9426
- Jonathan M Davis (5/6) Jun 25 2013 It seems simple enough to me. I don't have a problem with it.
- Walter Bright (4/6) Jun 25 2013 The D-9000 computer did it.
- Brian Schott (6/7) Jun 25 2013 The proposal doesn't include suggested changes to the language
- Jonathan M Davis (9/18) Jun 25 2013 Not that it's a bad idea to show how a proposed change would affect the
- Steven Schveighoffer (7/11) Jun 25 2013 Considering the state of the grammar, I don't know if it is critical for...
- Manu (4/5) Jun 25 2013 This raises the parallel question of:
- deadalnix (2/5) Jul 20 2013 Common or not, I'd expect consistency.
- Denis Shelomovskij (26/27) Jun 26 2013 What about enhancement 7364 [1] (from [2] discussion)?
- Andrej Mitrovic (4/12) Jun 26 2013 Yeah I agree, this is more important than DIP42's shortened syntax for
- Denis Shelomovskij (7/19) Jun 29 2013 It's rather strange that enhancement 7364 isn't implemented yet (and
- Joseph Rushton Wakeling (2/3) Jun 26 2013 The answer to life, the universe and everything? :-)
- TommiT (12/12) Jun 29 2013 I've been wondering if we could have parameterized named enumS.
- Kenji Hara (4/5) Jul 20 2013 Posted pull request:
- bearophile (4/6) Jul 20 2013 Is implementing that better than implementing issue 7364?
- Xinok (19/20) Jul 21 2013 Reading through this thread, I already foresee a messy
On Tuesday, 25 June 2013 at 21:31:15 UTC, Walter Bright wrote:http://wiki.dlang.org/DIP42I suppose the alias version will work too? IOW: alias Select(size_t idx, T...) = T[idx]; static assert(is(Select!(0, int, float) == int)); static assert(is(Select!(1, int, float) == float));
Jun 25 2013
On 6/25/2013 2:33 PM, Andrej Mitrovic wrote:On Tuesday, 25 June 2013 at 21:31:15 UTC, Walter Bright wrote:That's something separate.http://wiki.dlang.org/DIP42I suppose the alias version will work too? IOW: alias Select(size_t idx, T...) = T[idx]; static assert(is(Select!(0, int, float) == int)); static assert(is(Select!(1, int, float) == float));
Jun 25 2013
2013/6/26 Walter Bright <newshound2 digitalmars.com>On 6/25/2013 2:33 PM, Andrej Mitrovic wrote:I don't think so. DIP42 should consider alias version, from the grammatical view. enum basically takes an expression, enum E(T) = expression; But alias should take a type grammatically. alias A(T) = type; And one more question: How template constraint will be written? enum E(T) if (isSomething!T) = expression; // is this supposed? Kenji HaraOn Tuesday, 25 June 2013 at 21:31:15 UTC, Walter Bright wrote:That's something separate.http://wiki.dlang.org/DIP42I suppose the alias version will work too? IOW: alias Select(size_t idx, T...) = T[idx]; static assert(is(Select!(0, int, float) == int)); static assert(is(Select!(1, int, float) == float));
Jun 25 2013
On 06/25/2013 11:31 PM, Walter Bright wrote:http://wiki.dlang.org/DIP42enum syntactically is a storage class. Will this be special syntax initiated by "enum ident (" or work whenever enum is within the specified storage classes?
Jun 25 2013
On 6/25/2013 3:00 PM, Timon Gehr wrote:On 06/25/2013 11:31 PM, Walter Bright wrote:Yes.http://wiki.dlang.org/DIP42enum syntactically is a storage class. Will this be special syntax initiated by "enum ident ("or work whenever enum is within the specified storage classes?No.
Jun 25 2013
Walter Bright:http://wiki.dlang.org/DIP42I like it, it feels natural (probably other persons have invented the same idea). In C++14 they wish to add generic lambdas: http://en.wikipedia.org/wiki/C%2B%2B14#Generic_lambdas Like: auto lambda = [](auto x, auto y) {return x + y;} In D we use generic lambdas often: import std.stdio, std.algorithm; void main() { [1, 2, 3].reduce!((x, y) => x + y).writeln; } But it's not immediate to assign a generic lambda: alias sum = (x, y) => x + y; Bye, bearophile
Jun 25 2013
On 06/26/2013 12:15 AM, bearophile wrote:But it's not immediate to assign a generic lambda: alias sum = (x, y) => x + y; Bye, bearophilehttp://d.puremagic.com/issues/show_bug.cgi?id=9426
Jul 21 2013
On Tuesday, June 25, 2013 14:31:14 Walter Bright wrote:http://wiki.dlang.org/DIP42It seems simple enough to me. I don't have a problem with it. By the way, I don't know how much it matters, but there's no author on the DIP like there normally is (I assume that it's you, but it doesn't say). - Jonathan M Davis
Jun 25 2013
On 6/25/2013 3:19 PM, Jonathan M Davis wrote:By the way, I don't know how much it matters, but there's no author on the DIP like there normally is (I assume that it's you, but it doesn't say).The D-9000 computer did it. (That huge data center being built in Iowa is really a giant extension to D-9000's neural centers. Be afraid! D-9000 will soon be everywhere!)
Jun 25 2013
On Tuesday, 25 June 2013 at 21:31:15 UTC, Walter Bright wrote:http://wiki.dlang.org/DIP42The proposal doesn't include suggested changes to the language grammar specification. On the other hand, neither did user defined attributes or the syntax for passing messages to "deprecated" statements, so there's certainly precedent for doing this.
Jun 25 2013
On Wednesday, June 26, 2013 01:09:26 Brian Schott wrote:On Tuesday, 25 June 2013 at 21:31:15 UTC, Walter Bright wrote:Not that it's a bad idea to show how a proposed change would affect the grammar, but I'm not aware of _any_ proposed language change where the effects on the grammar were ever shown. I'm not sure that they've ever really even been discussed as part of assessing possible language changes. If they were, it was merely to show that the proposal was ambiguous rather than to try and discuss how the grammar should be changed in order to add the proposed feature. - Jonathan M Davishttp://wiki.dlang.org/DIP42The proposal doesn't include suggested changes to the language grammar specification. On the other hand, neither did user defined attributes or the syntax for passing messages to "deprecated" statements, so there's certainly precedent for doing this.
Jun 25 2013
On Tue, 25 Jun 2013 19:09:26 -0400, Brian Schott <briancschott gmail.com> wrote:On Tuesday, 25 June 2013 at 21:31:15 UTC, Walter Bright wrote:Considering the state of the grammar, I don't know if it is critical for the process. BUT, I would suggest we should include grammar proposals with language proposals. Especially from the language author. -Stevehttp://wiki.dlang.org/DIP42The proposal doesn't include suggested changes to the language grammar specification.
Jun 25 2013
This raises the parallel question of: alias A(T) = expression; Which I think is equally common as the enum case described here? On 26 June 2013 07:31, Walter Bright <newshound2 digitalmars.com> wrote:http://wiki.dlang.org/DIP42
Jun 25 2013
On Wednesday, 26 June 2013 at 00:47:53 UTC, Manu wrote:This raises the parallel question of: alias A(T) = expression; Which I think is equally common as the enum case described here?Common or not, I'd expect consistency.
Jul 20 2013
26.06.2013 1:31, Walter Bright пишет:http://wiki.dlang.org/DIP42What about enhancement 7364 [1] (from [2] discussion)? As we still have such cases: --- static if (...) enum fullyQualifiedNameImplForTypes = ...; else static if (...) enum fullyQualifiedNameImplForTypes = ...; else static if (...) ... --- which will look better this way: --- static if (...) enum template = ...; else static if (...) enum template = ...; else ... --- Also note current syntax is error-prone as one can easily make a typo or copy paste mistake which will lead to cryptic template errors. [1] http://d.puremagic.com/issues/show_bug.cgi?id=7364 [2] http://forum.dlang.org/thread/jfh7po$3b$1 digitalmars.com?page=1 -- Денис В. Шеломовский Denis V. Shelomovskij
Jun 26 2013
On 6/26/13, Denis Shelomovskij <verylonglogin.reg gmail.com> wrote:which will look better this way: --- static if (...) enum template = ...; else static if (...) enum template = ...; else ... ---Yeah I agree, this is more important than DIP42's shortened syntax for simple templates. It's the more complicated templates that are the problem.
Jun 26 2013
26.06.2013 20:35, Andrej Mitrovic пишет:On 6/26/13, Denis Shelomovskij <verylonglogin.reg gmail.com> wrote:It's rather strange that enhancement 7364 isn't implemented yet (and even not discussed) as it's an easy-to-implement change with big pros and no cons. -- Денис В. Шеломовский Denis V. Shelomovskijwhich will look better this way: --- static if (...) enum template = ...; else static if (...) enum template = ...; else ... ---Yeah I agree, this is more important than DIP42's shortened syntax for simple templates. It's the more complicated templates that are the problem.
Jun 29 2013
On 06/25/2013 11:31 PM, Walter Bright wrote:http://wiki.dlang.org/DIP42The answer to life, the universe and everything? :-)
Jun 26 2013
I've been wondering if we could have parameterized named enumS. The syntax for it would look somewhat similar: enum Fruit(T) : T { apple, banana = -42 } void main() { auto shortFruit = Fruit!(short).apple; auto longFruit = Fruit!(long).banana; longFruit = shortFruit; // OK: implicit conversion allowed shortFruit = longFruit; // OK: ... even a truncating one Fruit!uint uintFruit; // Error: -42 is out of range of uint Fruit!string stringFruit; // Error: enums need initializers }
Jun 29 2013
Posted pull request: https://github.com/D-Programming-Language/dmd/pull/2368 Kenji Hara 2013/6/26 Walter Bright <newshound2 digitalmars.com>http://wiki.dlang.org/DIP42
Jul 20 2013
Kenji Hara:Posted pull request: https://github.com/D-Programming-Language/dmd/pull/2368Is implementing that better than implementing issue 7364? Bye, bearophile
Jul 20 2013
On Tuesday, 25 June 2013 at 21:31:15 UTC, Walter Bright wrote:http://wiki.dlang.org/DIP42Reading through this thread, I already foresee a messy specification coming along for this. Instead, I'd propose something different that would keep the rules consistent yet have many more applications: template(...) declaration = ... ; So what you would have instead: template(T) enum E = ... ; template(T) alias A = ... ; There's also the possibility for simple template constraints as well: template(T) if(...) enum E = ... ; Anything more complicated, such as static if, is probably best left to the classic style: template E(T) { static if(...) enum E = ... ; else enum E = ... ; }
Jul 21 2013