Re: Is the world coming to an end?

2011-04-02 Thread Aleksandar Ružičić
Nice to see awkward octal literal syntax being removed from Phobos! :)

On Sat, Apr 2, 2011 at 10:16 PM, Andrej Mitrovic  wrote:
> https://github.com/D-Programming-Language/phobos/commit/83f99df573c089cc186ef370cb691c2f8a25c873
> https://github.com/D-Programming-Language/phobos/commit/88904f7795a94b23e750e10a2addc90783089de7
>
> If I didn't know it better I would think it's still April 1st. :D
>


Re: Is the world coming to an end?

2011-04-02 Thread bearophile
Andrej Mitrovic:

> If I didn't know it better I would think it's still April 1st. :D

I don't like the "octal!" a lot, I prefer a syntax like the Python3 one, but 
Walter never stops moving himself forward :-)

Bye,
bearophile


Re: Is the world coming to an end?

2011-04-02 Thread Mafi

Am 02.04.2011 23:38, schrieb bearophile:

Andrej Mitrovic:


If I didn't know it better I would think it's still April 1st. :D


I don't like the "octal!" a lot, I prefer a syntax like the Python3 one, but 
Walter never stops moving himself forward :-)

Bye,
bearophile


No ofence, but I sometimes get the opinion that you think something is 
better just because there's "Python" written on it.
But sure, syntaxes are a matter of taste and people shouldn't dispute 
about tastes.


Mafi

PS I don't want to say every of Python's decisions is wrong. Many of 
them are great (but defenitely not significant intendation).


Re: Is the world coming to an end?

2011-04-02 Thread Daniel Gibson
Am 02.04.2011 23:38, schrieb bearophile:
> Andrej Mitrovic:
> 
>> If I didn't know it better I would think it's still April 1st. :D
> 
> I don't like the "octal!" a lot, I prefer a syntax like the Python3 one, 

Come on: the C-style octal syntax is bad (see [1]) and can lead to strange bugs,
so it's a huge win that it's finally killed, even if you don't like the new
syntax :-)
In general octal numbers are rarely needed (I guess), so the somehow clumsy
octal!123 syntax doesn't matter. Also it's more readable (self-documenting) for
someone not used to octal numbers than Python3's 0o123.

Also congratulations to spir, I guess his "0nnn octal notation considered
harmful" thread[1] was a good argument for this step :-)


Cheers,
- Daniel

[1]
http://www.digitalmars.com/d/archives/digitalmars/D/0nnn_octal_notation_considered_harmful_129416.html


Re: Is the world coming to an end?

2011-04-02 Thread bearophile
Daniel Gibson:

> In general octal numbers are rarely needed (I guess), so the somehow clumsy
> octal!123 syntax doesn't matter. Also it's more readable (self-documenting) 
> for
> someone not used to octal numbers than Python3's 0o123.

I agree.

Bye,
bearophile


Re: Is the world coming to an end?

2011-04-02 Thread Daniel Gibson
Am 03.04.2011 00:00, schrieb ulrik.mikaels...@gmail.com:
> About time someone dropped the 0777-nonsense. The least common digit-base 
> should
> not easily be invoked "by accident".
> 
> However:
> 
> 
>> I don't like the "octal!" a lot, I prefer a syntax like the Python3 one, but
>> Walter never stops moving himself forward :-)
> 
> I too was just about to ask why on earth "octal!" instead of 0o (and I didn't
> know about Python3).
> 
> Sure, I think it's nice and clean language-wise to implement it as a
> template-function, but if so the same should go for 0b and 0x? Are they too
> deprecated in D2?
> 

0b and 0x are not "dangerous" so there's no need to remove/deprecate them and
thus cause breakage of code using them.
At least 0x is quite common (certainly more common than octal numbers) so it
makes sense to have this short syntax (IMHO).

Cheers,
- Daniel


Re: Is the world coming to an end?

2011-04-02 Thread KennyTM~

On Apr 3, 11 06:27, ulrik.mikaels...@gmail.com wrote:

A D-newbie would probably be able to guess 0o for octal, but hardly
octal!. octal! breaks the rule of least surprise.


Except a big error

octal literals 011 are deprecated, use std.conv.octal!11 instead

will be emitted when the said newbie tries to compile with 011 :). See 
commit 
https://github.com/D-Programming-Language/dmd/commit/87afe713711060ec73942d1a94d3e28024781932


Re: Is the world coming to an end?

2011-04-02 Thread KennyTM~

On Apr 3, 11 06:49, KennyTM~ wrote:

On Apr 3, 11 06:27, ulrik.mikaels...@gmail.com wrote:

A D-newbie would probably be able to guess 0o for octal, but hardly
octal!. octal! breaks the rule of least surprise.


Except a big error

octal literals 011 are deprecated, use std.conv.octal!11 instead

will be emitted when the said newbie tries to compile with 011 :). See
commit
https://github.com/D-Programming-Language/dmd/commit/87afe713711060ec73942d1a94d3e28024781932



But of course

 1. this message is specific to the dmd front-end. Other lexers might
not show this message
 2. this assumes std.conv.octal exists, though it may not be the case
(e.g. using Tango without Phobos (well Tango devs could add just
std.conv.octal)).


Re: Is the world coming to an end?

2011-04-02 Thread Daniel Gibson
Am 03.04.2011 00:58, schrieb KennyTM~:
> On Apr 3, 11 06:49, KennyTM~ wrote:
>> On Apr 3, 11 06:27, ulrik.mikaels...@gmail.com wrote:
>>> A D-newbie would probably be able to guess 0o for octal, but hardly
>>> octal!. octal! breaks the rule of least surprise.
>>
>> Except a big error
>>
>> octal literals 011 are deprecated, use std.conv.octal!11 instead
>>
>> will be emitted when the said newbie tries to compile with 011 :). See
>> commit
>> https://github.com/D-Programming-Language/dmd/commit/87afe713711060ec73942d1a94d3e28024781932
>>
>>
> 
> But of course
> 
>  1. this message is specific to the dmd front-end. Other lexers might
> not show this message
>  2. this assumes std.conv.octal exists, though it may not be the case
> (e.g. using Tango without Phobos (well Tango devs could add just
> std.conv.octal)).

If Tango is ever ported to D2 it should be possible to use Phobos and Tango at
the same time (thanks to druntime), so that shouldn't be an issue, right?


Re: Is the world coming to an end?

2011-04-02 Thread Michel Fortin

On 2011-04-02 18:27:12 -0400, ulrik.mikaels...@gmail.com said:


011 = 11
0b11 = 3
0x11 = 17
0o11 = 9

is much more consistent than

011 = 11
0b11 = 3
0x11 = 17
octal!11 = 9


I too would prefer 0o11 for consistency.

It's funny that D (the language) has binary notation built-in (which C 
doesn't have) but no octal notation anymore (which C has). You now have 
to resort to a library template for that, and it doesn't work for big 
numbers: try assert(octal!17 == 
0x___). Not that I expect anyone to want to write big 
64-bit numbers in octal, but it makes the new "official" octal notation 
more like a hack.


But it's a good thing that the old error-prone octal notation is 
deprecated. So overall I think the change is positive, I just find the 
replacement a little too hackish.


--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/



Re: Is the world coming to an end?

2011-04-02 Thread Andrei Alexandrescu

On 4/2/11 5:27 PM, ulrik.mikaels...@gmail.com wrote:

A D-newbie would probably be able to guess 0o for octal, but hardly
octal!. octal! breaks the rule of least surprise.


I fail to infer how using the word "octal" for an octal literal is 
surprising at all.


This thread is a good example that it's impossible to please everyone. 
Although past discussions made it clear that most everyone found leading 
0 a poor convention for octal numbers, now not only the consensus is 
weaker, but some actually claim a different solution is superior. If 
that were chosen, then all of a sudden octal!777 would have become 
suddenly sexy and so on.


The grass is always greener on the other side...


Andrei


Re: Is the world coming to an end?

2011-04-02 Thread Daniel Gibson
Am 03.04.2011 01:20, schrieb Andrei Alexandrescu:
> On 4/2/11 5:27 PM, ulrik.mikaels...@gmail.com wrote:
>> A D-newbie would probably be able to guess 0o for octal, but hardly
>> octal!. octal! breaks the rule of least surprise.
> 
> I fail to infer how using the word "octal" for an octal literal is surprising 
> at
> all.
> 
> This thread is a good example that it's impossible to please everyone. 
> Although
> past discussions made it clear that most everyone found leading 0 a poor
> convention for octal numbers, now not only the consensus is weaker, but some
> actually claim a different solution is superior. If that were chosen, then all
> of a sudden octal!777 would have become suddenly sexy and so on.
> 
> The grass is always greener on the other side...
> 
> 
> Andrei

I don't think the consensus that a leading 0 is a poor convention for octal
numbers is weaker now - so far nobody wants the old syntax back :)


Re: Is the world coming to an end?

2011-04-02 Thread Walter Bright

On 4/2/2011 2:38 PM, bearophile wrote:

Andrej Mitrovic:


If I didn't know it better I would think it's still April 1st. :D


I don't like the "octal!" a lot, I prefer a syntax like the Python3 one



The point is that "octal!" is not a syntax. It's completely a library 
construction.


Re: Is the world coming to an end?

2011-04-02 Thread bearophile
Andrei:

> Although past discussions made it clear that most everyone found leading 
> 0 a poor convention for octal numbers, now not only the consensus is 
> weaker,

The consensus was as much strong as now that the leading zero to denote octals 
is bad. But even in past some people (like me) have suggested more than one 
replacement syntax (see Bugzilla). So I am seeing nothing new in the 
discussions of today.


> If that were chosen, then all of a sudden octal!777 would have become 
> suddenly sexy and so on.

You have no proof of this.

By the way, I am happy of this (unannounced) change.

Bye,
bearophile


Re: Is the world coming to an end?

2011-04-02 Thread Daniel Gibson
Am 03.04.2011 01:50, schrieb Walter Bright:
> On 4/2/2011 3:27 PM, ulrik.mikaels...@gmail.com wrote:
>> As I wrote, I think it's great that 010 != 8 anymore.
> 
> 010, etc., will now be errors. They will not be 10 decimal.
> 
> Also, the literals 00, 01, ..., 07 will still be accepted without complaint. 
> 08,
> 09, etc. will of course be errors.

That feels pretty inconsistent.

Cheers,
- Daniel


Re: Is the world coming to an end?

2011-04-02 Thread Walter Bright

On 4/2/2011 3:27 PM, ulrik.mikaels...@gmail.com wrote:

As I wrote, I think it's great that 010 != 8 anymore.


010, etc., will now be errors. They will not be 10 decimal.

