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 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 inste

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 p

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 ~

Re: Purity with references and pointers

2010-09-18 Thread Simen kjaeraas
Jonathan M Davis 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 convertible to immutable, if

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 f

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 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 case

Re: Purity with references and pointers

2010-09-18 Thread Simen kjaeraas
Jonathan M Davis 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 of pointing to the s

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 be

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!

Re: Garbage Collection, Allocators/Deallocators and

2010-09-18 Thread Simen kjaeraas
Ivo Kasiuk 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 explicitly?

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: Error: cannot implicitly convert expression (this) of type const(S) to S

2010-09-18 Thread Jonathan M Davis
On Saturday 18 September 2010 09:58:15 Steven Schveighoffer wrote: > On Sat, 18 Sep 2010 05:15:38 -0400, Jonathan M Davis > > wrote: > > 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 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

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: Function with default parameters

2010-09-18 Thread Simen kjaeraas
Philippe Sigaud 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 nfoo("d", true, "b", 100)

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: Applying a tuple to a function (and more)

2010-09-18 Thread Philippe Sigaud
On Sat, Sep 18, 2010 at 19:59, Juanjo Alvarez 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 them in a

Re: Garbage Collection, Allocators/Deallocators and

2010-09-18 Thread Simen kjaeraas
Ivo Kasiuk 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 C1, I have no ide

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

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("

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 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 implicitly convert expre

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: 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 a

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(i

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 simp

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; str

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.

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 oth

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 save()

pure member functions

2010-09-18 Thread Jonathan M Davis
I assume that if you declare a member function as pure, then all of its parameters - including the invisible this - are included in that. That is, if all of them - including the invisible this - have the same value, then the result will be the same. I'm not quite sure way (perhaps because pure