Re: Adding overloaded methods

2012-02-21 Thread Jonathan M Davis
On Wednesday, February 22, 2012 08:19:09 Jacob Carlborg wrote: > He is overloading, not overriding. You have to start notice the > difference when reading these posts :) Well, it's both. He's overriding a base class function with a different signature. So, depending on how the compiler treats tha

Re: Adding overloaded methods

2012-02-21 Thread Jacob Carlborg
On 2012-02-22 03:39, Jonathan M Davis wrote: On Wednesday, February 22, 2012 02:21:43 BLM wrote: I'm working on a project where I'm using overloaded virtual methods, and I've run into a challenge with overload sets. My code looks something like this: class Base { void get(ubyte b) {}; } class

Re: inout problems

2012-02-21 Thread Andrej Mitrovic
Hmm nevermind. The param type had to be inout, but to do that the ctor itself has to be inout. Somehow I managed to put the inout specifier in the wrong place when testing, I did this: this(inout(void*) obj) { } inout which is not the same as this: this(inout(void*) obj) inout { } Damn specs. A

Re: Avoiding const?

2012-02-21 Thread Ali Çehreli
On 02/21/2012 07:42 PM, ixid wrote: > Ranges are a bit of a mystery. May I shamelessly recommend the Ranges chapter of my about-30%-translated book: http://ddili.org/ders/d.en/ranges.html > I'm a little worried that the very basic level of my posts is spamming > the forum Not at all! We a

Re: inout problems

2012-02-21 Thread James Miller
On 22 February 2012 17:01, Andrej Mitrovic wrote: > class Foo > { >    this(int) inout >    { } > >    Foo makeFoo() { return new Foo(1); } > } > > void main() { } > > test.d(8): Error: cannot implicitly convert expression (new Foo(1)) of > type inout(Foo) to test.Foo > > Is this a bug? I have no

Re: Avoiding const?

2012-02-21 Thread Jonathan M Davis
On Wednesday, February 22, 2012 04:42:05 ixid wrote: > Thank you, I'll read those articles. Is there a more elegant way > than this to get the string[] out of a range after using the > algorithms sort? Ranges are a bit of a mystery. > > string[] temp; > foreach(i;sort(set.keys)) >

Re: Adding overloaded methods

2012-02-21 Thread BLM
Hmm... I guess I'll have to figure out why my code is behaving differently and put a test case together. Strange... Thanks for fixing the semicolons. Old C++ habits die hard, even if one has written very little C++ :)

inout problems

2012-02-21 Thread Andrej Mitrovic
class Foo { this(int) inout { } Foo makeFoo() { return new Foo(1); } } void main() { } test.d(8): Error: cannot implicitly convert expression (new Foo(1)) of type inout(Foo) to test.Foo Is this a bug?

Re: Avoiding const?

2012-02-21 Thread ixid
Thank you, I'll read those articles. Is there a more elegant way than this to get the string[] out of a range after using the algorithms sort? Ranges are a bit of a mystery. string[] temp; foreach(i;sort(set.keys)) temp ~= to!string(i); I'm a little worried that

Re: Adding overloaded methods

2012-02-21 Thread BLM
I've submitted it to the DMD developers. Hopefully it won't take too long to get fixed; it looks like it would be a _fairly_ simple fix to make. (Since when is a compiler fix simple?)

Re: Adding overloaded methods

2012-02-21 Thread Ali Çehreli
On 02/21/2012 06:21 PM, BLM wrote: I'm working on a project where I'm using overloaded virtual methods, and I've run into a challenge with overload sets. My code looks something like this: class Base { void get(ubyte b) {}; } class Derived: Base { //alias Base.get get; void get(string s)

Re: Adding overloaded methods

2012-02-21 Thread Jonathan M Davis
On Wednesday, February 22, 2012 02:50:41 BLM wrote: > I tried using override and it complained that the functions weren't > overriding anything. I think that the main problem is that the alias > solution was designed to allow derived classes to use overloads that had > already been defined in the b

Re: delegate as memeber