Also, the literals 00, 01, ..., 07 will still be accepted without complaint. 08, 
09, etc. will of course be errors.


Re: Is the world coming to an end?

2011-04-02 Thread Walter Bright

On 4/2/2011 3:58 PM, KennyTM~ wrote:

1. this message is specific to the dmd front-end. Other lexers might
not show this message


Appropriate and informative error messages are properly 
quality-of-implementation issues. As the dmd source shows, doing this message is 
trivial.



2. this assumes std.conv.octal exists, though it may not be the case
(e.g. using Tango without Phobos (well Tango devs could add just
std.conv.octal)).


This change will not migrate to D1.


Re: Is the world coming to an end?

2011-04-02 Thread Walter Bright

On 4/2/2011 4:11 PM, Michel Fortin wrote:

It's funny that D (the language) has binary notation built-in (which C doesn't
have) but no octal notation anymore (which C has).


The problem with the octal literals is, as has been often complained about, 
people getting surprised by it. I've never heard of anyone being surprised by 
the binary or hex literals.



You now have to resort to a
library template for that,


I think it's a feature, not a "resort", that library templates can do this well. 
I think it's far better than C++0x's user defined literals, for example.



and it doesn't work for big numbers: try
assert(octal!17 == 0x___). Not that I expect
anyone to want to write big 64-bit numbers in octal, but it makes the new
"official" octal notation more like a hack.


If you use octal!"17" it will work correctly. You're right 
in that the decimal literal being "converted" to octal is a bit of a hack.


The octal!17 will fail at compile time with an integer 
overflow, it never gets to the runtime assert.


Re: Is the world coming to an end?

2011-04-02 Thread bearophile
Walter:

> Also, the literals 00, 01, ..., 07 will still be accepted without complaint. 
> 08, 
> 09, etc. will of course be errors.

Isn't this a corner case of the general rule? (corner cases are bad).

Bye,
bearophile


Re: Is the world coming to an end?

2011-04-02 Thread Adam D. Ruppe
Walter Bright wrote:
> You're right in that the decimal literal being "converted"
> to octal is a bit of a hack.

Yeah, but it's a no-win scenario.

Without it, people would bitch and moan that they have to put
quotes around little numbers like permission masks.

With it, people bitch and moan that its a hack, probably without
ever actually using it.


Re: Is the world coming to an end?

2011-04-02 Thread bearophile
Walter:

> The point is that "octal!" is not a syntax. It's completely a library 
> construction.

It seems I use the word "syntax" in a different way, for me it means any way to 
express a semantics. I will be more careful with my wording.

Bye,
bearophile


Re: Is the world coming to an end?

2011-04-02 Thread Francisco Almeida
Walter Bright Wrote:

> On 4/2/2011 3:27 PM, ulrik.mikaels...@gmail.com wrote:
> > As I wrote, I think it's great that 010 != 8 anymore.
> 
> 010, etc., will now be errors. They will not be 10 decimal.
> 
> Also, the literals 00, 01, ..., 07 will still be accepted without complaint. 
> 08, 
> 09, etc. will of course be errors.

This doesn't feel right, though. Either you permit leading numbers with leading 
zeroes to be read as decimals, or you forbid them unless they are 0x... or 
0b... .

I am concerned about the choice of relegating a kind of number literal to a 
library template. Doesn't this needlessly impact performance?

Granted, the 0123 syntax was error prone and we're all glad it's gone, but 
aren't there better alternatives such as 0o123 or 0q123, for example?



Re: Is the world coming to an end?

2011-04-02 Thread Daniel Gibson
Am 03.04.2011 02:23, schrieb Francisco Almeida:
> Walter Bright Wrote:
> 
>> On 4/2/2011 3:27 PM, ulrik.mikaels...@gmail.com wrote:
>>> As I wrote, I think it's great that 010 != 8 anymore.
>>
>> 010, etc., will now be errors. They will not be 10 decimal.
>>
>> Also, the literals 00, 01, ..., 07 will still be accepted without complaint. 
>> 08, 
>> 09, etc. will of course be errors.
> 
> This doesn't feel right, though. Either you permit leading numbers with 
> leading zeroes to be read as decimals, or you forbid them unless they are 
> 0x... or 0b... .

I agree.

> 
> I am concerned about the choice of relegating a kind of number literal to a 
> library template. Doesn't this needlessly impact performance?

No, it's a template, so it's evaluated at compile-time and doesn't impact
(runtime) performance.

> 
> Granted, the 0123 syntax was error prone and we're all glad it's gone, but 
> aren't there better alternatives such as 0o123 or 0q123, for example?
> 

How often do you use octal numbers?


Re: Is the world coming to an end?

2011-04-02 Thread KennyTM~

On Apr 3, 11 07:52, Walter Bright wrote:

On 4/2/2011 3:58 PM, KennyTM~ wrote:

1. this message is specific to the dmd front-end. Other lexers might
not show this message


Appropriate and informative error messages are properly
quality-of-implementation issues. As the dmd source shows, doing this
message is trivial.



DMD recognizes the octal literal then rejects it later. Ideally the 
lexer should not accept 0\d{2,} at all.



2. this assumes std.conv.octal exists, though it may not be the case
(e.g. using Tango without Phobos (well Tango devs could add just
std.conv.octal)).


This change will not migrate to D1.


Yes. I mean Tango for D2 (if it will be finished?)

Anyway the above aren't really big problems. I don't expect newbies know 
octal literals :).


Re: Is the world coming to an end?

2011-04-02 Thread Michel Fortin

On 2011-04-02 19:58:25 -0400, Walter Bright  said:


On 4/2/2011 4:11 PM, Michel Fortin wrote:

It's funny that D (the language) has binary notation built-in (which C doesn't
have) but no octal notation anymore (which C has).


The problem with the octal literals is, as has been often complained 
about, people getting surprised by it. I've never heard of anyone being 
surprised by the binary or hex literals.


Indeed. Isn't that a good argument for implementing octal literals the 
same way as binary and hex literals?




You now have to resort to a
library template for that,


I think it's a feature, not a "resort", that library templates can do 
this well. I think it's far better than C++0x's user defined literals, 
for example.


I disagree that it's better. With C++ user defined literals the user 
doesn't have to find by himself whether the number fits within the 
range of a regular integer literal and if not fall back to using a 
string as the template argument instead.


I don't think it's much worse, but I fail to see how it could be better.



and it doesn't work for big numbers: try
assert(octal!17 == 0x___). Not that 
I expect

anyone to want to write big 64-bit numbers in octal, but it makes the new
"official" octal notation more like a hack.


If you use octal!"17" it will work correctly. 
You're right in that the decimal literal being "converted" to octal is 
a bit of a hack.


The octal!17 will fail at compile time with an 
integer overflow, it never gets to the runtime assert.


Which makes me wonder, what does the compiler suggests in the error 
message when it encounters 017 ? I suspect it 
doesn't add the necessary quotes, does it?


The new syntax is certainly usable, it's just inelegant and hackish. 
Its your language, it's your choice, and I'll admit it won't affect me 
much.


--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/



Re: Is the world coming to an end?

2011-04-02 Thread Francisco Almeida
== Quote from Daniel Gibson (metalcae...@gmail.com)'s article

> > I am concerned about the choice of relegating a kind of number literal to a
library template. Doesn't this needlessly impact performance?
> No, it's a template, so it's evaluated at compile-time and doesn't impact
> (runtime) performance.

If there is no runtime performance penalty, then it's fine.

> > Granted, the 0123 syntax was error prone and we're all glad it's gone, but
aren't there better alternatives such as 0o123 or 0q123, for example?
> >
> How often do you use octal numbers?

Good point.


Re: Is the world coming to an end?

2011-04-02 Thread bearophile
Michel Fortin:

> The new syntax is certainly usable, it's just inelegant and hackish. 
> Its your language, it's your choice, and I'll admit it won't affect me 
> much.

My suggestions for Walter are:
- To turn 01 .. 07 too into errors;
- to deprecate the octal! Phobos template.
- To introduce the 0o leading that works from 0o0 to the uint.max;
- To change the new error message, so it suggests to use 0o.
- To ask opinions to the community here next time before changing things in 
D2/D3 :-)

Bye,
bearophile


Re: Is the world coming to an end?

2011-04-02 Thread Walter Bright

On 4/2/2011 5:34 PM, KennyTM~ wrote:

On Apr 3, 11 07:52, Walter Bright wrote:

On 4/2/2011 3:58 PM, KennyTM~ wrote:

1. this message is specific to the dmd front-end. Other lexers might
not show this message


Appropriate and informative error messages are properly
quality-of-implementation issues. As the dmd source shows, doing this
message is trivial.



DMD recognizes the octal literal then rejects it later. Ideally the lexer should
not accept 0\d{2,} at all.


That's for backwards compatibility.


Yes. I mean Tango for D2 (if it will be finished?)


I hope that Tango for D2 will not have gratuitous incompatibilities.


Re: Is the world coming to an end?

2011-04-02 Thread KennyTM~

On Apr 3, 11 08:30, Michel Fortin wrote:

On 2011-04-02 19:58:25 -0400, Walter Bright 
said:


On 4/2/2011 4:11 PM, Michel Fortin wrote:

It's funny that D (the language) has binary notation built-in (which
C doesn't
have) but no octal notation anymore (which C has).


The problem with the octal literals is, as has been often complained
about, people getting surprised by it. I've never heard of anyone
being surprised by the binary or hex literals.


Indeed. Isn't that a good argument for implementing octal literals the
same way as binary and hex literals?



You now have to resort to a
library template for that,


I think it's a feature, not a "resort", that library templates can do
this well. I think it's far better than C++0x's user defined literals,
for example.


I disagree that it's better. With C++ user defined literals the user
doesn't have to find by himself whether the number fits within the range
of a regular integer literal and if not fall back to using a string as
the template argument instead.



