Re: updating druntime

2013-12-13 Thread Benji
On Saturday, 14 December 2013 at 00:15:30 UTC, Marco Leise wrote: Am Fri, 13 Dec 2013 21:40:10 +0100 schrieb "Benji" : I got two errors mentioned above at once.. :( What the heck is happening on your system? :( I plan to install Arch, so hope that will solve it :P

Re: Array - Sockets - Clients

2013-12-13 Thread Irving Montalvo
Thanks! - receive( (shared(Socket) c) { Socket cli = cast(Socket) c; while (cli.isAlive()) { ubyte[8192] buf; ulong bufLen = cli.receive(buf); ... } } );

Re: const method and return type

2013-12-13 Thread Jakob Ovrum
On Saturday, 14 December 2013 at 00:53:27 UTC, Andrea Fontana wrote: Consider this way to escape current constness: This isn't "escaping" constness. Const only means mutation is prevented through that particular reference. It is distinct from immutability.

Re: const method and return type

2013-12-13 Thread Andrea Fontana
On Saturday, 14 December 2013 at 00:31:24 UTC, Adam D. Ruppe wrote: On Saturday, 14 December 2013 at 00:24:01 UTC, Andrea Fontana wrote: Just another thought. If we have: class B; struct C; class A { void method() const { ... } B another_class; C a_struct; } B is just a reference to a o

Re: Array - Sockets - Clients

2013-12-13 Thread Ali Çehreli
On 12/13/2013 04:11 PM, Irving Montalvo wrote: How do I pass a socket to concurrency? send(tid, cli); // Socket cli -- receive ( (Socket cli) { cli.send("1234567890"); } ) - Help me :) Unfortunately, some cast(shared) is needed at this time: import std.stdio; import

Re: const method and return type

2013-12-13 Thread Jakob Ovrum
On Friday, 13 December 2013 at 23:46:14 UTC, Andrea Fontana wrote: class A { auto getter() const { return property; } int property = 0; } Please notice that getter method is marked as const. Why this method return "const int"? `const` as a function attribute just mar

Re: const method and return type

2013-12-13 Thread Adam D. Ruppe
On Saturday, 14 December 2013 at 00:24:01 UTC, Andrea Fontana wrote: Just another thought. If we have: class B; struct C; class A { void method() const { ... } B another_class; C a_struct; } B is just a reference to a object, so method() should not reassign it. The reference should b

Re: const method and return type

2013-12-13 Thread Adam D. Ruppe
On Saturday, 14 December 2013 at 00:09:03 UTC, Andrea Fontana wrote: I'm not changing anything. Just returning it. Right, it is just that "auto" keeps the exact type, and in the const method, the exact type of the members are all const too since that's how the language enforces that you don't

Re: const method and return type

2013-12-13 Thread Andrea Fontana
Just another thought. If we have: class B; struct C; class A { void method() const { ... } B another_class; C a_struct; } B is just a reference to a object, so method() should not reassign it. The reference should be const, not the object itself. method() should be able to call mutab

Re: updating druntime

2013-12-13 Thread Marco Leise
Am Fri, 13 Dec 2013 21:40:10 +0100 schrieb "Benji" : > I got two errors mentioned above at once.. :( What the heck is happening on your system? :( -- Marco

Re: Array - Sockets - Clients

2013-12-13 Thread Irving Montalvo
How do I pass a socket to concurrency? send(tid, cli); // Socket cli -- receive ( (Socket cli) { cli.send("1234567890"); } ) - Help me :)

Re: Strict capacity of array

2013-12-13 Thread Marco Leise
Am Fri, 13 Dec 2013 21:02:58 +0100 schrieb "FreeSlave" : > Thanks for answers. > > On Friday, 13 December 2013 at 19:35:01 UTC, Marco Leise wrote: > > Have you tried this?: > > > > import core.memory; > > int[] data = (cast(int*)GC.malloc(size * int.sizeof, > > GC.BlkAttr.NO_SCAN))[0 .. size]; >

Re: const method and return type

2013-12-13 Thread Andrea Fontana
I read: Const Member Functions Const member functions are functions that are not allowed to change any part of the object through the member function's this reference. I'm not changing anything. Just returning it. Is this a try to avoid something like the following, then? ... B getter() con

Re: const method and return type

2013-12-13 Thread Adam D. Ruppe
On Friday, 13 December 2013 at 23:46:14 UTC, Andrea Fontana wrote: class A { auto getter() const { return property; } int property = 0; Why this method return "const int"? Inside getter, "this" is const. Due to transitive const, all the members through this are const

Re: Array - Sockets - Clients

2013-12-13 Thread Ali Çehreli
On 12/13/2013 03:53 PM, Irving Montalvo wrote: Socket[ulong] clients; ---main() ulong index = clients.length; clients[index] = cli; //<-- Socket cli send(tid, index) -spawned() receive( (ulong i) { clients[i].send('Hello concur

Array - Sockets - Clients

2013-12-13 Thread Irving Montalvo
Socket[ulong] clients; ---main() ulong index = clients.length; clients[index] = cli; //<-- Socket cli send(tid, index) -spawned() receive( (ulong i) { clients[i].send('Hello concurrent'); // Error clients.length is zero } ); --

const method and return type

2013-12-13 Thread Andrea Fontana
class A { auto getter() const { return property; } int property = 0; } Please notice that getter method is marked as const. Why this method return "const int"? If i force it declaring: int getter() const it returns "int". It takes me a lot to understand where the is

Re: updating druntime

2013-12-13 Thread Benji
On Friday, 13 December 2013 at 19:22:20 UTC, Marco Leise wrote: Am Fri, 13 Dec 2013 19:48:46 +0100 schrieb "Benji" : When I compile it this way: dmd helloa.d -L-lphobos2 -L-lcurl Another error appear: [...] helloa.d:(.text._D3std6format66__T14formattedWriteTS3std5array17__T8AppenderTAyaZ8Appen

Re: Strict capacity of array

2013-12-13 Thread FreeSlave
Thanks for answers. On Friday, 13 December 2013 at 19:35:01 UTC, Marco Leise wrote: Have you tried this?: import core.memory; int[] data = (cast(int*)GC.malloc(size * int.sizeof, GC.BlkAttr.NO_SCAN))[0 .. size]; Did you mean GC.BlkAttr.NONE maybe? If I get it right GC.BlkAttr.NO_SCAN means

Re: static if - is the 'static' really needed?

2013-12-13 Thread Chris Cain
On Friday, 13 December 2013 at 12:10:02 UTC, comco wrote: Imagine a world in which a simple 'if' has the semantics of a static if, if the condition is evaluable at CT. Is this a world you would rather live in? They are fundamentally two different things. Eliding the difference is not a good i

Re: Strict capacity of array

2013-12-13 Thread Marco Leise
Am Fri, 13 Dec 2013 19:47:34 +0100 schrieb "FreeSlave" : > Suppose some class contains slice (dynamic array) as data member. > Constructor takes integer value that defines the size of data > should be allocated. After object was constructed size of slice > never changes by design. > > Dynamic

Re: updating druntime

2013-12-13 Thread Marco Leise
Am Fri, 13 Dec 2013 19:48:46 +0100 schrieb "Benji" : > When I compile it this way: dmd helloa.d -L-lphobos2 -L-lcurl > Another error appear: > > [...] > helloa.d:(.text._D3std6format66__T14formattedWriteTS3std5array17__T8AppenderTAyaZ8AppenderTaTmTmZ14formattedWriteFNaNfS3std5array17__T8AppenderT

Re: Strict capacity of array

2013-12-13 Thread Ali Çehreli
On 12/13/2013 10:47 AM, FreeSlave wrote: > Suppose some class contains slice (dynamic array) as data member. > Constructor takes integer value that defines the size of data should be > allocated. After object was constructed size of slice never changes by > design. > > Dynamic arrays are allocate

Re: updating druntime

2013-12-13 Thread Benji
On Friday, 13 December 2013 at 15:00:57 UTC, Marco Leise wrote: Am Thu, 12 Dec 2013 20:29:31 +0100 schrieb "Benji" : On Thursday, 12 December 2013 at 19:11:03 UTC, John Colvin wrote: > On Thursday, 12 December 2013 at 16:44:28 UTC, Benji wrote: >> Hello, >> when I try to compile something with

Strict capacity of array

2013-12-13 Thread FreeSlave
Suppose some class contains slice (dynamic array) as data member. Constructor takes integer value that defines the size of data should be allocated. After object was constructed size of slice never changes by design. Dynamic arrays are allocated with extra space that we can know from 'capacit

Re: Performance of ranges verses direct

2013-12-13 Thread lomereiter
On Friday, 13 December 2013 at 18:03:28 UTC, Nikolay wrote: Results: ~/ldc2-0.12.0-linux-x86_64/bin/ldmd2 -O -release -inline zip_test.d ./zip_test --limit 1000 … 0 - 0 1 - 764 And now try -inline-threshold=1024 ;-) Reading -help-hidden sometimes helps.

Re: ubyte array changing values between calls? Possible bug?

2013-12-13 Thread Rémy Mouëza
It works fine when using dup to the value returned by nativeToBigEndian: public void opAssign(uint value) { this._octets = value.nativeToBigEndian().dup; assert(this._octets == cast (ubyte[]) [1, 2, 3, 4]); } On 12/13/2013 06:35 PM, John Colvin wrote: On Friday, 13

Re: Performance of ranges verses direct

2013-12-13 Thread Nikolay
I found that performance of ranges is miserable in many cases. You should not use them if there is any chance for big/critical computations. Actually I don't like to have two subsets of language: one with good performance, and other with good maintainability/readability. I have a couple thought

Re: ubyte array changing values between calls? Possible bug?

2013-12-13 Thread John Colvin
On Friday, 13 December 2013 at 16:37:51 UTC, Gary Willoughby wrote: I have the following code which is massively simplified from a larger type. The problem occurs between assigning the value to the type and retrieving it. The value is assigned through opAssign and the assert passes. When usin

ubyte array changing values between calls? Possible bug?

2013-12-13 Thread Gary Willoughby
I have the following code which is massively simplified from a larger type. The problem occurs between assigning the value to the type and retrieving it. The value is assigned through opAssign and the assert passes. When using a property to retrieve the same data the assert fails! import std

Re: updating druntime

2013-12-13 Thread John Colvin
On Friday, 13 December 2013 at 15:54:06 UTC, Marco Leise wrote: Am Fri, 13 Dec 2013 16:08:22 +0100 schrieb "John Colvin" : On Friday, 13 December 2013 at 15:00:57 UTC, Marco Leise wrote: > I'd say format c: A bit drastic, or am i missing something?!?! That was meant as "remove anything D rel

Re: Allowing string value with getopt without requiring it

2013-12-13 Thread H. S. Teoh
On Fri, Dec 13, 2013 at 10:46:57AM +0100, John Colvin wrote: > On Friday, 13 December 2013 at 01:51:25 UTC, Ithy wrote: > >Hello. I'm just getting into D (literally writing my first > >program), and I can't figure out how to do this with getopt: > > > >I want to have the option --log, which will en

Re: Ranges: is it ok if front is a data member?

2013-12-13 Thread H. S. Teoh
On Fri, Dec 13, 2013 at 04:20:18PM +0100, Joseph Rushton Wakeling wrote: > On 13/12/13 16:52, Marco Leise wrote: > >Most non-trivial ranges do the actual work in `popFront()' and > >return a cached value from `front'. It has been argued as a > >design quirk, that this in general leads to: > > > >st

Re: updating druntime

2013-12-13 Thread Marco Leise
Am Fri, 13 Dec 2013 16:08:22 +0100 schrieb "John Colvin" : > On Friday, 13 December 2013 at 15:00:57 UTC, Marco Leise wrote: > > I'd say format c: > > A bit drastic, or am i missing something?!?! That was meant as "remove anything D related from your system". format c: on a POSIX system, come on

Demangling D Symbols when Profiling D Programs with perf

2013-12-13 Thread Nordlöw
I've just discovered the fantastic tool perf on Linux. I profiled a D program with this but when I call perf report the symbols are not demangled. I'm aware of `ddemangle` but this only works in batch-processing mode. I could always dump the output to a file for viewing. But it would be

Re: static if - is the 'static' really needed?

2013-12-13 Thread Jesse Phillips
On Friday, 13 December 2013 at 12:10:02 UTC, comco wrote: Imagine a world in which a simple 'if' has the semantics of a static if, if the condition is evaluable at CT. Is this a world you would rather live in? template Fac(int i) { if (i == 0) { // static if; doesn't introduce scope enum Fac =

Re: Ranges: is it ok if front is a data member?

2013-12-13 Thread Joseph Rushton Wakeling
On 13/12/13 16:52, Marco Leise wrote: Most non-trivial ranges do the actual work in `popFront()' and return a cached value from `front'. It has been argued as a design quirk, that this in general leads to: struct Range { bool popFrontHasBeenCalledOnce = false; T current; @property T fr

Re: Performance of ranges verses direct

2013-12-13 Thread Marco Leise
Am Thu, 12 Dec 2013 16:02:28 +0100 schrieb "John Colvin" : > On Wednesday, 11 December 2013 at 16:40:48 UTC, Joseph Rushton > Wakeling wrote: > > [* If I recall right, it's achievable by special-casing iota > > when the increment is 1, but don't quote me on that.] > > That shouldn't be necessar

Re: updating druntime

2013-12-13 Thread John Colvin
On Friday, 13 December 2013 at 15:00:57 UTC, Marco Leise wrote: I'd say format c: A bit drastic, or am i missing something?!?!

Re: updating druntime

2013-12-13 Thread Marco Leise
Am Thu, 12 Dec 2013 20:29:31 +0100 schrieb "Benji" : > On Thursday, 12 December 2013 at 19:11:03 UTC, John Colvin wrote: > > On Thursday, 12 December 2013 at 16:44:28 UTC, Benji wrote: > >> Hello, > >> when I try to compile something with dmd, > >> I get following message: > >> > >> /usr/include/d

Re: Ranges: is it ok if front is a data member?

2013-12-13 Thread Marco Leise
Am Thu, 12 Dec 2013 08:43:35 -0800 schrieb "H. S. Teoh" : > I do this with my own ranges sometimes. Sometimes, it's more performant > to precompute the value of .front and store it (as .front), and have > .popFront compute the next value, than to have .front compute the value > every time. AFAICT,

Re: Is file.rename() atomic?

2013-12-13 Thread Marco Leise
Am Thu, 12 Dec 2013 18:08:12 +0100 schrieb "Jacek Furmankiewicz" : > void rename(in char[] from, in char[] to); > Rename file from to to. If the target file exists, it is > overwritten. > > Throws: > FileException on error. > > Just wanted to know if this operatio

Re: Ensuring template argument is descendant of class

2013-12-13 Thread Brian Rogoff
On Friday, 13 December 2013 at 05:55:09 UTC, H. S. Teoh wrote: On Fri, Dec 13, 2013 at 06:42:26AM +0100, Brian Rogoff wrote: I'm sympathetic to this POV, or something similar. For example, a multiyear plan to deprecate the 'is' syntax and replace it with something better, in the current D. I'm

Re: String mixins with string arrays

2013-12-13 Thread John Colvin
On Friday, 13 December 2013 at 13:23:24 UTC, Mike James wrote: On Friday, 13 December 2013 at 12:09:59 UTC, John Colvin wrote: On Friday, 13 December 2013 at 11:40:35 UTC, Mike James wrote: Hi, Is it possible to pass a string array to a string mixin e.g template GenSomething(string foo, strin

Re: String mixins with string arrays

2013-12-13 Thread Mike James
On Friday, 13 December 2013 at 12:09:59 UTC, John Colvin wrote: On Friday, 13 December 2013 at 11:40:35 UTC, Mike James wrote: Hi, Is it possible to pass a string array to a string mixin e.g template GenSomething(string foo, string[] bar){ some_kind_of_foreach(br: bar) { const char[] foo ~

Re: static if - is the 'static' really needed?

2013-12-13 Thread comco
On Friday, 13 December 2013 at 12:50:01 UTC, Nicolas Sicard wrote: On Friday, 13 December 2013 at 12:10:02 UTC, comco wrote: Imagine a world in which a simple 'if' has the semantics of a static if, if the condition is evaluable at CT. Is this a world you would rather live in? template Fac(int

Re: static if - is the 'static' really needed?

2013-12-13 Thread Nicolas Sicard
On Friday, 13 December 2013 at 12:10:02 UTC, comco wrote: Imagine a world in which a simple 'if' has the semantics of a static if, if the condition is evaluable at CT. Is this a world you would rather live in? template Fac(int i) { if (i == 0) { // static if; doesn't introduce scope enum Fac =

Re: String mixins with string arrays

2013-12-13 Thread John Colvin
On Friday, 13 December 2013 at 11:40:35 UTC, Mike James wrote: Hi, Is it possible to pass a string array to a string mixin e.g template GenSomething(string foo, string[] bar){ some_kind_of_foreach(br: bar) { const char[] foo ~ br ~ ";\n"; } } and call: mixin(GenSomething!("A", ["B", "

static if - is the 'static' really needed?

2013-12-13 Thread comco
Imagine a world in which a simple 'if' has the semantics of a static if, if the condition is evaluable at CT. Is this a world you would rather live in? template Fac(int i) { if (i == 0) { // static if; doesn't introduce scope enum Fac = 1; } else { enum Fac = i * Fac!(i-1); } } // If the condi

Match properties as member variables

2013-12-13 Thread comco
From client perspective, properties look like member variables. With (auto) ref, a generic function can catch a member variable and read it and update it: void swap(T)(ref T a, ref T b) {...} The client can use swap with member variables. But he can't use this swap with class properties - they

Re: Type inference and overloaded functions

2013-12-13 Thread Namespace
On Friday, 13 December 2013 at 00:37:36 UTC, Namespace wrote: Why don't you discuss on github? And finally I did it: auto[$] a_arr2 = dyn_arr[4 .. 8]; assert(is(typeof(a_arr2) == int[4])); I will make a Pull Request tomorrow. Hope my code isn't that bad. :/ Done: https://github.co

String mixins with string arrays

2013-12-13 Thread Mike James
Hi, Is it possible to pass a string array to a string mixin e.g template GenSomething(string foo, string[] bar){ some_kind_of_foreach(br: bar) { const char[] foo ~ br ~ ";\n"; } } and call: mixin(GenSomething!("A", ["B", "C", "D"])); would generate: A.B; A.C; A.D; Regards, -=mike=-

Re: Interfacing C programs: Pass D string to C function

2013-12-13 Thread Mike Parker
On 12/13/2013 5:00 PM, Dfr wrote: Hello I trying to write simple wrapper around pcre and have problem passing strings to it. As i understood, the best way is std.string.toStringZ. So, my code look like: string pattern = ""; pcre_compile2( toStringz(pattern), options, &errcode, &errmsg, &er

Re: Allowing string value with getopt without requiring it

2013-12-13 Thread John Colvin
On Friday, 13 December 2013 at 01:51:25 UTC, Ithy wrote: Hello. I'm just getting into D (literally writing my first program), and I can't figure out how to do this with getopt: I want to have the option --log, which will enable logging (set a bool variable to true). However, I want the program

Re: Interfacing C programs: Pass D string to C function

2013-12-13 Thread Jonathan M Davis
On Friday, December 13, 2013 09:00:20 Dfr wrote: > Hello > > I trying to write simple wrapper around pcre and have problem > passing strings to it. As i understood, the best way is > std.string.toStringZ. > > So, my code look like: > > string pattern = ""; > pcre_compile2( toStringz(pattern)

Re: What is the common way of porting opaque types in C header files?

2013-12-13 Thread Gary Willoughby
On Friday, 13 December 2013 at 01:20:41 UTC, Mike Parker wrote: On 12/13/2013 7:52 AM, Gary Willoughby wrote: I have a lot of opaque types in C headers i'm porting to D. What is the best way to handle these? Would you just use void pointers? In the below example Tcl_AsyncHandler_ is not define

Re: Interfacing C programs: Pass D string to C function

2013-12-13 Thread Ithy
On Friday, 13 December 2013 at 08:00:21 UTC, Dfr wrote: Hello I trying to write simple wrapper around pcre and have problem passing strings to it. As i understood, the best way is std.string.toStringZ. So, my code look like: string pattern = ""; pcre_compile2( toStringz(pattern), optio

Interfacing C programs: Pass D string to C function

2013-12-13 Thread Dfr
Hello I trying to write simple wrapper around pcre and have problem passing strings to it. As i understood, the best way is std.string.toStringZ. So, my code look like: string pattern = ""; pcre_compile2( toStringz(pattern), options, &errcode, &errmsg, &erroffset, cast(char*)null); T