Standard way to supply hints to branches

Daniel N no at public.email
Fri Sep 13 20:23:01 UTC 2024


On Friday, 13 September 2024 at 18:53:11 UTC, Walter Bright wrote:
>
> Hence, if D were to support something along those lines, it 
> would be a keyword such as:
>
> ```
> ifrarely (i) return 0;
> ```
>
> as the least ugly approach. But I've been unable to come up 
> with an obviously good keyword for it. And we would need buyin 
> from Iain and Martin.

ifrarely is nice, but I prefer swift style guard.


```swift
func ex(maybe : Int?)
{
     guard let val = maybe else {
         // implicitly unlikely
         print("early exit")
         return
     }

     // look ma - val is in scope here!
     print("val = ", val)
}

ex(maybe:1)
ex(maybe:nil)
```


More information about the Digitalmars-d mailing list