This is a problem but as I'd test it's a non-issue. Running a Google 
code search on   [^.'"-]\b0[0-7]{7,}[ulUL]*\b -0{8,}   shows only two 
instances of real (i.e. not used for testing the format function) usage 
of long (> 7 digits) octal literals in the first few pages:


0360l  in Android's OpenSSL (this is 0x_L)
0777L  in Apache's ASF (this is 0x1__L)

Both of them fit inside 2^^63 as decimal digits for octal!(), and both 
of them could better be represented as hex if ported.



I don't think it's much worse, but I fail to see how it could be better.



Avoiding needing to create another kind of literal?




and it doesn't work for big numbers: try
assert(octal!17 == 0x___). Not
that I expect
anyone to want to write big 64-bit numbers in octal, but it makes the
new
"official" octal notation more like a hack.


If you use octal!"17" it will work correctly.
You're right in that the decimal literal being "converted" to octal is
a bit of a hack.

The octal!17 will fail at compile time with an
integer overflow, it never gets to the runtime assert.


Which makes me wonder, what does the compiler suggests in the error
message when it encounters 017 ? I suspect it
doesn't add the necessary quotes, does it?



There's no quotes, and there should be, but the extra cost for this 
branch may not worth it (the lower limit of quotes depends on whether it 
is a long/unsigned literal).



The new syntax is certainly usable, it's just inelegant and hackish. Its
your language, it's your choice, and I'll admit it won't affect me much.





Re: Is the world coming to an end?

2011-04-02 Thread Walter Bright

On 4/2/2011 4:52 PM, Daniel Gibson wrote:

Am 03.04.2011 01:50, schrieb Walter Bright:

On 4/2/2011 3:27 PM, ulrik.mikaels...@gmail.com wrote:

As I wrote, I think it's great that 010 != 8 anymore.


010, etc., will now be errors. They will not be 10 decimal.

Also, the literals 00, 01, ..., 07 will still be accepted without complaint. 08,
09, etc. will of course be errors.


That feels pretty inconsistent.


It is inconsistent. One of the interesting things about "good" user interface 
design is it is awfully inconsistent.


The thing is, I ran into a bunch of D code that used 01, 03, etc. They weren't 
octal, and it seemed a pity to break it.


Re: Is the world coming to an end?

2011-04-02 Thread Walter Bright

On 4/2/2011 5:30 PM, Michel Fortin wrote:

On 2011-04-02 19:58:25 -0400, Walter Bright  said:

The problem with the octal literals is, as has been often complained about,
people getting surprised by it. I've never heard of anyone being surprised by
the binary or hex literals.

Indeed. Isn't that a good argument for implementing octal literals the same way
as binary and hex literals?


Yes, except for something else - the rarity of need for octal literals. The only 
modern usage I've seen of it is for file permissions.




I think it's a feature, not a "resort", that library templates can do this
well. I think it's far better than C++0x's user defined literals, for example.

I disagree that it's better. With C++ user defined literals the user doesn't
have to find by himself whether the number fits within the range of a regular
integer literal and if not fall back to using a string as the template argument
instead.


I believe that if you attempted to do octal literals using C++0x user defined 
literals, you'd run into exactly the same issue (overflow). See:


 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2765.pdf

C++0x user defined literals call a global function, which fails when you have 
more than one definition of the same literal. I.e. you cannot qualify the 
function to resolve ambiguity.


Other complaints about them:

 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3250.html



I don't think it's much worse, but I fail to see how it could be better.


Reasons:

1. It is not a language extension
2. Conflicting names are easily resolved
3. More than one argument is possible
4. The full power of CTFE is available to compute it, rather than the very 
limited C++0x constexpr
5. If you read N2765, it's pretty darned hackish. I.e. there's the "raw" and 
"cooked" mode.




Which makes me wonder, what does the compiler suggests in the error message when
it encounters 017 ? I suspect it doesn't add the necessary
quotes, does it?


No, it doesn't. The lexer knows nothing about higher level semantics.




Re: Is the world coming to an end?

2011-04-02 Thread Daniel Gibson
Am 03.04.2011 03:39, schrieb Walter Bright:
> On 4/2/2011 4:52 PM, Daniel Gibson wrote:
>> Am 03.04.2011 01:50, schrieb Walter Bright:
>>> On 4/2/2011 3:27 PM, ulrik.mikaels...@gmail.com wrote:
 As I wrote, I think it's great that 010 != 8 anymore.
>>>
>>> 010, etc., will now be errors. They will not be 10 decimal.
>>>
>>> Also, the literals 00, 01, ..., 07 will still be accepted without 
>>> complaint. 08,
>>> 09, etc. will of course be errors.
>>
>> That feels pretty inconsistent.
> 
> It is inconsistent. One of the interesting things about "good" user interface
> design is it is awfully inconsistent.
> 
> The thing is, I ran into a bunch of D code that used 01, 03, etc. They weren't
> octal, and it seemed a pity to break it.

They were octal, it just didn't make a difference. I don't see a reason to use
them (if not as octals) anyway.

Time will tell but I wouldn't be surprised if sooner or later somebody wonders
why 00, 01..07 work, but 08 etc don't and complains about weird corner cases ;)

Cheers,
- Daniel


Re: Is the world coming to an end?

2011-04-02 Thread Andrei Alexandrescu

On 4/2/11 6:36 PM, Daniel Gibson wrote:

Am 03.04.2011 01:20, schrieb Andrei Alexandrescu:

On 4/2/11 5:27 PM, ulrik.mikaels...@gmail.com wrote:

A D-newbie would probably be able to guess 0o for octal, but hardly
octal!. octal! breaks the rule of least surprise.


I fail to infer how using the word "octal" for an octal literal is surprising at
all.

This thread is a good example that it's impossible to please everyone. Although
past discussions made it clear that most everyone found leading 0 a poor
convention for octal numbers, now not only the consensus is weaker, but some
actually claim a different solution is superior. If that were chosen, then all
of a sudden octal!777 would have become suddenly sexy and so on.

The grass is always greener on the other side...


Andrei


I don't think the consensus that a leading 0 is a poor convention for octal
numbers is weaker now - so far nobody wants the old syntax back :)


Some discussions on IRC suggest otherwise.

Andrei


Re: Is the world coming to an end?

2011-04-02 Thread Daniel Gibson
Am 03.04.2011 04:00, schrieb Andrei Alexandrescu:
> On 4/2/11 6:36 PM, Daniel Gibson wrote:
>> Am 03.04.2011 01:20, schrieb Andrei Alexandrescu:
>>> On 4/2/11 5:27 PM, ulrik.mikaels...@gmail.com wrote:
 A D-newbie would probably be able to guess 0o for octal, but hardly
 octal!. octal! breaks the rule of least surprise.
>>>
>>> I fail to infer how using the word "octal" for an octal literal is 
>>> surprising at
>>> all.
>>>
>>> This thread is a good example that it's impossible to please everyone. 
>>> Although
>>> past discussions made it clear that most everyone found leading 0 a poor
>>> convention for octal numbers, now not only the consensus is weaker, but some
>>> actually claim a different solution is superior. If that were chosen, then 
>>> all
>>> of a sudden octal!777 would have become suddenly sexy and so on.
>>>
>>> The grass is always greener on the other side...
>>>
>>>
>>> Andrei
>>
>> I don't think the consensus that a leading 0 is a poor convention for octal
>> numbers is weaker now - so far nobody wants the old syntax back :)
> 
> Some discussions on IRC suggest otherwise.
> 
> Andrei

Ok. I don't hang out in the D IRC chan because the NG is time-consuming enough
already ;)


Re: Is the world coming to an end?

2011-04-02 Thread Andrei Alexandrescu

On 4/2/11 7:52 PM, bearophile wrote:

Michel Fortin:


The new syntax is certainly usable, it's just inelegant and hackish.
Its your language, it's your choice, and I'll admit it won't affect me
much.


My suggestions for Walter are:
- To turn 01 .. 07 too into errors;
- to deprecate the octal! Phobos template.
- To introduce the 0o leading that works from 0o0 to the uint.max;
- To change the new error message, so it suggests to use 0o.
- To ask opinions to the community here next time before changing things in 
D2/D3 :-)

Bye,
bearophile


I think a point the size of China is being missed here.

"octal" is not only an alternative notation, it is an example, a model 
for defining other user-defined literals. Adding 0o or whatever would 
solve the issue of defining an obscure literal, whereas octal opens the 
door to a host of possibilities to define user-defined literals.


std.conv.octal _is_ the work of the community, written by myself and 
others (could you please identify yourselves)?



Andrei


Re: Is the world coming to an end?

2011-04-02 Thread Walter Bright

On 4/2/2011 6:44 PM, Daniel Gibson wrote:

Time will tell but I wouldn't be surprised if sooner or later somebody wonders
why 00, 01..07 work, but 08 etc don't and complains about weird corner cases ;)


They might. We'll see.


Re: Is the world coming to an end?

2011-04-02 Thread Adam D. Ruppe
Andrei Alexandrescu wrote:
> std.conv.octal _is_ the work of the community, written by myself and
> others (could you please identify yourselves)?

I wrote the first version, interestingly, almost exactly a year
ago now. (The timestamp on my local file is 2010-03-26)

It looks like the current version is mostly the same as my
original one, although with significantly improved documentation
and some style cleanup.


Re: Is the world coming to an end?

2011-04-02 Thread Andrei Alexandrescu

On 4/2/11 9:28 PM, Adam D. Ruppe wrote:

Andrei Alexandrescu wrote:

std.conv.octal _is_ the work of the community, written by myself and
others (could you please identify yourselves)?


I wrote the first version, interestingly, almost exactly a year
ago now. (The timestamp on my local file is 2010-03-26)

It looks like the current version is mostly the same as my
original one, although with significantly improved documentation
and some style cleanup.


Did that include the string parsing and all? I didn't write that code.

Andrei


Re: Is the world coming to an end?

2011-04-02 Thread Andrei Alexandrescu

On 4/2/11 9:38 PM, Adam D. Ruppe wrote:

Andrei Alexandrescu wrote:

Did that include the string parsing and all?


Yeah. You can see my original version here:
http://arsdnet.net/dcode/octal.d

The meat of the code is pretty well unchanged in Phobos.


Oh indeed, and you're credited in std.conv as an author, too. Thanks!

Andrei


Re: Is the world coming to an end?

2011-04-03 Thread Russel Winder
On Sat, 2011-04-02 at 16:47 -0700, Walter Bright wrote:

> The point is that "octal!" is not a syntax. It's completely a library 
> construction.

So remove 0b... and 0x... as well such that the compiler only knows
about decimal.  The point here is not the removal of the C-style octal
notation, everyone agrees that it was and remains a bad idea, the
problem is the inconsistency of treatment of binary and hexadecimal
compared to octal.

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


signature.asc
Description: This is a digitally signed message part


Re: Is the world coming to an end?

2011-04-03 Thread Russel Winder
On Sat, 2011-04-02 at 18:36 -0700, Walter Bright wrote:

> Yes, except for something else - the rarity of need for octal literals. The 
> only 
> modern usage I've seen of it is for file permissions.

What is the use for binary literals or hexadecimal literals, I can't
think of one.

Except perhaps specification of register save masks and control status
work literals -- which is of course where the octal stuff came from in
the first place in C and when the VAX replaced PDP, hexadecimal was
rapidly introduced. (*)

