Re: The cast(signed), cast(unsigned) feature proposal

2013-06-08 Thread deadalnix
On Friday, 7 June 2013 at 20:52:53 UTC, Mrzlga wrote: - Use the library for it and instead make signed(x), unsigned(x) templates. This !

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Marco Leise
Am Fri, 07 Jun 2013 17:03:47 -0400 schrieb Andrei Alexandrescu : > On 6/7/13 4:52 PM, Mrzlga wrote: > > Hi guys, > > > > This is a small feature proposal. > > Please consider to add these to the language: > > > > cast(signed) > > cast(unsigned) > > http://dlang.org/phobos/std_traits.html#.unsigne

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Mrzlga
So, let me get this straight: * You don't want `cast(signed)`, because of the range difference between the types. * You want `cast(signed int)` but not as syntactic salt - which means you still want `cast(int)` to work. How about `cast(/*signed*/ int)`? - I do want cast(signed) - I don'

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Walter Bright
On 6/7/2013 2:33 PM, Mrzlga wrote: Yet we can easily grep for: cast(signed) Not/*"*/"*/that easy

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Idan Arye
On Saturday, 8 June 2013 at 01:58:46 UTC, Mrzlga wrote: So, you want a syntactic salt that will force people to write No, no, I don't actually want the salt. I hoped I had indicated that in my message. It was only for your consideration about cast(int), how it would be nice to "indicate eve

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Timothee Cour
the point is to avoid breaking code. Since no-one can possibly use cast(unsigned) currently, introducing Cast and recommending using Cast instead of cast() will not break any code and provide room for library based cast extensions. The smaller the symbols in scope and the shorter the syntax the be

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Mrzlga
not suggesting deprecating cast(), just suggesting there's no need to extend the language as it can be done in library code, advantageously. It's trivially extensible as I wrote it. However, any language extension has to be re-implemented by each compiler implementation. I don't think you ca

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread timotheecour
On Saturday, 8 June 2013 at 02:21:01 UTC, Timothee Cour wrote: not to mention its much harder to implement in language, whereas its trivial in the library. Also, it makes instrumentation easier, if one wants to add a callback/logging/breakpoint for a particular cast operation. Seems much harde

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Timothee Cour
not to mention its much harder to implement in language, whereas its trivial in the library. Also, it makes instrumentation easier, if one wants to add a callback/logging/breakpoint for a particular cast operation. Seems much harder with language solution. On Fri, Jun 7, 2013 at 6:53 PM, Mrzlga w

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Mrzlga
I don't know the story of how D resolved to not provide 'ulong' and 'unsigned long' as equivalent, but I do understand the motivation to keep things short and standard, with 1-word-per-basic-type. I should say one thing though, In C / C++: unsigned x = f(); // this was traumatic. "unsigned

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Timothee Cour
On Fri, Jun 7, 2013 at 6:53 PM, Mrzlga wrote: > Timothy, > > How do you get everyone to use: > a.Cast!Signed > a.Cast!Unsigned > a.Cast!Const > a.Cast!Immutable > a.Cast!Shared > > And to stop using: > cast(const) > cast(immutable) > cast(shared) > cast(inout)

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Mrzlga
So, you want a syntactic salt that will force people to write No, no, I don't actually want the salt. I hoped I had indicated that in my message. It was only for your consideration about cast(int), how it would be nice to "indicate everything" if there was no price to it.

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Mrzlga
Timothy, How do you get everyone to use: a.Cast!Signed a.Cast!Unsigned a.Cast!Const a.Cast!Immutable a.Cast!Shared And to stop using: cast(const) cast(immutable) cast(shared) cast(inout) ? And have everyone be consistent about it? Remove the cast() ones from

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Idan Arye
On Saturday, 8 June 2013 at 00:43:28 UTC, Mrzlga wrote: "doing nothing but converting unsigned->signed" is a dubious statement. They are still screwing with the range, they are not just "doing nothing but converting unsigned->signed". And 'int' says something about the outcome. So I am reall

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Timothee Cour
I'm against it since we can do it better in library with same efficiency and better UFCS syntax: see https://github.com/timotheecour/dtools/blob/master/dtools/util/cast_funs.d to test it, nothing to install, just type: rdmd --main -unittest dtools/all.d here's the unittest: version(unittest

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Mrzlga
"doing nothing but converting unsigned->signed" is a dubious statement. They are still screwing with the range, they are not just "doing nothing but converting unsigned->signed". And 'int' says something about the outcome. So I am really asking for: cast(signed int) x; // make them poor pr

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Mrzlga
How about this: if `Foo` is a template with a single type parameter that returns a type, writing `cast(Foo)bar` will be parsed as `cast(Foo!(typeof(bar))bar`. My proposal has a bad thing about it: The 'unsigned' and 'signed' keywords can't be as easily extended the way that an signed(x) templ

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Andrei Alexandrescu
On 6/7/13 5:41 PM, Mrzlga wrote: Andrei, what do you think about the unsigned(x) not showing up on greps for 'cast'? No problem? Is the grep irrelevant? Not all casts should be marked as a cast? People told me the grepping was important, so I tried to work their idea in. I understand, you can

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Idan Arye
On Friday, 7 June 2013 at 21:42:05 UTC, Jesse Phillips wrote: On Friday, 7 June 2013 at 21:34:00 UTC, Mrzlga wrote: A reason for cast(signed) is to discourage the user from writing: cast(int) x; Because we can't grep for the word "signed", We have to search for "cast( )" only! cast(int

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Idan Arye
On Friday, 7 June 2013 at 22:05:46 UTC, Idan Arye wrote: but not as good as the template solution Should be "not as good as the syntactic sugar solution"

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Jesse Phillips
On Friday, 7 June 2013 at 21:34:00 UTC, Mrzlga wrote: A reason for cast(signed) is to discourage the user from writing: cast(int) x; Because we can't grep for the word "signed", We have to search for "cast( )" only! cast(int) x// hides the intention, hard to search for! Yet we ca

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Mrzlga
Andrei, what do you think about the unsigned(x) not showing up on greps for 'cast'? No problem? Is the grep irrelevant? Not all casts should be marked as a cast? People told me the grepping was important, so I tried to work their idea in. I understand, you can still search for: "signed("

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Mrzlga
A reason for cast(signed) is to discourage the user from writing: cast(int) x; Because we can't grep for the word "signed", We have to search for "cast( )" only! cast(int) x// hides the intention, hard to search for! Yet we can easily grep for: cast(signed)

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread monarch_dodra
On Friday, 7 June 2013 at 21:04:40 UTC, monarch_dodra wrote: On Friday, 7 June 2013 at 20:52:53 UTC, Mrzlga wrote: That's it! Thanks for your consideration :) FWI, you can use std.trait's Signed and Unsigned as a partial alternative. http://dlang.org/phobos/std_traits.html#.Signed IMO, not

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Adam D. Ruppe
On Friday, 7 June 2013 at 20:52:53 UTC, Mrzlga wrote: - Use the library for it and instead make signed(x), unsigned(x) templates. I think this is a really strong counterargument and one I'd like to see done, along with other kinds of casts in the library. > Downsides to this solution: Us

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread monarch_dodra
On Friday, 7 June 2013 at 20:52:53 UTC, Mrzlga wrote: That's it! Thanks for your consideration :) FWI, you can use std.trait's Signed and Unsigned as a partial alternative. http://dlang.org/phobos/std_traits.html#.Signed IMO, not quite as elegant. I support this syntax. It's natural, and I

Re: The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Andrei Alexandrescu
On 6/7/13 4:52 PM, Mrzlga wrote: Hi guys, This is a small feature proposal. Please consider to add these to the language: cast(signed) cast(unsigned) http://dlang.org/phobos/std_traits.html#.unsigned We should prolly add signed() as well. Could you please author an enhancement request (and

The cast(signed), cast(unsigned) feature proposal

2013-06-07 Thread Mrzlga
Hi guys, This is a small feature proposal. Please consider to add these to the language: cast(signed) cast(unsigned) Motivation: - To remove the need to write "cast(ulong) x" and repeat the underlying type, which is the same motivation as cast(const), cast(immutable), cast(shared)