Error: cannot implicitly convert expression (this) of type const(S) to S

2010-09-18 Thread Jonathan M Davis
Okay, if I try and compile the following program. struct S { @property S save() const { return this; } int[] _val; } void main() { } I get the error message d.d(5): Error: cannot implicitly convert expression (this) of type const(S) to S If I remove const from

Re: Function with default parameters

2010-09-18 Thread Jacob Carlborg
On 2010-09-18 00:37, Mariusz GliwiƄski wrote: I just could promise I've seen in D2 something like in scripting languages: module test; void main (string[] args) { test(b = test); } void test(string a = a, string b = b, string c = c) { } Basically picking just right parameter while other have

Where is module dstats.all for dflplot?

2010-09-18 Thread Sam Hu
Greetings! I want to have a try on dflplot.But I don't find module dstats.all which is used by dflplot.d,could anybody let me where it is? Thank you.

Garbage Collection, Allocators/Deallocators and Constructors/Destructors

2010-09-18 Thread Ivo Kasiuk
Hi, to improve my understanding of the GC and when/how allocators/deallocators and constructors/destructors get called, I wrote a little test program. And now I understand even less than before... Here is the program: import core.memory; import std.stdio;

Re: Error: cannot implicitly convert expression (this) of type const(S) to S

2010-09-18 Thread Ivo Kasiuk
Am Samstag, den 18.09.2010, 02:15 -0700 schrieb Jonathan M Davis: Okay, if I try and compile the following program. struct S { @property S save() const { return this; } int[] _val; } void main() { } Actually, wouldn't it be much more simple to just copy

Re: Garbage Collection, Allocators/Deallocators and

2010-09-18 Thread Sean Kelly
Ivo Kasiuk Wrote: Hi, to improve my understanding of the GC and when/how allocators/deallocators and constructors/destructors get called, I wrote a little test program. And now I understand even less than before... ... Running this with DMD 2.049, I observed the following: - S1(int),

Re: FIle I/O

2010-09-18 Thread Graham Nicholls
Thanks. I figured that it was a duplicate definition, but not if I leave out st.stream, then OpenException is undefined. Is there a documentation for the exceptions which are in the relevant packages - I'll struggle without it! And thanks, all for the help - much appreciated. BTW, am I making

Re: Garbage Collection, Allocators/Deallocators and

2010-09-18 Thread Ivo Kasiuk
Am Samstag, den 18.09.2010, 10:08 -0400 schrieb Sean Kelly: Ivo Kasiuk Wrote: Hi, to improve my understanding of the GC and when/how allocators/deallocators and constructors/destructors get called, I wrote a little test program. And now I understand even less than before... ...

Re: Error: cannot implicitly convert expression (this) of type const(S) to S

2010-09-18 Thread Steven Schveighoffer
On Sat, 18 Sep 2010 05:15:38 -0400, Jonathan M Davis jmdavisp...@gmx.com wrote: Okay, if I try and compile the following program. struct S { @property S save() const { return this; } int[] _val; } void main() { } I get the error message d.d(5): Error: cannot

Re: Garbage Collection, Allocators/Deallocators and

2010-09-18 Thread Ivo Kasiuk
An interesting case is when using C's malloc for C1 and using the scope attribute for c1: class C1 { ubyte[1_000_000] buf; new(size_t size) { void* ptr = std.c.stdlib.malloc(size); if (ptr is null) throw new OutOfMemoryError(__FILE__, __LINE__); writefln(C1.new(%d)

Applying a tuple to a function (and more)

2010-09-18 Thread Juanjo Alvarez
Hi, I've just arrived to D 2.0 and after reading Andrei's book I'm loving everything I'm seeing (except the bugs, of course). I wanted to ask how these would be done, because I can't find how to do it: 1. Having the strings, defined at compile time, MyClass and mymethod, how could I could I get

Re: Garbage Collection, Allocators/Deallocators and

2010-09-18 Thread Simen kjaeraas
Ivo Kasiuk i.kas...@gmx.de wrote: Ok, that makes sense. So the deallocators really should not get called in this case. But why are the destructors not invoked when the GC finalizes the objects? For S1 and S2, this is a known bug - destructors of structs on the heap don't get called. As for

Re: Applying a tuple to a function (and more)

2010-09-18 Thread Philippe Sigaud
On Sat, Sep 18, 2010 at 19:59, Juanjo Alvarez juan...@gmail.com wrote: I wanted to ask how these would be done, because I can't find how to do it: 1. Having the strings, defined at compile time, MyClass and mymethod, how could I could I get to a delegate to MyClass.mymethod? You can insert

Re: Function with default parameters

2010-09-18 Thread Philippe Sigaud
It seems doable to have some kind of function transformer (adaptor?) for this. from: int foo(int a = 0, int b = 1, double c = 0.0, bool d = false) { return 1;} alias namedParams!foo nfoo; nfoo(d, true); // a = 0, b = 1, c = 0.0, d = true nfoo(d, true, b, 100); // a=0, b=100, c=0.0, d=true