I would suggest that rather than discriminating against people who like
octal instead of decimal or hexadecimal, the solution of introducing
0o... in harmony with 0b... and 0x... -- and of course removing the
leading 0 octal literal convention -- is obviously the right solution.
It ticks all the boxes.


(*)  For anyone not immediately in the know here PDP had 8 registers and
VAX 16 so octal and hexadecimal were the natural bases for specifying
masks.  The 68000 also played a part.  The use of octal on the PDP
actually goes a lot deeper than this, cf. Unibus,  but it is all ancient
history now.

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


signature.asc
Description: This is a digitally signed message part


Re: Is the world coming to an end?

2011-04-03 Thread Russel Winder
On Sat, 2011-04-02 at 18:20 -0500, Andrei Alexandrescu wrote:
> On 4/2/11 5:27 PM, ulrik.mikaels...@gmail.com wrote:
> > A D-newbie would probably be able to guess 0o for octal, but hardly
> > octal!. octal! breaks the rule of least surprise.
> 
> I fail to infer how using the word "octal" for an octal literal is 
> surprising at all.

The problem is not that it is a poor solution in isolation, it is the
conflict between 0b... and 0x.. versus octal!...  Why is octal being
discriminated against compared to binary and hexadecimal?

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


signature.asc
Description: This is a digitally signed message part


Re: Is the world coming to an end?

2011-04-03 Thread Russel Winder
On Sat, 2011-04-02 at 21:16 -0500, Andrei Alexandrescu wrote:
[ . . . ]
> I think a point the size of China is being missed here.
> 
> "octal" is not only an alternative notation, it is an example, a model 
> for defining other user-defined literals. Adding 0o or whatever would 
> solve the issue of defining an obscure literal, whereas octal opens the 
> door to a host of possibilities to define user-defined literals.

The same goes for 0b... 0x... so why aren't they being removed in favour
of library based solution?

Despite Walters claim that inconsistency is not a bad thing, evidence
indicates that from the psychology community that consistency and
affordance is a very good thing for usability.  

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


signature.asc
Description: This is a digitally signed message part


Re: Is the world coming to an end?

2011-04-03 Thread Nick Sabalausky
"Andrej Mitrovic"  wrote in message 
news:in8060$lt3$1...@digitalmars.com...
> https://github.com/D-Programming-Language/phobos/commit/83f99df573c089cc186ef370cb691c2f8a25c873
> https://github.com/D-Programming-Language/phobos/commit/88904f7795a94b23e750e10a2addc90783089de7
>
> If I didn't know it better I would think it's still April 1st. :D

Yea! I stumbled onto that, too. IIRC, I let out a rather audible "Whoohoo!" 
:)




Re: Is the world coming to an end?

2011-04-03 Thread Nick Sabalausky
On Sat, 2011-04-02 at 21:16 -0500, Andrei Alexandrescu wrote:
[ . . . ]
>> I think a point the size of China is being missed here.
>>
>> "octal" is not only an alternative notation, it is an example, a model
>> for defining other user-defined literals. Adding 0o or whatever would
>> solve the issue of defining an obscure literal, whereas octal opens the
>> door to a host of possibilities to define user-defined literals.
>
>The same goes for 0b... 0x... so why aren't they being removed in favour
>of library based solution?

Because unlike the octal syntax, those are neither error-prone nor 
barely-useful. I agree that consistency is good, but I think it's far 
outweighed in this case by those other concerns.




Re: Is the world coming to an end?

2011-04-03 Thread Nick Sabalausky
"Michel Fortin"  wrote in message 
news:in8f9e$1h45$1...@digitalmars.com...
> On 2011-04-02 19:58:25 -0400, Walter Bright  
> said:
>
>> On 4/2/2011 4:11 PM, Michel Fortin wrote:
>>> It's funny that D (the language) has binary notation built-in (which C 
>>> doesn't
>>> have) but no octal notation anymore (which C has).
>>
>> The problem with the octal literals is, as has been often complained 
>> about, people getting surprised by it. I've never heard of anyone being 
>> surprised by the binary or hex literals.
>
> Indeed. Isn't that a good argument for implementing octal literals the 
> same way as binary and hex literals?
>

Octal is never really needed or used for anything but unix file permissions, 
so I really don't think it matters at all if it happens to be inconsistent.

>>
>> I think it's a feature, not a "resort", that library templates can do 
>> this well. I think it's far better than C++0x's user defined literals, 
>> for example.
>
> I disagree that it's better. With C++ user defined literals the user 
> doesn't have to find by himself whether the number fits within the range 
> of a regular integer literal and if not fall back to using a string as the 
> template argument instead.
>

C++'s user defined literals sound like a lexing nightmare to me.





Re: Is the world coming to an end?

2011-04-03 Thread Nick Sabalausky
"Russel Winder"  wrote in message 
news:mailman.3055.1301814881.4748.digitalmar...@puremagic.com...
>On Sat, 2011-04-02 at 18:20 -0500, Andrei Alexandrescu wrote:
>> On 4/2/11 5:27 PM, ulrik.mikaels...@gmail.com wrote:
>> > A D-newbie would probably be able to guess 0o for octal, but hardly
>> > octal!. octal! breaks the rule of least surprise.
>>
>> I fail to infer how using the word "octal" for an octal literal is
>> surprising at all.
>
>The problem is not that it is a poor solution in isolation, it is the
>conflict between 0b... and 0x.. versus octal!...  Why is octal being
>discriminated against compared to binary and hexadecimal?
>

To be perfectly blunt, it's because octal...well, sucks. It's useless 
compared to binary and hex and just isn't really deserving of a special 
notation anyway. Even more so since the rare uses of it are possible in D 
without it being part of the language. Binary and hex, OTOH, are useful (I 
use hex very frequently. And I would get a lot of use out of binary if I 
actually had time to do low-level work like I used to).

That said, I woudn't have a problem with 0o... being used instead (Although 
I'd actually prefer 0c...). But I have a hard time understanding why people 
are making such a big deal out of something that practically no one ever 
uses anyway. Consistency is nice, sure, but when it's such a trival 
corner-case as octal: Why even care? This isn't the color of the bikeshed, 
this is the *shade* of color on the underside of the trim on a window that's 
one foot off the ground and completely blocked by a big tree.





Re: Is the world coming to an end?

2011-04-03 Thread Nick Sabalausky
"Daniel Gibson"  wrote in message 
news:in8jko$knb$7...@digitalmars.com...
> Am 03.04.2011 03:39, schrieb Walter Bright:
>> On 4/2/2011 4:52 PM, Daniel Gibson wrote:
>>> Am 03.04.2011 01:50, schrieb Walter Bright:
 On 4/2/2011 3:27 PM, ulrik.mikaels...@gmail.com wrote:
> As I wrote, I think it's great that 010 != 8 anymore.

 010, etc., will now be errors. They will not be 10 decimal.

 Also, the literals 00, 01, ..., 07 will still be accepted without 
 complaint. 08,
 09, etc. will of course be errors.
>>>
>>> That feels pretty inconsistent.
>>
>> It is inconsistent. One of the interesting things about "good" user 
>> interface
>> design is it is awfully inconsistent.
>>
>> The thing is, I ran into a bunch of D code that used 01, 03, etc. They 
>> weren't
>> octal, and it seemed a pity to break it.
>
> They were octal, it just didn't make a difference. I don't see a reason to 
> use
> them (if not as octals) anyway.
>
> Time will tell but I wouldn't be surprised if sooner or later somebody 
> wonders
> why 00, 01..07 work, but 08 etc don't and complains about weird corner 
> cases ;)
>

Yea, but I bet people would also complain if it were disallowed. "There's no 
ambiguity here! Why's it whining about something that's obviously guaranteed 
to work?!"




Re: Is the world coming to an end?

2011-04-03 Thread Russel Winder
On Sun, 2011-04-03 at 04:05 -0400, Nick Sabalausky wrote:
[ . . . ]
> >The same goes for 0b... 0x... so why aren't they being removed in favour
> >of library based solution?
> 
> Because unlike the octal syntax, those are neither error-prone nor 
> barely-useful. I agree that consistency is good, but I think it's far 
> outweighed in this case by those other concerns.

Your argument rests on the octal representation being like 0777, a
notation that everyone has already agreed needs removing.  The
introduction of 0o777 for octal increases consistency without
introducing error proneness.  This is just win--win.

There is no consistent language design argument that supports have 0b...
and 0x... but not 0o... -- requiring the use of octal! from the library
when hex! and binary! are not the standard forms.

In the end this is Walter's decision, I'd just prefer him not to get it
wrong.

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


signature.asc
Description: This is a digitally signed message part


Re: Is the world coming to an end?

2011-04-03 Thread Walter Bright

On 4/3/2011 12:12 AM, Russel Winder wrote:

On Sat, 2011-04-02 at 18:36 -0700, Walter Bright wrote:


Yes, except for something else - the rarity of need for octal literals. The only
modern usage I've seen of it is for file permissions.


What is the use for binary literals or hexadecimal literals, I can't
think of one.

Except perhaps specification of register save masks and control status
work literals -- which is of course where the octal stuff came from in
the first place in C and when the VAX replaced PDP, hexadecimal was
rapidly introduced. (*)


I still prefer binary for that. It takes me a senior moment or two to remember 
what bit pattern 0xB is, for example.




I would suggest that rather than discriminating against people who like
octal


The phrase "discriminating against people" has a lot of emotional baggage 
associated with it that is irrelevant to this.




instead of decimal or hexadecimal, the solution of introducing
0o... in harmony with 0b... and 0x... -- and of course removing the
leading 0 octal literal convention -- is obviously the right solution.
It ticks all the boxes.


Except the box of a kitchen sink of features of marginal utility. A feature that 
can be handled adequately by the library should not be part of the core language.


And yes, you can make a reasonable case that 0b should be ditched for the same 
reason.


Re: Is the world coming to an end?

2011-04-03 Thread Walter Bright

On 4/3/2011 12:00 AM, Russel Winder wrote:

On Sat, 2011-04-02 at 16:47 -0700, Walter Bright wrote:


The point is that "octal!" is not a syntax. It's completely a library 
construction.


So remove 0b... and 0x... as well such that the compiler only knows
about decimal.  The point here is not the removal of the C-style octal
notation, everyone agrees that it was and remains a bad idea, the
problem is the inconsistency of treatment of binary and hexadecimal
compared to octal.



The 0x notation is heavily used, and so justifies a custom syntax for it. Octal 
is pretty much never used outside of setting file permission masks.


Much as I like PDP-10's and PDP-11's, they are dead and gone. 


Re: Is the world coming to an end?

