Differing levels of type-inference: Can D do this?

2012-07-27 Thread Chad J
Is there some way to do something similar to this right now? void main() { // Differing levels of type-inference: int[] r1 = [1,2,3]; // No type-inference. Range!(int) r2 = [1,2,3]; // Only range kind inferred. Range r3 = [1,2,3]; // Element type inferred. autor4 = [

Re: A few questions

2012-07-27 Thread bearophile
Jonathan M Davis: // x is a nullable class reference if (x == null) { ... } else { // here the type system sees x as not null. } ??? What does it matter if the type system knows whether a pointer is null unless it's trying to warn you about dereferencing null? In the else branch

Re: A few questions

2012-07-27 Thread Simen Kjaeraas
On Fri, 27 Jul 2012 22:16:05 +0200, Namespace wrote: And that is the explicit way with pre- and postconditions of Java, which i want to avoid. I see, the most of you prefer to write "try and catch" or use the java principle with explicit pre- and post conditions. The time will show, if

Re: A few questions

2012-07-27 Thread Jonathan M Davis
On Saturday, July 28, 2012 01:48:00 bearophile wrote: > Jonathan M Davis: > > Adding something to the language doesn't buy you much more than > > that anyway. > > In the case of not-nullability, this isn't true. Integrating > not-null in the type system allows the language to do things you > can't

Re: A few questions

2012-07-27 Thread bearophile
Jonathan M Davis: Adding something to the language doesn't buy you much more than that anyway. In the case of not-nullability, this isn't true. Integrating not-null in the type system allows the language to do things you can't do with NotNull, like: // x is a nullable class reference if (

Re: A few questions

2012-07-27 Thread Jonathan M Davis
On Saturday, July 28, 2012 01:16:41 Namespace wrote: > Therefore i hope that it will be official added into D. > Otherwise of course i use it only for projects between me and my > other students. > > I don't know what is wrong with this shorthand. So why don't give > it a try? I don't even know w

Re: A few questions

2012-07-27 Thread Adam D. Ruppe
I started a not null struct for phobos but then had to move, added another job, and other real life stuff that meant I haven't finished it yet. Fairly usable though. Look for struct NotNull: https://github.com/adamdruppe/phobos/blob/0c97414bb4aa3c748caa42948ffec25f8a291300/std/typecons.d (also

Re: A few questions

2012-07-27 Thread Namespace
Therefore i hope that it will be official added into D. Otherwise of course i use it only for projects between me and my other students. I don't know what is wrong with this shorthand. So why don't give it a try? I'm absolutely sure that Walter will _never_ add real non-nullable references. A

Re: A few questions

2012-07-27 Thread Jonathan M Davis
On Saturday, July 28, 2012 01:00:22 Namespace wrote: > Me again. > What's the matter if i write something for that shorthand and dmd > has only to switch to it before the compiling begins? Doing stuff like that makes your code completely unportable. It's _bad_ practice. Don't go and try to redesi

Re: A few questions

2012-07-27 Thread Namespace
Me again. What's the matter if i write something for that shorthand and dmd has only to switch to it before the compiling begins? My little test program works with VisualD. I goto the build events and there i write into "Pre-Build Command": [quote]not_null main.d #t[/quote] and into "Post-Buil

Implementing a Monitor

2012-07-27 Thread Minas Mina
I'm using condition variables to implement a monitor that simulates the producer-consumer(unbounded buffer) scenario. Note: monitor is __gshared and is initialized in main(). Then the other threads are created and run. There is one producer thread, and 5 consumer threads. void producer() {

Re: A few questions

2012-07-27 Thread Artur Skawina
On 07/27/12 21:48, Adam D. Ruppe wrote: > On Windows, an access violation (from a null pointer or other > causes) is an exception that is thrown and can even be caught. > > On Linux, a segfault is a signal that just kills the program, > it doesn't work like a regular exception. It's not a regular

Re: A few questions

2012-07-27 Thread Namespace
And that is the explicit way with pre- and postconditions of Java, which i want to avoid. I see, the most of you prefer to write "try and catch" or use the java principle with explicit pre- and post conditions. The time will show, if D get therewith enough members to get serious. But this is

Re: A few questions

2012-07-27 Thread Adam D. Ruppe
On Friday, 27 July 2012 at 19:50:46 UTC, Era Scarecrow wrote: Linux also dumps the state into a file. Only if core dumps are enabled... but I think someone did a Linux stack trace signal handler somewhere for D, but it never got merged into druntime. (What it'd do is print out some info before

Re: A few questions

2012-07-27 Thread Era Scarecrow
On Friday, 27 July 2012 at 19:48:33 UTC, Adam D. Ruppe wrote: On Windows, an access violation (from a null pointer or other causes) is an exception that is thrown and can even be caught. On Linux, a segfault is a signal that just kills the program, it doesn't work like a regular exception. Li

Re: A few questions

2012-07-27 Thread Adam D. Ruppe
On Windows, an access violation (from a null pointer or other causes) is an exception that is thrown and can even be caught. On Linux, a segfault is a signal that just kills the program, it doesn't work like a regular exception. The Windows exceptions can do pretty stack traces, including on nu

Re: A few questions

2012-07-27 Thread Era Scarecrow
On Friday, 27 July 2012 at 19:01:39 UTC, Namespace wrote: I also get null references (and every time I hate D a bit more), but mostly my classmates and other friends whom I've shown D. And most of them are already back to C++ or C#. And I can understand them. If you want that D is sometimes tak

Re: A few questions

2012-07-27 Thread Namespace
I also get null references (and every time i hate D a bit more), but mostly my classmates and other friends whom I've shown D. And most of them are already back to C++ or C#. And I can understand them. If you want that D is sometimes taken seriously (and it reached only if you win more people f

Re: copying the targets of pointers

2012-07-27 Thread Artur Skawina
On 07/27/12 19:28, monarch_dodra wrote: > On Friday, 27 July 2012 at 16:47:47 UTC, Artur Skawina wrote: >> On 07/27/12 18:11, monarch_dodra wrote: >>> This is going to sound stupid, but how do you have two pointers' targets >>> copy each other? since pointers are used like reference types, how do

Re: A few questions

2012-07-27 Thread Jonathan M Davis
On Friday, July 27, 2012 20:07:56 Namespace wrote: > > Walter's stand on this is that the OS gives you > > null-dereferencing detection - > > i.e. segfaults and access violations. He's not going to add > > extra syntax for > > it. > > > > - Jonathan M Davis > > That is a huge mistake. My OS print

Re: A few questions

2012-07-27 Thread Namespace
Walter's stand on this is that the OS gives you null-dereferencing detection - i.e. segfaults and access violations. He's not going to add extra syntax for it. - Jonathan M Davis That is a huge mistake. My OS prints me only a funny "Access violation". And so i can search for my little null

Re: copying the targets of pointers

2012-07-27 Thread Jonathan M Davis
On Friday, July 27, 2012 10:32:07 Ali Çehreli wrote: > On 07/27/2012 09:11 AM, monarch_dodra wrote: > > This is going to sound stupid, but how do you have two pointers' targets > > copy each other? since pointers are used like reference types, how do > > you write the C++ equivalent of "*p1 == *

Re: A few questions

2012-07-27 Thread Jonathan M Davis
On Friday, July 27, 2012 19:34:52 Simen Kjaeraas wrote: > On Fri, 27 Jul 2012 17:35:19 +0200, Jonathan M Davis > > wrote: > > Many of us think that > > > > const Foo func() {} > > > > should just become illegal inconsistency or not because of all of this > > confusion, but Walter doesn't buy in

Re: copying the targets of pointers

2012-07-27 Thread Simen Kjaeraas
On Fri, 27 Jul 2012 19:28:06 +0200, monarch_dodra wrote: I'm kind of confused, because every time I see pointer usage, the deference operator is omitted? For example: struct S { void foo(){}; } S* p = new S(); p.foo(); When and where can/should/shouldn't I derefer

Re: Assert prints an "array of char" when used why to!string

2012-07-27 Thread Ali Çehreli
On 07/27/2012 09:02 AM, monarch_dodra wrote: > On Friday, 27 July 2012 at 11:56:07 UTC, bearophile wrote: >> monarch_dodra: >> >>> 1) Is this the "normal" behavior, or a "known limitation"? >> >> It seems a DMD bug, why don't you add it to Bugzilla? >> >> >>> 2) Is there a "workaround"? >> >> stat

Re: A few questions

2012-07-27 Thread Simen Kjaeraas
On Fri, 27 Jul 2012 17:35:19 +0200, Jonathan M Davis wrote: Many of us think that const Foo func() {} should just become illegal inconsistency or not because of all of this confusion, but Walter doesn't buy into that. Like monarch_dodra said, this is also a style favored by some: @pure @

Re: copying the targets of pointers

2012-07-27 Thread Ali Çehreli
On 07/27/2012 09:11 AM, monarch_dodra wrote: > This is going to sound stupid, but how do you have two pointers' targets > copy each other? since pointers are used like reference types, how do > you write the C++ equivalent of "*p1 == *p2" The type must provide a function to make a copy of itself.

Re: A matter of inout

2012-07-27 Thread Ali Çehreli
On 07/27/2012 10:13 AM, bearophile wrote: > Artur Skawina: > >> 'inout' basically means 'local const' - if you'd allow inout >> data to be modified then it wouldn't be possible to call the >> function with a const or immutable argument - which is the >> whole point of inout... > > dmd 2.059 was wr

Re: copying the targets of pointers

2012-07-27 Thread monarch_dodra
On Friday, 27 July 2012 at 16:47:47 UTC, Artur Skawina wrote: On 07/27/12 18:11, monarch_dodra wrote: This is going to sound stupid, but how do you have two pointers' targets copy each other? since pointers are used like reference types, how do you write the C++ equivalent of "*p1 == *p2" Ex

Re: A matter of inout

2012-07-27 Thread Artur Skawina
On 07/27/12 19:06, bearophile wrote: > Artur Skawina: > >> 'inout' basically means 'local const' - if you'd allow inout >> data to be modified then it wouldn't be possible to call the >> function with a const or immutable argument - which is the >> whole point of inout... >> You probably want 'ino

Re: A matter of inout

2012-07-27 Thread bearophile
Artur Skawina: 'inout' basically means 'local const' - if you'd allow inout data to be modified then it wouldn't be possible to call the function with a const or immutable argument - which is the whole point of inout... dmd 2.059 was wrong then. Bye, bearophile

Re: A matter of inout

2012-07-27 Thread bearophile
Artur Skawina: 'inout' basically means 'local const' - if you'd allow inout data to be modified then it wouldn't be possible to call the function with a const or immutable argument - which is the whole point of inout... You probably want 'inout(T)[]' if you're going to alter the array. Using i

Re: copying the targets of pointers

2012-07-27 Thread Artur Skawina
On 07/27/12 18:11, monarch_dodra wrote: > This is going to sound stupid, but how do you have two pointers' targets copy > each other? since pointers are used like reference types, how do you write > the C++ equivalent of "*p1 == *p2" Exactly the same, there's no difference between C and D pointe

Re: A matter of inout

2012-07-27 Thread Artur Skawina
On 07/27/12 17:53, bearophile wrote: > This program used to compile in DMD 2.059: > > > import std.stdio; > inout(T[]) forwardDifference(T)(inout(T[]) s, in int n) pure { > foreach (_; 0 .. n) > s[] -= s[1 .. $]; > return s[0 .. $-n]; > } > void main() { > immutable A = [90.5,

Re: A matter of inout

2012-07-27 Thread Dmitry Olshansky
On 27-Jul-12 19:53, bearophile wrote: This program used to compile in DMD 2.059: import std.stdio; inout(T[]) forwardDifference(T)(inout(T[]) s, in int n) pure { foreach (_; 0 .. n) s[] -= s[1 .. $]; return s[0 .. $-n]; } void main() { immutable A = [90.5, 47, 58, 29, 22

copying the targets of pointers

2012-07-27 Thread monarch_dodra
This is going to sound stupid, but how do you have two pointers' targets copy each other? since pointers are used like reference types, how do you write the C++ equivalent of "*p1 == *p2" Here is the context of what I'm trying to do: struct S { struct Payload {} Payload payload;

Re: Just a matter of parentheses

2012-07-27 Thread bearophile
Alex Rønne Petersen: Yes. keys is specifically meant to be a property. http://d.puremagic.com/issues/show_bug.cgi?id=8453 Bye, bearophile

Re: Assert prints an "array of char" when used why to!string

2012-07-27 Thread monarch_dodra
On Friday, 27 July 2012 at 11:56:07 UTC, bearophile wrote: monarch_dodra: 1) Is this the "normal" behavior, or a "known limitation"? It seems a DMD bug, why don't you add it to Bugzilla? 2) Is there a "workaround"? static assert(0, text("Failure: ", 55)); Bye, bearophile Thanks. I'll

A matter of inout

2012-07-27 Thread bearophile
This program used to compile in DMD 2.059: import std.stdio; inout(T[]) forwardDifference(T)(inout(T[]) s, in int n) pure { foreach (_; 0 .. n) s[] -= s[1 .. $]; return s[0 .. $-n]; } void main() { immutable A = [90.5, 47, 58, 29, 22, 32, 55, 5, 55, 73.5]; foreach (level;

Re: A few questions

2012-07-27 Thread Jonathan M Davis
On Friday, July 27, 2012 12:29:13 Namespace wrote: > 1. > Why are these two method header identitcal? > > const Foo some_function() { > > and > > Foo some_function() const { > > ? > const(Foo) but ref Foo. This is inconsistency, if you ask me. > So why is between C++ and D such a huge differen

Re: Just a matter of parentheses

2012-07-27 Thread Alex Rønne Petersen
On 27-07-2012 17:23, bearophile wrote: This works in DMD 2.059, but it doesn't in dmd 2.060beta: import std.algorithm: sort; void main() { int[int] foo; auto bar1 = foo.keys().sort(); // OK auto bar2 = foo.keys.sort(); // Error: function expected before ()... } Do you think thi

Just a matter of parentheses

2012-07-27 Thread bearophile
This works in DMD 2.059, but it doesn't in dmd 2.060beta: import std.algorithm: sort; void main() { int[int] foo; auto bar1 = foo.keys().sort(); // OK auto bar2 = foo.keys.sort(); // Error: function expected before ()... } Do you think this should be filed as regression? Bye, be

Re: A few questions

2012-07-27 Thread Simen Kjaeraas
On Fri, 27 Jul 2012 16:39:49 +0200, Namespace wrote: What's wrong with the solution that void some_function(Foo? f) { is converted to void some_function(Foo f, string filename = __FILE__, uint line = __LINE__) in { assert(f !is null, std.string.format("Null Object @ File %s on Line

Re: Assert prints an "array of char" when used why to!string

2012-07-27 Thread novice2
Ah, thanks! On Friday, 27 July 2012 at 14:47:49 UTC, Adam D. Ruppe wrote: On Friday, 27 July 2012 at 14:40:33 UTC, novice2 wrote: What is the "three character widths" note? Who knows? string, wstring, and dstring. Width refers to the bit size of the char (8 bit, 16 bit, or 32 bit).

Re: Assert prints an "array of char" when used why to!string

2012-07-27 Thread Adam D. Ruppe
On Friday, 27 July 2012 at 14:40:33 UTC, novice2 wrote: What is the "three character widths" note? Who knows? string, wstring, and dstring. Width refers to the bit size of the char (8 bit, 16 bit, or 32 bit).

Re: Assert prints an "array of char" when used why to!string

2012-07-27 Thread novice2
BTW, in docs about "text": http://dlang.org/phobos/std_conv.html#text "...Convenience functions for converting any number and types of arguments into text (the three character widths)... " What is the "three character widths" note? Who knows?

Re: A few questions

2012-07-27 Thread Namespace
What's wrong with the solution that void some_function(Foo? f) { is converted to void some_function(Foo f, string filename = __FILE__, uint line = __LINE__) in { assert(f !is null, std.string.format("Null Object @ File %s on Line %d.", filename, line)); } body { ? It isn't a huge effor

Re: A few questions

2012-07-27 Thread bearophile
Simen Kjaeraas: I believe at least part of the explanation is that Walter wants NotNull to implemented in a library. That's part of the reason for introducing @disable this(). Yes, I remember part of the discussions. And I agree that generally it's better to put meta-features in a language t

Re: A few questions

2012-07-27 Thread Namespace
Short improvement: http://dpaste.dzfl.pl/f3263def

Re: A few questions

2012-07-27 Thread Simen Kjaeraas
On Fri, 27 Jul 2012 14:44:35 +0200, bearophile wrote: Namespace: Then: What is the problem to introduce such shorthand? I don't know. I have a partial enhancement on the topic: http://d.puremagic.com/issues/show_bug.cgi?id=4571 Bye, bearophile I believe at least part of the explanation

Re: A few questions

2012-07-27 Thread bearophile
Namespace: Then: What is the problem to introduce such shorthand? I don't know. I have a partial enhancement on the topic: http://d.puremagic.com/issues/show_bug.cgi?id=4571 Bye, bearophile

Re: A few questions

2012-07-27 Thread Namespace
On Friday, 27 July 2012 at 11:50:46 UTC, bearophile wrote: Namespace: Good point. I had completely forgotten, that that is possible. But it seems that no one would have interest in my second proposal. :) Similar things were discussed a lot. And some people think that similar nonnull annotat

Re: Assert prints an "array of char" when used why to!string

2012-07-27 Thread bearophile
monarch_dodra: 1) Is this the "normal" behavior, or a "known limitation"? It seems a DMD bug, why don't you add it to Bugzilla? 2) Is there a "workaround"? static assert(0, text("Failure: ", 55)); Bye, bearophile

Re: A few questions

2012-07-27 Thread bearophile
Namespace: Good point. I had completely forgotten, that that is possible. But it seems that no one would have interest in my second proposal. :) Similar things were discussed a lot. And some people think that similar nonnull annotations are a good idea. Bye, bearophile

Re: A few questions

2012-07-27 Thread Namespace
The reason "const Foo some_function" is allowed is because in D this syntax is possible: class Foo { const: Foo some_function () {} } Good point. I had completely forgotten, that that is possible. But it seems that no one would have interest in my second proposal. :)

Re: A few questions

2012-07-27 Thread Jacob Carlborg
On 2012-07-27 13:14, Jacob Carlborg wrote: On 2012-07-27 12:29, Namespace wrote: const(Foo) but ref Foo. This is inconsistency, if you ask me. So why is between C++ and D such a huge difference? Why isn't it simply const Foo instead of const(Foo)? I think the reason is the same as above. If

Re: A few questions

2012-07-27 Thread Jacob Carlborg
On 2012-07-27 12:29, Namespace wrote: 1. Why are these two method header identitcal? const Foo some_function() { and Foo some_function() const { ? The reason "const Foo some_function" is allowed is because in D this syntax is possible: class Foo { const: Foo some_function () {}

Re: A few questions

2012-07-27 Thread monarch_dodra
On Friday, 27 July 2012 at 10:29:15 UTC, Namespace wrote: 1. Why are these two method header identitcal? const Foo some_function() { and Foo some_function() const { ? IMO that isn't consistent. IMO only the last is valid. With this example, it is somewhat understandable. Some would argue o

A few questions

2012-07-27 Thread Namespace
1. Why are these two method header identitcal? const Foo some_function() { and Foo some_function() const { ? IMO that isn't consistent. IMO only the last is valid. With this example, it is somewhat understandable. // C++ class Bar { const Foo getFooObj() const { ... } const Foo& getF

Assert prints an "array of char" when used why to!string

2012-07-27 Thread monarch_dodra
Code: import std.conv; void main() { static assert( is(typeof(("Failure: " ~ to!string(55)) == string)) ); static assert(0 , ("Failure: " ~ to!string(55))); } main.d(7): Error: static assert ['F','a','i','l','u','r','e',':',' ','5','5'] The problem is the ugly-ass "p

Re: Writing very large files 50+ GB

2012-07-27 Thread Regan Heath
On Fri, 27 Jul 2012 02:50:56 +0100, wmunger wrote: I need to write to a file that is 50 to 250GB on all three major operating systems. I tried to use the c function pwrite64. But it is not available on the Mac. I have seen where some have used the iostream in C++ but this does not see