Re: Function with default parameters

2010-09-18 Thread Simen kjaeraas
Philippe Sigaud philippe.sig...@gmail.com wrote: It seems doable to have some kind of function transformer (adaptor?) for this. from: int foo(int a = 0, int b = 1, double c = 0.0, bool d = false) { return 1;} alias namedParams!foo nfoo; nfoo(d, true); // a = 0, b = 1, c = 0.0, d = true

Re: Function with default parameters

2010-09-18 Thread Philippe Sigaud
My main problem with these solutions is that they're largely runtime solutions. Not that calling a function with named parameters is very likely to happen in an inner loop, now I think of it... I imagined the foo(b, 100, d, true) version to be largely CT: variadic list, testing and

Re: Garbage Collection, Allocators/Deallocators and

2010-09-18 Thread Ivo Kasiuk
Exploring the example a bit further: If C's malloc is used instead of GC.malloc then the deallocators also are not called and the program runs out of memory. How are the objects supposed to get finalized in this case - do I have to use the delete keyword explicitly? If you use C's

Re: Error: cannot implicitly convert expression (this) of type const(S) to S

2010-09-18 Thread Jonathan M Davis
On Saturday 18 September 2010 06:45:51 Ivo Kasiuk wrote: Am Samstag, den 18.09.2010, 02:15 -0700 schrieb Jonathan M Davis: Okay, if I try and compile the following program. struct S { @property S save() const { return this; }

Re: Garbage Collection, Allocators/Deallocators and

2010-09-18 Thread Simen kjaeraas
Ivo Kasiuk i.kas...@gmx.de wrote: Exploring the example a bit further: If C's malloc is used instead of GC.malloc then the deallocators also are not called and the program runs out of memory. How are the objects supposed to get finalized in this case - do I have to use the delete keyword

Re: FIle I/O

2010-09-18 Thread Jonathan M Davis
On Saturday 18 September 2010 08:50:41 Graham Nicholls wrote: Thanks. I figured that it was a duplicate definition, but not if I leave out st.stream, then OpenException is undefined. Is there a documentation for the exceptions which are in the relevant packages - I'll struggle without it!

Purity with references and pointers

2010-09-18 Thread Jonathan M Davis
If a pure function takes a reference/pointer, does that state that the result of the function will be the same on two calls to it if the reference/pointer points to the same data in both cases or if the data itself is unchanged? If it's a matter of pointing to the same data, then that could

Re: Purity with references and pointers

2010-09-18 Thread Simen kjaeraas
Jonathan M Davis jmdavisp...@gmx.com wrote: If a pure function takes a reference/pointer, does that state that the result of the function will be the same on two calls to it if the reference/pointer points to the same data in both cases or if the data itself is unchanged? If it's a matter

Re: Purity with references and pointers

2010-09-18 Thread Jonathan M Davis
On Saturday 18 September 2010 17:33:21 Simen kjaeraas wrote: Jonathan M Davis jmdavisp...@gmx.com wrote: If a pure function takes a reference/pointer, does that state that the result of the function will be the same on two calls to it if the reference/pointer points to the same data in

Re: Purity with references and pointers

2010-09-18 Thread Jonathan M Davis
On Saturday 18 September 2010 18:16:31 Jonathan M Davis wrote: I don't think that *anything* is implicitly convertable to immutable. const yes, but not immutable Actually, I guess that value types are implicitly convertible to immutable in the sense that you can create a new immutable value

Re: Purity with references and pointers

2010-09-18 Thread Simen kjaeraas
Jonathan M Davis jmdavisp...@gmx.com wrote: Except that since when is anything implictly convertable to immutable? Implicitly converted to const, yes. That happens often enough, but immutable? Anything that does not contain pointers or references to non-immutable data is implicitly

Re: Applying a tuple to a function (and more)

2010-09-18 Thread Juanjo Alvarez
Philippe Sigaud wrote: 1. Having the strings, defined at compile time, MyClass and mymethod, how could I could I get to a delegate to MyClass.mymethod? You can insert them in a piece of code as a string, and then mix it in: enum string code = auto deleg = ~ className ~ . ~ methodName ~

Copying a delegate

2010-09-18 Thread Jonathan M Davis
Is it in any way possible to copy a delegate? Take this program for example: import std.stdio; void main() { int a = 0; int func() { return a++; } int delegate() b = func; int delegate() c = b; writeln(b()); writeln(c()); writeln(b()); } It will

Re: Applying a tuple to a function (and more)

2010-09-18 Thread Philippe Sigaud
On Sun, Sep 19, 2010 at 03:43, Juanjo Alvarez juan...@gmail.com wrote: enum string code = auto deleg = ~ className ~ . ~ methodName ~ ;; // auto deleg = MyClass.mymethod; mixin(code); // created deleg, you're good to go. I tried it and worked like a charm (but I've changed my code so