2011-04-03 Thread Nick Sabalausky
"bearophile"  wrote in message 
news:in8dfe$1e32$1...@digitalmars.com...
> Walter:
>
>> Also, the literals 00, 01, ..., 07 will still be accepted without 
>> complaint. 08,
>> 09, etc. will of course be errors.
>
> Isn't this a corner case of the general rule? (corner cases are bad).
>

"(corner cases are bad)"

So is stealing, but no one ever bitches if you pick up a penny off the 
ground. Yea, it's a corner case, but it's trivial enough not to actually 
matter. Guaranteed, people would bitch the other way too, so it's "dammed if 
we do, dammed if we don't" anyway.




Re: Is the world coming to an end?

2011-04-03 Thread Nick Sabalausky
"Walter Bright"  wrote in message 
news:in9c9h$134t$1...@digitalmars.com...
> On 4/3/2011 12:12 AM, Russel Winder wrote:
>> On Sat, 2011-04-02 at 18:36 -0700, Walter Bright wrote:
>>
>>> Yes, except for something else - the rarity of need for octal literals. 
>>> The only
>>> modern usage I've seen of it is for file permissions.
>>
>> What is the use for binary literals or hexadecimal literals, I can't
>> think of one.
>>
>> Except perhaps specification of register save masks and control status
>> work literals -- which is of course where the octal stuff came from in
>> the first place in C and when the VAX replaced PDP, hexadecimal was
>> rapidly introduced. (*)
>
> I still prefer binary for that. It takes me a senior moment or two to 
> remember what bit pattern 0xB is, for example.
>

Somtimes I have to wonder if I'm much older than I think I am. I'm exactly 
the same way as you with "moment or two to remember what bit pattern 0xB is, 
for example", and if I'm getting senior moments in my late 20's then 
something is very very wrong ;)




Re: Is the world coming to an end?

2011-04-03 Thread Walter Bright

On 4/3/2011 12:20 AM, Russel Winder wrote:

Despite Walters claim that inconsistency is not a bad thing, evidence
indicates that from the psychology community that consistency and
affordance is a very good thing for usability.



I meant that inconsistency is not *necessarily* a bad thing.

Successful programming languages are remarkably inconsistent, because people 
like them that way. Completely consistent languages tend to be failures.


Obviously, there's a judgment call about what's a bad inconsistency and what's a 
good inconsistency. A programming language is a mass of principles that pretty 
much all conflict with each other. The art is, for each conflict, deciding which 
principle should matter for that particular case.


Ok, I won't drag out my hoary airplane design analogy this time, but have you 
ever designed a house? It's nothing but conflicting requirements. There is no 
consistency. In fact, as any architect will tell you, a consistent design 
actually looks wrong! Look no further than the Parthenon, which doesn't have a 
straight line anywhere in it, even though it looks straight.


Re: Is the world coming to an end?

2011-04-03 Thread Walter Bright

On 4/3/2011 1:54 AM, Nick Sabalausky wrote:

Somtimes I have to wonder if I'm much older than I think I am. I'm exactly
the same way as you with "moment or two to remember what bit pattern 0xB is,
for example", and if I'm getting senior moments in my late 20's then
something is very very wrong ;)


You should be fine as long as you're not tying an onion to your belt!



Re: Is the world coming to an end?

2011-04-03 Thread Walter Bright

On 4/3/2011 1:46 AM, Russel Winder wrote:

In the end this is Walter's decision, I'd just prefer him not to get it
wrong.


At some point, one has to take a leap of faith. Only time will tell if it was 
the right decision or not.


Or if (in this particular case) it's just a bikeshed color and simply does not 
matter.




Re: Is the world coming to an end?

2011-04-03 Thread KennyTM~

On Apr 3, 11 09:44, Daniel Gibson wrote:

Am 03.04.2011 03:39, schrieb Walter Bright:

On 4/2/2011 4:52 PM, Daniel Gibson wrote:

Am 03.04.2011 01:50, schrieb Walter Bright:

On 4/2/2011 3:27 PM, ulrik.mikaels...@gmail.com wrote:

As I wrote, I think it's great that 010 != 8 anymore.


010, etc., will now be errors. They will not be 10 decimal.

Also, the literals 00, 01, ..., 07 will still be accepted without complaint. 08,
09, etc. will of course be errors.


That feels pretty inconsistent.


It is inconsistent. One of the interesting things about "good" user interface
design is it is awfully inconsistent.

The thing is, I ran into a bunch of D code that used 01, 03, etc. They weren't
octal, and it seemed a pity to break it.


They were octal, it just didn't make a difference. I don't see a reason to use
them (if not as octals) anyway.

Time will tell but I wouldn't be surprised if sooner or later somebody wonders
why 00, 01..07 work, but 08 etc don't and complains about weird corner cases ;)

Cheers,
- Daniel


No need to be surprised, people are already complaining languages 
supporting the 0nnn notation that why 08, 09 does not compile. :)


e.g.

08 in Python 2: 
http://stackoverflow.com/questions/336181/python-invalid-token
09 in Java: 
http://stackoverflow.com/questions/970039/09-is-not-recognized-where-as-9-is-recognized


Re: Is the world coming to an end?

2011-04-03 Thread KennyTM~

On Apr 3, 11 07:50, Walter Bright wrote:

On 4/2/2011 3:27 PM, ulrik.mikaels...@gmail.com wrote:

As I wrote, I think it's great that 010 != 8 anymore.


010, etc., will now be errors. They will not be 10 decimal.

Also, the literals 00, 01, ..., 07 will still be accepted without
complaint. 08, 09, etc. will of course be errors.


Will it be part of the spec that 0+[0-7] will work, and the rest of 0\d+ 
won't? Or is this considered just a DMD extension?


Re: Is the world coming to an end?

2011-04-03 Thread Ulrik Mikaelsson
2011/4/3 Walter Bright :
>
> The 0x notation is heavily used, and so justifies a custom syntax for it.
> Octal is pretty much never used outside of setting file permission masks.

The thing is, since you already have 0x and 0b, 0o would not be much
of a "custom syntax". It would simply be an "extrapolation of the
rule". It follows the already set pattern for non 10-base literals.

Regarding the "but it's so uncommon"-argument, there are 23 characters
left for the "0"-notation, there isn't exactly an
allocation-problem.

> A feature that can be handled adequately by the library should not be part of 
> the core language.
If you're looking for uncommonly used language-features that could
easily be otherwise solved, go ahead and remove asm instead. I'll
guess it's about as uncommon as octal literals (or maybe even more),
have simple other solution (just compile it separately and link), and
has much greater impact on the language and the compiler.

I simply don't buy the "uncommon" argument, when it's such a minuscule
thing in the language, following an already established
framework/pattern.

> The phrase "discriminating against people" has a lot of emotional baggage 
> associated with it that is irrelevant to this.
Walter, you can make the decisions you see fit, you are the BDFL, but
please don't dismiss peoples feelings like this. It will only hinder D
longevity and growth.

I realize the discussion is over, and the feature has been
implemented. Bitching and moaning now won't change anybodys mind, but
for the record, I think this is a bad design-move, breaking
established patterns. I agree it minuscule and seldom used, so I'm not
going to continue the discussion.


Re: Is the world coming to an end?

2011-04-03 Thread Walter Bright

On 4/3/2011 2:31 AM, KennyTM~ wrote:

No need to be surprised, people are already complaining languages supporting the
0nnn notation that why 08, 09 does not compile. :)

e.g.

08 in Python 2: http://stackoverflow.com/questions/336181/python-invalid-token
09 in Java:
http://stackoverflow.com/questions/970039/09-is-not-recognized-where-as-9-is-recognized



I love the answer given: "There is no 9 in octal"



Re: Is the world coming to an end?

2011-04-03 Thread Walter Bright

On 4/3/2011 2:33 AM, KennyTM~ wrote:

On Apr 3, 11 07:50, Walter Bright wrote:

On 4/2/2011 3:27 PM, ulrik.mikaels...@gmail.com wrote:

As I wrote, I think it's great that 010 != 8 anymore.


010, etc., will now be errors. They will not be 10 decimal.

Also, the literals 00, 01, ..., 07 will still be accepted without
complaint. 08, 09, etc. will of course be errors.


Will it be part of the spec that 0+[0-7] will work, and the rest of 0\d+ won't?
Or is this considered just a DMD extension?


It should be part of the spec.


Re: Is the world coming to an end?

2011-04-03 Thread spir

On 04/03/2011 10:37 AM, Nick Sabalausky wrote:

That said, I woudn't have a problem with 0o... being used instead (Although
I'd actually prefer 0c...). But I have a hard time understanding why people
are making such a big deal out of something that practically no one ever
uses anyway. Consistency is nice, sure, but when it's such a trival
corner-case as octal: Why even care? This isn't the color of the bikeshed,
this is the *shade* of color on the underside of the trim on a window that's
one foot off the ground and completely blocked by a big tree.


What I fail to see is the advantage of introducing an exception for octal. 
Either it is left out of the language (including stdlib, possibly having around 
a 3rd party hack for it), or the same pattern is used as for hex and bin.
A point is stating a threshold of usefulness. Seems nearly everyone agrees 
octal is not worth it: then just say bye. If it kept instead because of 
historical reasons (what I guess is the case), then just *fix* the syntax. 
Introducing a feature (an exception) for a nearly useless notion is weird.


Denis
--
_
vita es estrany
spir.wikidot.com



Re: Is the world coming to an end?

2011-04-03 Thread spir

On 04/03/2011 11:39 AM, Walter Bright wrote:

On 4/3/2011 2:31 AM, KennyTM~ wrote:

No need to be surprised, people are already complaining languages supporting the
0nnn notation that why 08, 09 does not compile. :)

e.g.

08 in Python 2: http://stackoverflow.com/questions/336181/python-invalid-token
09 in Java:
http://stackoverflow.com/questions/970039/09-is-not-recognized-where-as-9-is-recognized




I love the answer given: "There is no 9 in octal"


I love that one: "10 is how many digits you have, whereas 010 is is what you 
get if you don't count your thumbs."


Denis
--
_
vita es estrany
spir.wikidot.com



Re: Is the world coming to an end?

2011-04-03 Thread spir

On 04/03/2011 02:52 AM, bearophile wrote:

Michel Fortin:


The new syntax is certainly usable, it's just inelegant and hackish.
Its your language, it's your choice, and I'll admit it won't affect me
much.


My suggestions for Walter are:
- To turn 01 .. 07 too into errors;
- to deprecate the octal! Phobos template.
- To introduce the 0o leading that works from 0o0 to the uint.max;
- To change the new error message, so it suggests to use 0o.
- To ask opinions to the community here next time before changing things in 
D2/D3 :-)


I'm very surprised of this move -- aside the concrete details. What I point out 
here is how far sentiments about what is "obvious" or "correct" can be, for a 
given issue, that most of us considered wrong for the same reason.