2012-02-21 Thread Vladimir Panteleev
On Tuesday, 21 February 2012 at 15:41:58 UTC, deadalnix wrote: Le 21/02/2012 16:32, Vladimir Panteleev a écrit : On Tuesday, 21 February 2012 at 15:22:15 UTC, deadalnix wrote: struct stuff { private Exception delegate() exceptionBuilder = delegate Exception() { return new Exception("foobar");

Re: Adding overloaded methods

2012-02-21 Thread BLM
I tried using override and it complained that the functions weren't overriding anything. I think that the main problem is that the alias solution was designed to allow derived classes to use overloads that had already been defined in the base class, not for the derived classes to add _new_ overloa

Re: Adding overloaded methods

2012-02-21 Thread Jonathan M Davis
On Wednesday, February 22, 2012 02:21:43 BLM wrote: > I'm working on a project where I'm using overloaded virtual methods, and > I've run into a challenge with overload sets. > > My code looks something like this: > > class Base { > void get(ubyte b) {}; > } > > class Derived: Base { > //alias B

Re: Avoiding const?

2012-02-21 Thread Jonathan M Davis
On Wednesday, February 22, 2012 03:07:38 ixid wrote: > BLM: > const(char)[][] words = set.keys.sort; > > Converting the function's return type to const and doing this did > what I wanted elegantly, I didn't realise I could apply sort to a > const like this. > > Trying to use .dup like this: > >

Adding overloaded methods

2012-02-21 Thread BLM
I'm working on a project where I'm using overloaded virtual methods, and I've run into a challenge with overload sets. My code looks something like this: class Base { void get(ubyte b) {}; } class Derived: Base { //alias Base.get get; void get(string s) {}; } I've tried using an alias declar

Re: Avoiding const?

2012-02-21 Thread ixid
BLM: const(char)[][] words = set.keys.sort; Converting the function's return type to const and doing this did what I wanted elegantly, I didn't realise I could apply sort to a const like this. Trying to use .dup like this: char[][] words = set.keys.dup; gives this error mess

Re: Avoiding const?

2012-02-21 Thread Jonathan M Davis
On Wednesday, February 22, 2012 01:25:12 BLM wrote: > If you have a const array, you can create a non-const copy of the array > using the .dup property of the array. The reason that you need this is that > dynamic-length arrays share data when you assign them between variables, > and you can't have

Re: Avoiding const?

2012-02-21 Thread BLM
If you have a const array, you can create a non-const copy of the array using the .dup property of the array. The reason that you need this is that dynamic-length arrays share data when you assign them between variables, and you can't have a non-const variable using something else's const data wit

Re: std.regex named matches

2012-02-21 Thread James Miller
On 22 February 2012 04:45, Dmitry Olshansky wrote: > On 21.02.2012 7:34, James Miller wrote: >> >> On 20 February 2012 21:34, Dmitry Olshansky  wrote: >>> >>> 08.02.2012 13:07, James Miller пишет: >>> Hi, I am using std.regex and using the named matches. I would like to be

Avoiding const?

2012-02-21 Thread ixid
I apologize for what I'm sure is a very basic question. How should I do this elegantly? bool set[char[]]; //Stuff char[][] words = set.keys; It gives the error: Error: cannot implicitly convert expression (set.keys()) of type const(char)[][] to char[][] and I'm not sur

Re: Template Inheritance

2012-02-21 Thread BLM
That last one looks a lot better than my solution. It's certainly a lot clearer. One problem I discovered with using templates was that I ended up needing virtual functions, which means that I had to convert the template functions to mixins and just instantiate them for each type (at least there

Re: mixin template FAIL

2012-02-21 Thread Ellery Newcomer
On 02/21/2012 01:53 PM, Ali Çehreli wrote: According to the docs, template mixins can have only declarations but helpMe above has a statement. http://dlang.org/template-mixin.html Ali come to think of it, I've occasionally wished for statement mixins. This would make a good enhancement req

Re: mixin template FAIL

2012-02-21 Thread Jacob Carlborg
On 2012-02-21 20:53, Ali Çehreli wrote: On 02/21/2012 10:47 AM, Zach the Mystic wrote: > I decided to try using template mixin, but even the simplest program > fails. What's wrong with this code? Error list follows. > DMD64 D Compiler v2.057 OSX 10.6 > > import std.stdio; > > mixin templat

Re: delegate as memeber

2012-02-21 Thread H. S. Teoh
On Tue, Feb 21, 2012 at 08:01:18PM +0100, deadalnix wrote: [...] > But still I think the original code should be an error only if it > use data out of the delegate scope. If it doesn't, frame pointer > doesn't matter and null can be passed. You could file an enhancement request, if one hasn't alre

Re: Mixins: Using the type name to generate a method name

2012-02-21 Thread Robert Rouse
stringof did it. I'm still reading through the D programming book, so I guess I hadn't gotten there yet. I did a search in the book and found a reference. I'll read more. Thanks :) On Tuesday, 21 February 2012 at 19:48:18 UTC, Adam D. Ruppe wrote: On Tuesday, 21 February 2012 at 19:42:42 UTC

Re: mixin template FAIL

2012-02-21 Thread Ali Çehreli
On 02/21/2012 10:47 AM, Zach the Mystic wrote: > I decided to try using template mixin, but even the simplest program > fails. What's wrong with this code? Error list follows. > DMD64 D Compiler v2.057 OSX 10.6 > > import std.stdio; > > mixin template helpMe() > { > writeln("Satisfying!"); > } > >

Re: Mixins: Using the type name to generate a method name

2012-02-21 Thread Mantis
21.02.2012 21:42, Robert Rouse пишет: ... mixin("alias _method " ~ toLower(typeid(T)) ~ ";" ); ... Try typeid(T).toString(); or typeof(T).stringof; typeid does not return a string type.

Re: Mixins: Using the type name to generate a method name

2012-02-21 Thread Adam D. Ruppe
On Tuesday, 21 February 2012 at 19:42:42 UTC, Robert Rouse wrote: mixin("alias _method " ~ toLower(typeid(T)) ~ ";" ); Try using T.stringof instead of typeid(T). typeid does a runtime lookup. T.stringof does magic to get a string representation of the thing at compile time. Since, in th

Mixins: Using the type name to generate a method name

2012-02-21 Thread Robert Rouse
Piggy backing on my other question. I want to be able to make the name of the method optional in the argument list. If it doesn't exist, it should get the type name of the passed in type and lower case it and use it instead. I tried the following import std.stdio, std.string; mixin templat

Re: delegate as memeber

2012-02-21 Thread deadalnix
Le 21/02/2012 17:30, Mantis a écrit : 21.02.2012 17:24, deadalnix пишет: struct stuff { private Exception delegate() exceptionBuilder = delegate Exception() { return new Exception("foobar"); }; } The following piece of code trigger a compiler error : delegate module.stuff.__dgliteral1 function

mixin template FAIL

2012-02-21 Thread Zach the Mystic
I decided to try using template mixin, but even the simplest program fails. What's wrong with this code? Error list follows. DMD64 D Compiler v2.057 OSX 10.6 import std.stdio; mixin template helpMe() { writeln("Satisfying!"); } void main() { mixin helpMe(); } test.d(5): unexpected ( in

Re: Problems linking libdl?

2012-02-21 Thread Mike Wey
On 02/20/2012 10:33 PM, simendsjo wrote: On Mon, 20 Feb 2012 22:26:58 +0100, Mike Wey wrote: On 02/20/2012 09:49 PM, simendsjo wrote: On Mon, 20 Feb 2012 21:41:45 +0100, simendsjo wrote: I've tried the following using dmd 58 and trunk - both -m64 on kubuntu. Any idea what I'm doing wrong?

Re: Naming methods from strings using mixin

2012-02-21 Thread Robert Rouse
Nevermind.. I had it as struct playing around and didn't change it back On Tuesday, 21 February 2012 at 18:37:02 UTC, Robert Rouse wrote: I did not. Trying to new it gives me a compile error since "MyClass a" is not a pointer. If I define another method without mixin and call it before the

Re: Naming methods from strings using mixin

2012-02-21 Thread Robert Rouse
I did not. Trying to new it gives me a compile error since "MyClass a" is not a pointer. If I define another method without mixin and call it before the "mixin" one, it works. On Tuesday, 21 February 2012 at 18:13:30 UTC, Adam D. Ruppe wrote: On Tuesday, 21 February 2012 at 18:07:34 UTC, R

Re: Naming methods from strings using mixin

2012-02-21 Thread Adam D. Ruppe
On Tuesday, 21 February 2012 at 18:07:34 UTC, Robert Rouse wrote: What am I missing? Did you remember to new the class? class MyClass {} MyClass a; // a is null right now a = new MyClass(); // gotta remember this That's different than structs (or classes in C++) which work without being ne

Re: Naming methods from strings using mixin

2012-02-21 Thread Robert Rouse
Hello again, Both methods work as long as the object I call the mixin within is a struct struct Test { mixin MakeMethod!("bark"); } If I switch struct to class class Test { mixin MakeMethod!("bark"); } it segfaults. What am I missing? On Tuesday, 21 February 2012 at 15:29:49 UTC, Vl

Re: interface final members

2012-02-21 Thread Ali Çehreli
On 02/21/2012 09:58 AM, Ali Çehreli wrote: The reason that I think so is that when the 'I other' is moved to a parameter location other than the first one, it works: No, it doesn't work. Sorry for the noise. Ali

Re: interface final members

2012-02-21 Thread Ali Çehreli
On 02/21/2012 04:46 AM, Joshua Reusch wrote: interface I { final int foo(I other, int a, int b) { return other.foo(a,b) + a*b; } int foo(int a, int b); } class A : I { int foo(int a, int b) { return a*b; } } void main() { A a = new A; a.foo(5,5); a.I.foo(a, 5,5); a.foo(a, 5,5); //line 22 } ---

Re: Naming methods from strings using mixin

2012-02-21 Thread Robert Rouse
Awesome. Thanks! Adam D. Ruppe wrote: On Tuesday, 21 February 2012 at 14:53:06 UTC, Robert Rouse wrote: Using a mixin, is it possible to have it define a method based on a string passed into the mixin? Yeah, though you'll have to build a string of the method. Something like this: string

Re: delegate as memeber

2012-02-21 Thread Jacob Carlborg
On 2012-02-21 16:55, deadalnix wrote: Le 21/02/2012 16:48, Adam D. Ruppe a écrit : A possible workaround is to initialize the delegate in the object's constructor. It is a struct. And struct don't have default constructor. It lead to very segfault prone code (I did try that). You can impleme

Re: interface final members

2012-02-21 Thread Jacob Carlborg
On 2012-02-21 14:15, Mantis wrote: 21.02.2012 14:46, Joshua Reusch пишет: interface I { final int foo(I other, int a, int b) { return other.foo(a,b) + a*b; } int foo(int a, int b); } class A : I { int foo(int a, int b) { return a*b; } } void main() { A a = new A; a.foo(5,5); a.I.foo(a, 5,5);

Re: Executable size when compiling with GDC

2012-02-21 Thread Trass3r
Lots of symbols and stuff. You can get it down with -ffunction-sections -fdata-sections -Wl,-s,--gc-sections Phobos should also be compiled with -ffunction-sections -fdata-sections to get the whole effect though.

Re: Compress spaces to one space

2012-02-21 Thread Andrej Mitrovic
On 2/21/12, bearophile wrote: > Andrej Mitrovic: > >> Is there a Phobos function to compress all spaces to just one space in a >> string? >> >> E.g. " foo bar " >> becomes: " foo bar " > > import std.string; > void main() { > assert(" foo bar ".squeeze() == " fo bar

Re: Examples of Windows services in D?

2012-02-21 Thread Graham Fawcett
On Tue, 21 Feb 2012 17:35:34 +0100, Andrej Mitrovic wrote: > N, it wasn't me. I keep having to tell this to people, it was taken > from http://www.dsource.org/projects/bindings/wiki/WindowsApi but it > often doesn't compile with the latest compiler version so I keep it > updated inside my proj

Re: Examples of Windows services in D?

2012-02-21 Thread Andrej Mitrovic
N, it wasn't me. I keep having to tell this to people, it was taken from http://www.dsource.org/projects/bindings/wiki/WindowsApi but it often doesn't compile with the latest compiler version so I keep it updated inside my project.

Re: delegate as memeber

2012-02-21 Thread Mantis
21.02.2012 17:24, deadalnix пишет: struct stuff { private Exception delegate() exceptionBuilder = delegate Exception() { return new Exception("foobar"); }; } The following piece of code trigger a compiler error : delegate module.stuff.__dgliteral1 function literals cannot be class members Why

Re: delegate as memeber

2012-02-21 Thread deadalnix
Le 21/02/2012 16:48, Adam D. Ruppe a écrit : A possible workaround is to initialize the delegate in the object's constructor. It is a struct. And struct don't have default constructor. It lead to very segfault prone code (I did try that).

Re: delegate as memeber

2012-02-21 Thread Adam D. Ruppe
A possible workaround is to initialize the delegate in the object's constructor.

Re: std.regex named matches

2012-02-21 Thread Dmitry Olshansky
On 21.02.2012 7:34, James Miller wrote: On 20 February 2012 21:34, Dmitry Olshansky wrote: 08.02.2012 13:07, James Miller пишет: Hi, I am using std.regex and using the named matches. I would like to be able to get at the names that have matched, since this is library code. e.g. auto m

Re: delegate as memeber

2012-02-21 Thread deadalnix
Le 21/02/2012 16:32, Vladimir Panteleev a écrit : On Tuesday, 21 February 2012 at 15:22:15 UTC, deadalnix wrote: struct stuff { private Exception delegate() exceptionBuilder = delegate Exception() { return new Exception("foobar"); }; } The following piece of code trigger a compiler error : dele

Re: Executable size when compiling with GDC

2012-02-21 Thread Mars
On Tuesday, 21 February 2012 at 13:19:11 UTC, Andrea Fontana wrote: Have you tried to strip executable using --strip or --strip-all? Down to 1 MB, a good start, thanks. I guess that's more bearable.

Re: delegate as memeber

2012-02-21 Thread Vladimir Panteleev
On Tuesday, 21 February 2012 at 15:22:15 UTC, deadalnix wrote: struct stuff { private Exception delegate() exceptionBuilder = delegate Exception() { return new Exception("foobar"); }; } The following piece of code trigger a compiler error : delegate module.stuff.__dgl

Re: Naming methods from strings using mixin

2012-02-21 Thread Vladimir Panteleev
On Tuesday, 21 February 2012 at 14:53:06 UTC, Robert Rouse wrote: Using a mixin, is it possible to have it define a method based on a string passed into the mixin? A simpler way: mixin template MakeMethod(string name) { void _MakeMethod_method() { /* ... */ } mixin("alias _Make

delegate as memeber

2012-02-21 Thread deadalnix
struct stuff { private Exception delegate() exceptionBuilder = delegate Exception() { return new Exception("foobar"); }; } The following piece of code trigger a compiler error : delegate module.stuff.__dgliteral1 function literals cannot be class members Why is

Examples of Windows services in D?

2012-02-21 Thread Graham Fawcett
Hi folks, I've got a Windows service that I'd like to write in D, if possible. I see that Andrej Mitrovic has provided a binding for the relevant parts of the Windows API (thanks!): https://github.com/AndrejMitrovic/DWinProgramming/blob/master/win32/ winsvc.d Has anyone used this (or another b

Re: Naming methods from strings using mixin

2012-02-21 Thread Adam D. Ruppe
On Tuesday, 21 February 2012 at 14:53:06 UTC, Robert Rouse wrote: Using a mixin, is it possible to have it define a method based on a string passed into the mixin? Yeah, though you'll have to build a string of the method. Something like this: string make_method_string(string name) { strin

Naming methods from strings using mixin

2012-02-21 Thread Robert Rouse
Using a mixin, is it possible to have it define a method based on a string passed into the mixin? An example of what I'm hoping to do: mixin template make_method(string name) { void name() { // not sure how to make it become "void bark()" here writeln("hello"); } } class Ani

Re: Executable size when compiling with GDC

2012-02-21 Thread Andrea Fontana
Have you tried to strip executable using --strip or --strip-all? Il giorno mar, 21/02/2012 alle 13.51 +0100, Mars ha scritto: > Hello everybody. > > Today I've tested GDC (on Windows), and a simple Hello World > program results in a 5 MB exe file, while it's only about 200 KB > with DMD. Is

Re: Compress spaces to one space

2012-02-21 Thread Andrej Mitrovic
Oh cool, it even takes an optional parameter. Thanks! On 2/21/12, bearophile wrote: > Andrej Mitrovic: > >> Is there a Phobos function to compress all spaces to just one space in a >> string? >> >> E.g. " foo bar " >> becomes: " foo bar " > > import std.string; > void main() { >

Re: interface final members

2012-02-21 Thread Mantis
21.02.2012 14:46, Joshua Reusch пишет: interface I { final int foo(I other, int a, int b) { return other.foo(a,b) + a*b; } int foo(int a, int b); } class A : I { int foo(int a, int b) { return a*b; } } void main() { A a = new A; a.foo(5,5); a.I.foo(a, 5,5); a.foo(a, 5,5); //line 22 } -

Executable size when compiling with GDC

2012-02-21 Thread Mars
Hello everybody. Today I've tested GDC (on Windows), and a simple Hello World program results in a 5 MB exe file, while it's only about 200 KB with DMD. Is this normal? What does GDC (GCC?) put in there, to make it so big, and why? Mars

interface final members

2012-02-21 Thread Joshua Reusch
interface I { final int foo(I other, int a, int b) { return other.foo(a,b) + a*b; } int foo(int a, int b); } class A : I { int foo(int a, int b) { return a*b; } } void main() { A a = new A; a.foo(5,5);

Re: Everything on the Stack

2012-02-21 Thread bearophile
Don Clugston: > Does the library solution actually work the same as the language solution? Some time ago scoped worked worse than the built-in scope: http://d.puremagic.com/issues/show_bug.cgi?id=5115 But I don't know how well scoped works now, I have never used it any more. Bye, bearophile

Re: Compress spaces to one space

2012-02-21 Thread bearophile
Andrej Mitrovic: > Is there a Phobos function to compress all spaces to just one space in a > string? > > E.g. " foo bar " > becomes: " foo bar " import std.string; void main() { assert(" foo bar ".squeeze() == " fo bar "); } Bye, bearophile

Re: Everything on the Stack

2012-02-21 Thread Don Clugston
On 21/02/12 12:12, Timon Gehr wrote: On 02/21/2012 11:27 AM, Daniel Murphy wrote: scope/scoped isn't broken, they're just not safe. It's better to have an unsafe library feature than an unsafe language feature. scope is broken because it is not enforced by the means of flow-analysis. As a re

Re: Everything on the Stack

2012-02-21 Thread Timon Gehr
On 02/21/2012 11:27 AM, Daniel Murphy wrote: scope/scoped isn't broken, they're just not safe. It's better to have an unsafe library feature than an unsafe language feature. scope is broken because it is not enforced by the means of flow-analysis. As a result, it is not safe. Copying it to

Compress spaces to one space

2012-02-21 Thread Andrej Mitrovic
Is there a Phobos function to compress all spaces to just one space in a string? E.g. " foo bar " becomes: " foo bar "

Re: Everything on the Stack

2012-02-21 Thread Daniel Murphy
scope/scoped isn't broken, they're just not safe. It's better to have an unsafe library feature than an unsafe language feature.