digitalmars.dip.ideas - Case dot syntax
- monkyyy (30/30) Feb 26 several languages have implicit enum handling for switch
- Richard (Rikki) Andrew Cattermole (2/2) Feb 26 Dot expressions like this, already exist and refer to module
- Bradley Chatha (13/14) Mar 01 We also have the `with` statement:
- Juraj (10/24) Mar 01 This is always proposed, but `with` will now by active for the
- Walter Bright (8/16) Mar 06 I use this:
- monkyyy (5/22) Mar 09 Which does not do anything for non-enums; explicitly rikkis dip
several languages have implicit enum handling for switch
statements
```d
enum foo{a,b,c}
switch(somefoo){
case .a: ...
```
add that for enums
---
for user types, require the types define an enum `opGetTypes`
thats an array of string and an `opCastDot`
```d
struct nullable(T){
T get;
bool isnull;
enum opGetTypes=["null","value"];
ref T opCastDot(string s:"value")()=>get;
void opCastDot(string s:"null")(){}
}
```
this will enable
```d
final switch(somenullable){
case .value: value.writeln; break;
case .null: "error".writeln;
}
```
Making rikkis recent dip work for one then one case(I can easily
imagine this working for sumtypes); and matching some other
languages syntax.
Feb 26
Dot expressions like this, already exist and refer to module level symbols.
Feb 26
On Thursday, 26 February 2026 at 21:29:39 UTC, monkyyy wrote:...We also have the `with` statement: ```d enum SomeFoo { a, b, c } SomeFoo foo = ...; final switch(foo) with(SomeFoo) // or if you're extra: with(typeof(foo)) { case a: case b: case c: ... } ```
Mar 01
On Sunday, 1 March 2026 at 08:56:03 UTC, Bradley Chatha wrote:On Thursday, 26 February 2026 at 21:29:39 UTC, monkyyy wrote:This is always proposed, but `with` will now by active for the whole switch scope, I never successfully adopted this pattern in my codebase, also `switch` statement is not the only usecase for this feature. Imo `.` is the most ergonomic, there is an implementation using `$.` but the is hard on the eyes. I sadly did not found any alternative that did not "suck" in some way or another. In an ideal world, I would repurpose dot expression to something like `::`/`:`....We also have the `with` statement: ```d enum SomeFoo { a, b, c } SomeFoo foo = ...; final switch(foo) with(SomeFoo) // or if you're extra: with(typeof(foo)) { case a: case b: case c: ... } ```
Mar 01
On 2/26/2026 1:29 PM, monkyyy wrote:
several languages have implicit enum handling for switch statements
```d
enum foo{a,b,c}
switch(somefoo){
case .a: ...
```
I use this:
```d
enum foo{a,b,c};
with (foo) switch (somefoo)
{
case a: ...
``
Mar 06
On Friday, 6 March 2026 at 20:38:59 UTC, Walter Bright wrote:On 2/26/2026 1:29 PM, monkyyy wrote:Which does not do anything for non-enums; explicitly rikkis dip and my 2nd example is about nullable. By pushing it into switch Im suggesting it can have a unified syntax for enum, nullable and sumtype.several languages have implicit enum handling for switch statements ```d enum foo{a,b,c} switch(somefoo){ case .a: ... ```I use this: ```d enum foo{a,b,c}; with (foo) switch (somefoo) { case a: ... ``
Mar 09









Richard (Rikki) Andrew Cattermole <richard cattermole.co.nz> 