When I introduced the topic of octal notation 0nnn beeing bad, I was 100% sure 
that (if a move was ever made) either octals would be thrown out of D all 
together for beeing nearly useless, or the syntax would be fixed -- the 
"obvious" "correct" solution if octals remain. While I new about octal!, this 
was so hackish and obviously wrong *for me*, that I did not even imagine one 
second it could become the "official" solution.

I'm certainly not the only one.
Questions of detail, sure, but we all know what the details hide ;-)

Denis
--
_
vita es estrany
spir.wikidot.com



Re: Is the world coming to an end?

2011-04-03 Thread Lutger Blijdestijn
spir wrote:

> On 04/03/2011 02:52 AM, bearophile wrote:
>> Michel Fortin:
>>
>>> The new syntax is certainly usable, it's just inelegant and hackish.
>>> Its your language, it's your choice, and I'll admit it won't affect me
>>> much.
>>
>> My suggestions for Walter are:
>> - To turn 01 .. 07 too into errors;
>> - to deprecate the octal! Phobos template.
>> - To introduce the 0o leading that works from 0o0 to the uint.max;
>> - To change the new error message, so it suggests to use 0o.
>> - To ask opinions to the community here next time before changing things
>> in D2/D3 :-)
> 
> I'm very surprised of this move -- aside the concrete details. What I
> point out here is how far sentiments about what is "obvious" or "correct"
> can be, for a given issue, that most of us considered wrong for the same
> reason.
> 
> When I introduced the topic of octal notation 0nnn beeing bad, I was 100%
> sure that (if a move was ever made) either octals would be thrown out of D
> all together for beeing nearly useless, or the syntax would be fixed --
> the "obvious" "correct" solution if octals remain. While I new about
> octal!, this was so hackish and obviously wrong *for me*, that I did not
> even imagine one second it could become the "official" solution.
> I'm certainly not the only one.
> Questions of detail, sure, but we all know what the details hide ;-)
> 
> Denis

I don't understand why it is hackish if it's a pure library approach. (it is 
right?) I find it actually rather nice that D can do this. This is not a 
syntax change, octals are out of the language and the library now has an 
octal template. Where's the problem?



Re: Is the world coming to an end?

2011-04-03 Thread Andrei Alexandrescu

On 4/3/11 6:24 AM, spir wrote:

On 04/03/2011 10:37 AM, Nick Sabalausky wrote:

That said, I woudn't have a problem with 0o... being used instead
(Although
I'd actually prefer 0c...). But I have a hard time understanding why
people
are making such a big deal out of something that practically no one ever
uses anyway. Consistency is nice, sure, but when it's such a trival
corner-case as octal: Why even care? This isn't the color of the
bikeshed,
this is the *shade* of color on the underside of the trim on a window
that's
one foot off the ground and completely blocked by a big tree.


What I fail to see is the advantage of introducing an exception for
octal. Either it is left out of the language (including stdlib, possibly
having around a 3rd party hack for it), or the same pattern is used as
for hex and bin.


Right now octal constants are indeed out of the language.


A point is stating a threshold of usefulness. Seems nearly everyone
agrees octal is not worth it: then just say bye. If it kept instead
because of historical reasons (what I guess is the case), then just
*fix* the syntax. Introducing a feature (an exception) for a nearly
useless notion is weird.


This is not a feature. It is effectively "bye".


Thanks,

Andrei


Re: Is the world coming to an end?

2011-04-03 Thread Andrei Alexandrescu

On 4/3/11 4:39 AM, Ulrik Mikaelsson wrote:

2011/4/3 Walter Bright:


The 0x notation is heavily used, and so justifies a custom syntax for it.
Octal is pretty much never used outside of setting file permission masks.


The thing is, since you already have 0x and 0b, 0o would not be much
of a "custom syntax". It would simply be an "extrapolation of the
rule". It follows the already set pattern for non 10-base literals.


It is a custom syntax nevertheless. Worse, that custom syntax does 
nothing for other cases of literals (e.g. lat/long, degrees and minutes 
etc). The best thing about std.conv.octal is that is serves as a 
template (in the general sense of the word) for any custom literals. It 
offers the proverbial fishing rod as opposed to '0o' being the 
proverbial fish.



Regarding the "but it's so uncommon"-argument, there are 23 characters
left for the "0"-notation, there isn't exactly an
allocation-problem.


A feature that can be handled adequately by the library should not be part of 
the core language.

If you're looking for uncommonly used language-features that could
easily be otherwise solved, go ahead and remove asm instead. I'll
guess it's about as uncommon as octal literals (or maybe even more),
have simple other solution (just compile it separately and link), and
has much greater impact on the language and the compiler.

I simply don't buy the "uncommon" argument, when it's such a minuscule
thing in the language, following an already established
framework/pattern.


The phrase "discriminating against people" has a lot of emotional baggage 
associated with it that is irrelevant to this.

Walter, you can make the decisions you see fit, you are the BDFL, but
please don't dismiss peoples feelings like this. It will only hinder D
longevity and growth.

I realize the discussion is over, and the feature has been
implemented. Bitching and moaning now won't change anybodys mind, but
for the record, I think this is a bad design-move, breaking
established patterns. I agree it minuscule and seldom used, so I'm not
going to continue the discussion.


On the contrary, I think it's a very good and significant move in the 
right direction. If it breaks anything, it breaks an inferior approach 
to literals.



Andrei


Re: Is the world coming to an end?

2011-04-03 Thread Adam D. Ruppe
spir wrote:
> What I fail to see is the advantage of introducing an exception for
> octal.

Octal isn't the exception. Of all the infinite number bases out there,
octal is the one done in the most generic way. (In fact, it'd
probably be a reasonably simple change to make it alias base!8 octal;
or something like that)

The exceptions are decimal, hex, and binary. Each one has reasoning:

decimal: that's the way we normally talk and think. We need a
 starting point somewhere, so this is the natural choice.

hex: commonly used and cannot be easily written as a decimal
 literal. Piles upon piles of existing code depend on it.

binary:  Incredibly useful, not easily written as a decimal. The
 case for giving it special treatment isn't as strong as
 hex, but it follows the same reasoning. (Actually, in
 code that I write freshly, I use binary literals more
 often than hex. Like Walter, my brain is slow at making
 masks out of hex.)



Anything can follow the same pattern as octal. Not anything can
be shoved into the language.


Re: Is the world coming to an end?

2011-04-03 Thread Adam D. Ruppe
Walter Bright wrote:
> And yes, you can make a reasonable case that 0b should be ditched
> for the same reason.

I know people already think of the isIntegral versions of octal
as a hack, but I see that as one reason why binary wouldn't work
as well as a template:

binary!___

Overflow city! Such long numbers aren't terribly common in octal,
but they /are/ in binary.

Of course, you can just use the string version, so it isn't a
big deal, but nevertheless, it is a difference.


btw, it might be worth considering a change to overflow. Suppose
there was a way to get arbitrary size ints passed to a template.
Then, the library could do its own overflow checks, or not, enabling
things like bigint literals in this same fashion.

Though, I don't think it's a big benefit. It'd be really weird
to use (a new compile time only datatype?)

And if you actually need that, the string version works just fine.

So all in all I don't think it's worth it.


Re: Is the world coming to an end?

2011-04-03 Thread Andrei Alexandrescu

On 4/3/11 2:14 AM, Russel Winder wrote:

On Sat, 2011-04-02 at 18:20 -0500, Andrei Alexandrescu wrote:

On 4/2/11 5:27 PM, ulrik.mikaels...@gmail.com wrote:

A D-newbie would probably be able to guess 0o for octal, but
hardly octal!. octal! breaks the rule of least surprise.


I fail to infer how using the word "octal" for an octal literal is
surprising at all.


The problem is not that it is a poor solution in isolation, it is
the conflict between 0b... and 0x.. versus octal!...  Why is octal
being discriminated against compared to binary and hexadecimal?


It's very simple. You are making a number of fallacious assumptions
which logically lead to a wrong conclusion.

First fallacy is:


What is the use for binary literals or hexadecimal literals, I can't
think of one.


Just looking through std/ yields 1849 lines with 0x in them, of which 
many have several instances on the same line.


The second fallacy is assigning equal weight to every feature or 
potential feature. A language should not be a democracy.


The third fallacy is a unidimensional view of consistency. It's very 
easy to first limit the notion of consistency to only one possible 
dimension, to then show that a lot of stuff is inconsistent. In reality 
there are many dimensions of consistency, and choosing their right 
relative importance is much of the difficulty of language design.


Keeping 0x in the language is consistent with the general similarity of 
D with C, C++, Java, and many others.


Eliminating 0777 from the language is consistent with the notion that 
leading zeros are insignificant in regular decimal notation in math. It 
is also consistent with the desire of preventing subtle mistakes made by 
people who make the math-based assumption.


Adding octal!777 to std.conv is consistent with the notion that there 
still are a few uses for octal constants that are worth a presence in 
the standard library. It is also consistent with the desire to foster 
other user-defined literals defined from the same mold.



Andrei


Re: Is the world coming to an end?

2011-04-03 Thread Andrei Alexandrescu

On 4/3/11 3:46 AM, Russel Winder wrote:

On Sun, 2011-04-03 at 04:05 -0400, Nick Sabalausky wrote:
[ . . . ]

The same goes for 0b... 0x... so why aren't they being removed in favour
of library based solution?


Because unlike the octal syntax, those are neither error-prone nor
barely-useful. I agree that consistency is good, but I think it's far
outweighed in this case by those other concerns.


Your argument rests on the octal representation being like 0777, a
notation that everyone has already agreed needs removing.  The
introduction of 0o777 for octal increases consistency without
introducing error proneness.  This is just win--win.


It wins consistency with two other hardwired conventions for 
representing numbers. It is a total loss in helping anything but octal 
constants.



There is no consistent language design argument that supports have 0b...
and 0x... but not 0o... -- requiring the use of octal! from the library
when hex! and binary! are not the standard forms.


0x is too widespread and too often used in C and C++ to gratuitously 
eliminate it. It does not have significant disadvantages. Besides it is 
used fairly often. I agree that 0b could and should be deprecated.



In the end this is Walter's decision, I'd just prefer him not to get it
wrong.


That is appreciated.


Andrei



Re: Is the world coming to an end?

2011-04-03 Thread Michel Fortin

On 2011-04-03 12:04:42 -0400, Adam D. Ruppe  said:


btw, it might be worth considering a change to overflow. Suppose
there was a way to get arbitrary size ints passed to a template.
Then, the library could do its own overflow checks, or not, enabling
things like bigint literals in this same fashion.

Though, I don't think it's a big benefit. It'd be really weird
to use (a new compile time only datatype?)


I've been thinking about the same thing, except instead of having a 
special data type the template would simply take a string:


template binary(string digits) {
...
}

binary!___;
// no error, number "___" passed as a string to the 
template.

But the bigger problem is that it doesn't scale beyond base 10:

template hex(string digits) {
...
}

hex!ABCDEF00;
// isn't ABCDEF00 an identifier?

So it wouldn't bring us much when it comes to parsing different bases, 
even though it could be used for other things.


--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/



Re: Is the world coming to an end?

2011-04-03 Thread Adam D. Ruppe
Ulrik Mikaelsson wrote:
> If you're looking for uncommonly used language-features that could
> easily be otherwise solved, go ahead and remove asm instead. I'll
> guess it's about as uncommon as octal literals (or maybe even more),
> have simple other solution (just compile it separately and link),
> and has much greater impact on the language and the compiler.

Actually, inline asm can't be replaced. If you link it separately,
it won't be inlined...

There's also a huge difficulty change. 010 -> octal!10 is a simple
change. It'd be enormous effort to de-inline assembly, even if
it were actually possible in the first place! Consider asm
in version statements

Also, unlike octal literals, it couldn't be replaced by templates
either; inline asm enables things that are otherwise impossible.
There's simply no way for the language to express many of the
instructions available to you in asm. It's a foundational building
block.

This leads into the commonness too. I don't think I've *ever*
wanted an octal literal. But, assembly is useful in 3/5 of
my programs. Heck, even more, if you count library functions
that use it. (though lib functions could in theory be linked
separately)


Re: Is the world coming to an end?

2011-04-03 Thread KennyTM~

On Apr 4, 11 00:49, Adam D. Ruppe wrote:

Ulrik Mikaelsson wrote:

If you're looking for uncommonly used language-features that could
easily be otherwise solved, go ahead and remove asm instead. I'll
guess it's about as uncommon as octal literals (or maybe even more),
have simple other solution (just compile it separately and link),
and has much greater impact on the language and the compiler.


Actually, inline asm can't be replaced. If you link it separately,
it won't be inlined...


Talking of asm, would the following be expected to work?

---
import std.conv;
void main() {
asm {
di octal!777;
mov EAX, octal!777;
}
}
---


Re: Is the world coming to an end?

2011-04-03 Thread Adam D. Ruppe
KennyTM~ wrote:
> Talking of asm, would the following be expected to work?

Maybe. Part of me says "yes, it should be the same as a literal*"
but part of me says no because it's weird to drop a template in
an asm block.

* For example:

enum a = octal!777;
asm {
   mov EAX, a;
}

does indeed work.


But, all in all, I don't think octal! itself in asm should work.
It's not literally a literal.


Re: Is the world coming to an end?

2011-04-03 Thread Lars T. Kyllingstad
On Sun, 03 Apr 2011 11:14:16 -0500, Andrei Alexandrescu wrote:

> I agree that 0b could and should be deprecated.

Ditto.

-Lars


Re: Is the world coming to an end?

2011-04-03 Thread Walter Bright

On 4/3/2011 9:28 AM, Michel Fortin wrote:

So it wouldn't bring us much when it comes to parsing different bases, even
though it could be used for other things.


That would also get us into the C++0x territory of having "raw" and "cooked" 
tokens, something I really wish to avoid.


Re: Is the world coming to an end?

2011-04-03 Thread Walter Bright

On 4/3/2011 4:24 AM, spir wrote:

Introducing a
feature (an exception) for a nearly useless notion is weird.


The whole point of this is it is not introducing a feature. It's using existing 
features to emulate a feature that is being removed.


Re: Is the world coming to an end?

2011-04-03 Thread Nick Sabalausky
"Michel Fortin"  wrote in message 
news:ina7e9$2kdh$1...@digitalmars.com...
> On 2011-04-03 12:04:42 -0400, Adam D. Ruppe  
> said:
>
>> btw, it might be worth considering a change to overflow. Suppose
>> there was a way to get arbitrary size ints passed to a template.
>> Then, the library could do its own overflow checks, or not, enabling
>> things like bigint literals in this same fashion.
>>
>> Though, I don't think it's a big benefit. It'd be really weird
>> to use (a new compile time only datatype?)
>
> I've been thinking about the same thing, except instead of having a 
> special data type the template would simply take a string:
>
> template binary(string digits) {
> ...
> }
>
> binary!___;
> // no error, number "___" passed as a string to the 
> template.
>

I've always thought that we should be able to do something like this:

template foo(int val)
{
enum foo = val.meta.argString;
}
static assert(foo!(2+3) == "2+3");




Re: Is the world coming to an end?

2011-04-03 Thread bearophile
Lars T. Kyllingstad:

> > I agree that 0b could and should be deprecated.
> 
> Ditto.

No please :-)

