Where should I put a `condp` like function?

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Mon Apr 15 10:00:33 PDT 2013


On Sun, 14 Apr 2013 22:00:18 -0700
"H. S. Teoh" <hsteoh at quickfur.ath.cx> wrote:

> On Sun, Apr 14, 2013 at 11:46:04PM -0400, Nick Sabalausky wrote:
> > I've never seen a big problem with the statement vs expression
> > distinction, and I think the "statements == expresions" languages
> > sometimes takes things slightly overboard in the process of forcing
> > them into the same mold. However, I've *definitely* wished on many
> > occasions that D's switch could be used as an expression like in
> > Haxe.
> 
> Allowing arbitrary predicates and switch-as-expression allows you to
> write code that shows intent very clearly:
> 
> 	// In pseudo-D syntax
> 	void fill(T)(T image, int x, int y) {
> 		image[x,y] = switch {
> 			case isFillable(image,x,y): fillColor;
> 			case isBorder(image,x,y): borderColor;
> 			default: defaultColor;
> 		};
> 	}
> 

Yup, like I said, I've definitely wished that D's switch could be used
as an expression



More information about the Digitalmars-d mailing list