View mode: basic / threaded / horizontal-split · Log in · Help
May 31, 2007
Re: Suffix-based literal syntax
Reiner Pope wrote:
> Here's a small thought to improve the syntax for some user-defined 
> types: can we perhaps overload the suffix on literals, to give some user 
> types nicer literals?
> [...]

I've considered it and argued for it before, but when it comes down to 
it, how much is this going to be used?  Really, it's only going to be 
used for manifest constants, which tend to not be terribly numerous. 
Most other uses of dimensional types are as *variables*, and there the 
dimension is encoded in the type, not the suffix.  The fact that we can 
get "almost there" syntax demotivates this feature for some folks.

Dave
May 31, 2007
Re: Suffix-based literal syntax
I like that more; it's clearer.

Daniel Keep Wrote:

> 
> 
> Reiner Pope wrote:
> > Reiner Pope wrote:
> >> I envisage a usage something like this:
> >>
> >> struct LengthKM { ... }
> >> alias LengthKM.opCall opSuff_km;
> >> // Of course this would actually be auto generated by a template, but
> >> still...
> > 
> > Oh, and you might want:
> > 
> > struct Length {...}
> > 
> > Length opSuff_km(real r) { return Length(1000, r); }
> > Length opSuff_m(real r) { return Length(1, r); }
> > Length opSuff_mm(real r) { return Length(0.001, r); }
> 
> What if we just got type extensions instead?
> 
> Length km(this real r) { return Length(1000, r); }
> Length m(this real r) { return Length(1000, r); }
> 
> auto distance = 15 .km; // Space to break the float literal
> auto otherdis = (10).m; // Or use parens
> 
> That way, we don't need any new parsing rules, and this can be extended
> to any type, to do pretty much anything you want.
> 
> 	-- Daniel
> 
> -- 
> int getRandomNumber()
> {
>     return 4; // chosen by fair dice roll.
>               // guaranteed to be random.
> }
> 
> http://xkcd.com/
> 
> v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
> i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home