Bye,
bearophile


Re: Is the world coming to an end?

2011-04-03 Thread Walter Bright

On 4/3/2011 2:39 AM, Ulrik Mikaelsson wrote:

If you're looking for uncommonly used language-features that could
easily be otherwise solved, go ahead and remove asm instead. I'll
guess it's about as uncommon as octal literals (or maybe even more),
have simple other solution (just compile it separately and link), and
has much greater impact on the language and the compiler.


I've done assembler the old fashioned way - a separate .asm file assembled with 
masm and linked in - for years. Having the inline assembler is an ENORMOUS 
productivity improvement. Just a few off the top of my head:


1. MASM's syntax changes unpredictably from version to version. I'd get a lot of 
grief from customers with "this doesn't assemble with *my* version of MASM", or 
"I don't have MASM".


2. Different assemblers have utterly different syntax - see MASM and GAS.

3. MASM can't read struct declarations, meaning you now have parallel 
declarations that manually must be synced.


4. MASM doesn't understand C++ or D name mangling.

5. Can't mix MASM files and D code in the same function.

6. Can't access D manifest constants from MASM.

7. D takes care of local variable stack addressing modes for you.

8. I can't fix MASM bugs.

9. And Adam's comments.


Re: Is the world coming to an end?

2011-04-03 Thread Walter Bright

On 4/3/2011 4:48 AM, spir wrote:

When I introduced the topic of octal notation 0nnn beeing bad, I was 100% sure
that (if a move was ever made) either octals would be thrown out of D all
together for beeing nearly useless, or the syntax would be fixed -- the
"obvious" "correct" solution if octals remain. While I new about octal!, this
was so hackish and obviously wrong *for me*, that I did not even imagine one
second it could become the "official" solution.
I'm certainly not the only one.
Questions of detail, sure, but we all know what the details hide ;-)


I can see that the syntax octal!677 can be a bit off-putting at first, simply 
because it is not what we're used to. But give it a chance.


Re: Is the world coming to an end?

2011-04-03 Thread Nick Sabalausky
"Lutger Blijdestijn"  wrote in message 
news:in9t6a$21jb$1...@digitalmars.com...
>
> I don't understand why it is hackish if it's a pure library approach. (it 
> is
> right?) I find it actually rather nice that D can do this. This is not a
> syntax change, octals are out of the language and the library now has an
> octal template. Where's the problem?
>

Apperently, people want to get a warm fuzzy feeling from the existence of 
features they'll never use.

Seriously, we don't have an 0t... for trinary. We don't have an 0q... for 
base-4 (quadrary?). We don't have any such syntax for any base other than 2, 
10, and 16 (and previously 8). And how many people are bitching about those 
omissions? Nobody. But those omissions are *EVERY BIT* as inconsistent with 
decimal/hex/binary syntax as omitting octal is.

But n, apperently we *need* 0o... for octal just simply for the sake of 
*it* existing, but not for any other base. So where the fuck is the 
consistency in the self-proclaimed "consistency" argument? And don't tell me 
"octal is more useful than trinary" because then you're implicitly admitting 
that the consistency argument is a load of crap, and you're jumping ship to 
the "usefulness" argument...which octal *still* looses.




Re: Is the world coming to an end?

2011-04-03 Thread Nick Sabalausky
"spir"  wrote in message 
news:mailman.3064.1301831318.4748.digitalmar...@puremagic.com...
> On 04/03/2011 02:52 AM, bearophile wrote:
>> Michel Fortin:
>>
>>> The new syntax is certainly usable, it's just inelegant and hackish.
>>> Its your language, it's your choice, and I'll admit it won't affect me
>>> much.
>>
>> My suggestions for Walter are:
>> - To turn 01 .. 07 too into errors;
>> - to deprecate the octal! Phobos template.
>> - To introduce the 0o leading that works from 0o0 to the uint.max;
>> - To change the new error message, so it suggests to use 0o.
>> - To ask opinions to the community here next time before changing things 
>> in D2/D3 :-)
>
> I'm very surprised of this move -- aside the concrete details. What I 
> point out here is how far sentiments about what is "obvious" or "correct" 
> can be, for a given issue, that most of us considered wrong for the same 
> reason.
>
> When I introduced the topic of octal notation 0nnn beeing bad, I was 100% 
> sure that (if a move was ever made) either octals would be thrown out of D 
> all together for beeing nearly useless, or the syntax would be fixed --  
> the "obvious" "correct" solution if octals remain. While I new about 
> octal!, this was so hackish and obviously wrong *for me*, that I did not 
> even imagine one second it could become the "official" solution.
> I'm certainly not the only one.
> Questions of detail, sure, but we all know what the details hide ;-)
>

Sounds to me like you wanted a faster horse instead of a car ;)




Re: Is the world coming to an end?

2011-04-03 Thread Nick Sabalausky
"bearophile"  wrote in message 
news:inacud$10b$1...@digitalmars.com...
> Lars T. Kyllingstad:
>
>> > I agree that 0b could and should be deprecated.
>>
>> Ditto.
>
> No please :-)
>

Yea, I'm perfectly fine with omitting built-in octal literals, but I'll jump 
deep into the "bitch and moan" ship if the deprication-axe gets aimed at 
binary.




Re: Is the world coming to an end?

2011-04-03 Thread spir

On 04/03/2011 07:57 PM, Nick Sabalausky wrote:

"Michel Fortin"  wrote in message
news:ina7e9$2kdh$1...@digitalmars.com...

On 2011-04-03 12:04:42 -0400, Adam D. Ruppe
said:


btw, it might be worth considering a change to overflow. Suppose
there was a way to get arbitrary size ints passed to a template.
Then, the library could do its own overflow checks, or not, enabling
things like bigint literals in this same fashion.

Though, I don't think it's a big benefit. It'd be really weird
to use (a new compile time only datatype?)


I've been thinking about the same thing, except instead of having a
special data type the template would simply take a string:

template binary(string digits) {
...
}

binary!___;
// no error, number "___" passed as a string to the
template.



I've always thought that we should be able to do something like this:

template foo(int val)
{
 enum foo = val.meta.argString;
}
static assert(foo!(2+3) == "2+3");


That's Lisp (or Io): non-evaluated arguments (messages). Next century in 
compiled languages ;-)


Denis
--
_
vita es estrany
spir.wikidot.com



Re: Is the world coming to an end?

2011-04-03 Thread Andrei Alexandrescu

On 4/3/11 1:37 PM, spir wrote:

On 04/03/2011 07:57 PM, Nick Sabalausky wrote:

"Michel Fortin" wrote in message
news:ina7e9$2kdh$1...@digitalmars.com...

On 2011-04-03 12:04:42 -0400, Adam D. Ruppe
said:


btw, it might be worth considering a change to overflow. Suppose
there was a way to get arbitrary size ints passed to a template.
Then, the library could do its own overflow checks, or not, enabling
things like bigint literals in this same fashion.

Though, I don't think it's a big benefit. It'd be really weird
to use (a new compile time only datatype?)


I've been thinking about the same thing, except instead of having a
special data type the template would simply take a string:

template binary(string digits) {
...
}

binary!___;
// no error, number "___" passed as a string to the
template.



I've always thought that we should be able to do something like this:

template foo(int val)
{
enum foo = val.meta.argString;
}
static assert(foo!(2+3) == "2+3");


That's Lisp (or Io): non-evaluated arguments (messages). Next century in
compiled languages ;-)


No, that's C's last century's "#" prefix.


Andrei



Re: Is the world coming to an end?

2011-04-03 Thread spir

On 04/03/2011 06:14 PM, Andrei Alexandrescu wrote:

Adding octal!777 to std.conv is consistent with the notion that there still are
a few uses for octal constants that are worth a presence in the standard
library. It is also consistent with the desire to foster other user-defined
literals defined from the same mold.


What about a general baseNumber template instead?
...which would also be trivially "alias-able":
alias baseNumber!3 base3;

Denis
--
_
vita es estrany
spir.wikidot.com



Re: Is the world coming to an end?

2011-04-03 Thread spir

On 04/03/2011 07:19 PM, Adam D. Ruppe wrote:

KennyTM~ wrote:

Talking of asm, would the following be expected to work?


Maybe. Part of me says "yes, it should be the same as a literal*"
but part of me says no because it's weird to drop a template in
an asm block.

* For example:

enum a = octal!777;
asm {
mov EAX, a;
}

does indeed work.


But, all in all, I don't think octal! itself in asm should work.
It's not literally a literal.


The whole is that, precisely, it is not (no more) a literal. Octals have no 
more syntactic existence ;-)


Denis
--
_
vita es estrany
spir.wikidot.com



Re: Is the world coming to an end?

2011-04-03 Thread Andrei Alexandrescu

On 4/3/11 1:40 PM, spir wrote:

On 04/03/2011 06:14 PM, Andrei Alexandrescu wrote:

Adding octal!777 to std.conv is consistent with the notion that there
still are
a few uses for octal constants that are worth a presence in the standard
library. It is also consistent with the desire to foster other
user-defined
literals defined from the same mold.


What about a general baseNumber template instead?
which would also be trivially "alias-able":
alias baseNumber!3 base3;


When was last time you've been in a place in life when you could have 
used a base 3 literal?


Andrei



Re: Is the world coming to an end?

2011-04-03 Thread spir

On 04/03/2011 08:17 PM, Walter Bright wrote:

On 4/3/2011 4:48 AM, spir wrote:

When I introduced the topic of octal notation 0nnn beeing bad, I was 100% sure
that (if a move was ever made) either octals would be thrown out of D all
together for beeing nearly useless, or the syntax would be fixed -- the
"obvious" "correct" solution if octals remain. While I new about octal!, this
was so hackish and obviously wrong *for me*, that I did not even imagine one
second it could become the "official" solution.
I'm certainly not the only one.
Questions of detail, sure, but we all know what the details hide ;-)


I can see that the syntax octal!677 can be a bit off-putting at first, simply
because it is not what we're used to. But give it a chance.


Sorry, I expressed my thought wrongly: I meant this was my first impression. 
Then, I would rather go (see other post) for a general baseNumber! template, 
that could trivially be aliased as in

alias baNumber!3 base3;
What do you think?

Denis
--
_
vita es estrany
spir.wikidot.com



Re: Is the world coming to an end?

2011-04-03 Thread spir

On 04/03/2011 08:27 PM, Nick Sabalausky wrote:

"bearophile"  wrote in message
news:inacud$10b$1...@digitalmars.com...

Lars T. Kyllingstad:


I agree that 0b could and should be deprecated.


Ditto.


No please :-)



Yea, I'm perfectly fine with omitting built-in octal literals, but I'll jump
deep into the "bitch and moan" ship if the deprication-axe gets aimed at
binary.


;-) Same for me: sometimes I just want to write the exact bit sequence. I can't 
automagically figure it out in my head for eg D9 (aging... ).


denis
--
_
vita es estrany
spir.wikidot.com



Re: Is the world coming to an end?

2011-04-03 Thread spir

On 04/03/2011 08:49 PM, Andrei Alexandrescu wrote:

On 4/3/11 1:40 PM, spir wrote:

On 04/03/2011 06:14 PM, Andrei Alexandrescu wrote:

Adding octal!777 to std.conv is consistent with the notion that there
still are
a few uses for octal constants that are worth a presence in the standard
library. It is also consistent with the desire to foster other
user-defined
literals defined from the same mold.


What about a general baseNumber template instead?
which would also be trivially "alias-able":
alias baseNumber!3 base3;


When was last time you've been in a place in life when you could have used a
base 3 literal?


I'm not stating this point (implicitely); I mean that it would be useful. 
Rather you and others let me think at this by saying the template solution 
(octal!) is more general (than 0o).


Denis
--
_
vita es estrany
spir.wikidot.com



Re: Is the world coming to an end?

2011-04-03 Thread Walter Bright

On 4/3/2011 12:03 PM, spir wrote:

Then, I would rather go (see other post) for a general baseNumber! template,
that could trivially be aliased as in
alias baNumber!3 base3;
What do you think?


I think it'd need some compelling use cases.


Re: Is the world coming to an end?

2011-04-03 Thread Dan Olson
Andrei Alexandrescu  writes:

> I agree that 0b could and should be deprecated.

One vote here for not losing 0b.  It may sound silly, but some of D
simple niceties like binary literals and underscores (e.g. 0b0111_0001)
are what made me say to myself "D could be an awesome embedded
language".  Someday I hope to use D instead of C in embedded work.  I
have grown fond of 0b added to some C cross-compilers for manipulating
bits in custom h/w registers.

-- 
Dan


Re: Is the world coming to an end?

2011-04-03 Thread Andrej Mitrovic
On 4/3/11, Nick Sabalausky  wrote:
> I've always thought that we should be able to do something like this:
>
> template foo(int val)
> {
> enum foo = val.meta.argString;
> }
> static assert(foo!(2+3) == "2+3");
>

I wish we had some introspection to get the lines of code inside of a
function. But it's still pretty cool that you can pass expressions to
functions and automatically construct delegates. See here:

import std.stdio;

void main()
{
int x;

foo(false, x = 5);
assert(x != 5);

foo(true, x = 5);
assert(x == 5);
}

void foo(bool doit, int delegate()[] dgs ...)
{
if (doit)
dgs[0]();
}

I wonder how many people know about this feature. I just bumped into
it a few days ago while looking through the docs.


Re: Is the world coming to an end?

2011-04-03 Thread Nick Sabalausky
"Dan Olson"  wrote in message 
news:uzko7qgv2@comcast.net...
> Andrei Alexandrescu  writes:
>
>> I agree that 0b could and should be deprecated.
>
> One vote here for not losing 0b.  It may sound silly, but some of D
> simple niceties like binary literals and underscores (e.g. 0b0111_0001)
> are what made me say to myself "D could be an awesome embedded
> language".  Someday I hope to use D instead of C in embedded work.  I
> have grown fond of 0b added to some C cross-compilers for manipulating
> bits in custom h/w registers.
>

That's exactly what drew me to D too. The prospect of something better than 
C for embedded (and other low-level) work.




Re: Is the world coming to an end?

2011-04-03 Thread Nick Sabalausky
"Andrej Mitrovic"  wrote in message 
news:mailman.3093.1301858962.4748.digitalmar...@puremagic.com...
> On 4/3/11, Nick Sabalausky  wrote:
>> I've always thought that we should be able to do something like this:
>>
>> template foo(int val)
>> {
>> enum foo = val.meta.argString;
>> }
>> static assert(foo!(2+3) == "2+3");
>>
>
> I wish we had some introspection to get the lines of code inside of a
> function. But it's still pretty cool that you can pass expressions to
> functions and automatically construct delegates. See here:
>
> import std.stdio;
>
> void main()
> {
>int x;
>
>foo(false, x = 5);
>assert(x != 5);
>
>foo(true, x = 5);
>assert(x == 5);
> }
>
> void foo(bool doit, int delegate()[] dgs ...)
> {
>if (doit)
>dgs[0]();
> }
>
> I wonder how many people know about this feature. I just bumped into
> it a few days ago while looking through the docs.

I didn't know that. I think I remember the idea of it being discussed, but I 
didn't know it was in.





Re: Is the world coming to an end?

2011-04-03 Thread spir

On 04/03/2011 09:21 PM, Walter Bright wrote:

On 4/3/2011 12:03 PM, spir wrote:

Then, I would rather go (see other post) for a general baseNumber! template,
that could trivially be aliased as in
alias baNumber!3 base3;
What do you think?


I think it'd need some compelling use cases.


Well, like octal!... it's just more general.

Denis
--
_
vita es estrany
spir.wikidot.com



Re: Is the world coming to an end?

2011-04-03 Thread Andrei Alexandrescu

On 4/3/11 2:54 PM, spir wrote:

On 04/03/2011 09:21 PM, Walter Bright wrote:

On 4/3/2011 12:03 PM, spir wrote:

Then, I would rather go (see other post) for a general baseNumber!
template,
that could trivially be aliased as in
alias baNumber!3 base3;
What do you think?


I think it'd need some compelling use cases.


Well, like octal!... it's just more general.


There definitely is such a thing as overly general. I ran into that 
quite often while designing and implementing std.algorithm. Some 
generalization are useful and sometimes pleasantly surprising (e.g. 
levenshtein distance on UTF strings) whereas others are just random. I 
try to foster the former kind and dedicate no specific effort to the latter.


Andrei



  1   2   >