new A().b() currently requires extra brackets/parentheses

2012-09-09 Thread Ben Davis
Hi, I'm trying to define an API in D where an object can be instantiated and then set up inline. I have various methods that return 'this' so that they can be used inline in this way. For example: dialogue=new GuiDialogue([ (new GuiLabel(titleText)).setLayoutHint(GuiLayoutHint.TOP),

Re: new A().b() currently requires extra brackets/parentheses

2012-09-09 Thread Ben Davis
Hi, On 09/09/2012 14:23, Philippe Sigaud wrote: > you could use factory functions: > > class A {} > > A a() { return new A();} Good idea. It might not work so well for me because the user might also be creating custom GUI components and would therefore have to create their own factory function

Re: new A().b() currently requires extra brackets/parentheses

2012-09-09 Thread Ben Davis
On 09/09/2012 14:28, Timon Gehr wrote: I think so. Probably it is just a bug. (the spec does not indicate that it is illegal iirc.) Maybe you can even fix it yourself, the parser should be quite hackable. That's good to hear - but since I'm only using D for a project outside of work, and have

SpanMode uses incorrect terminology (breadth)

2012-09-16 Thread Ben Davis
According to http://dlang.org/phobos/std_file.html : depth Spans the directory depth-first, i.e. the content of any subdirectory is spanned before that subdirectory itself. Useful e.g. when recursively deleting files. breadth Spans the directory breadth-first, i.e. the content of any subdirec

Regression in 2.060 - corruption when lambda closes over foreach variable

2012-09-16 Thread Ben Davis
Hi, I have some code which has started breaking as of 2.060. I've simplified it down to the following: import std.stdio; void main() { broken(); reffix(); noclosefix(); } void broken() { foreach (z; 0..1) { writeln(z); //Corru

Re: Regression in 2.060 - corruption when lambda closes over foreach variable

2012-09-16 Thread Ben Davis
Sorry, the second "I'm compiling with" is a lie. (Edited it out below.) On 17/09/2012 00:16, Ben Davis wrote: Hi, I have some code which has started breaking as of 2.060. I've simplified it down to the following: import std.stdio; void main() { b

Re: SpanMode uses incorrect terminology (breadth)

2012-09-17 Thread Ben Davis
I have a feeling most people have missed the point here. Thanks for the example - it's a good one to work with. The 'expected approximation' was a bit of a mix of traversal strategies, so I've snipped it out below and put my own examples. Hope this helps clarify what I was getting at: On 17/09

Re: SpanMode uses incorrect terminology (breadth)

2012-09-17 Thread Ben Davis
On 17/09/2012 19:15, Dmitry Olshansky wrote: On 17-Sep-12 09:30, Jesse Phillips wrote: > >> What would be an example illustrating that "breadth" is doing the >> wrong thing? >> >> Andrei > Shouldn't be hard to add "true" breadth first then. Since it's a stack based visitation one just nee

Re: SpanMode uses incorrect terminology (breadth)

2012-09-17 Thread Ben Davis
On 17/09/2012 19:47, Jesse Phillips wrote: On Monday, 17 September 2012 at 18:20:55 UTC, Andrei Alexandrescu wrote: Thanks, that does seem to be a bug. Please make sure it's in bugzilla. Probably the best way to go is to adjust the behavior so it matches the specification. Andrei I should ha

Re: Regression in 2.060 - corruption when lambda closes over foreach variable

2012-09-17 Thread Ben Davis
On 17/09/2012 07:02, Nick Sabalausky wrote: You should probably file that here: http://d.puremagic.com/issues/ Done :) These two already existed: http://d.puremagic.com/issues/show_bug.cgi?id=8621 <-- posted here http://d.puremagic.com/issues/show_bug.cgi?id=8526 I guess they're probably du

Re: reference to 'self' inside a function

2012-09-18 Thread Ben Davis
Wild stab in the dark, but would something like this work: void myfunction() { int dummy; auto self = __traits(parent, dummy); } though it would be better if something like __traits(enclosing) were supported. On 18/09/2012 20:22, Rob T wrote: I was just about to make this pro

Re: SpanMode uses incorrect terminology (breadth)

2012-09-18 Thread Ben Davis
On 18/09/2012 15:25, David Piepgrass wrote: Breadth-first (probably never required): a/b a/c a/1.txt a/2.txt a/b/1.txt a/b/2.txt a/c/z a/c/1.txt a/c/z/1.txt Defining property: number of /'s increases monotonically. Note how the deeper you go, the more spread out the children become. It's ALL chil

Re: reference to 'self' inside a function

2012-09-18 Thread Ben Davis
Or indeed auto self = __traits(parent, self); Grin :) On 18/09/2012 20:57, Ben Davis wrote: Wild stab in the dark, but would something like this work: void myfunction() { int dummy; auto self = __traits(parent, dummy); } though it would be better if something like __traits

Re: SpanMode uses incorrect terminology (breadth)

2012-09-18 Thread Ben Davis
On 18/09/2012 21:08, Ben Davis wrote: On 18/09/2012 15:25, David Piepgrass wrote: Breadth-first (probably never required): a/b a/c a/1.txt a/2.txt a/b/1.txt a/b/2.txt a/c/z a/c/1.txt a/c/z/1.txt Defining property: number of /'s increases monotonically. Note how the deeper you go, the

Re: SpanMode uses incorrect terminology (breadth)

2012-09-18 Thread Ben Davis
Another thing worth mentioning occurred to me today. Whoever implements breadth-first - don't get caught out by symlinks. For the depth-first variants, you can just detect them by looking in the stack. For the breadth-first, you won't be able to detect them by looking in the queue that replace

Re: built-in array ptrEnd

2012-09-18 Thread Ben Davis
On 18/09/2012 21:10, Nick Sabalausky wrote: On Tue, 18 Sep 2012 15:43:37 +0200 "monarch_dodra" wrote: On Tuesday, 18 September 2012 at 12:06:15 UTC, Steven Schveighoffer wrote: There is another reason to avoid this. Note that if I have two consecutive blocks of memory: 0...4 and 4...8 If

Re: reference to 'self' inside a function

2012-09-18 Thread Ben Davis
On 18/09/2012 22:21, Rob T wrote: On Tuesday, 18 September 2012 at 19:57:05 UTC, Ben Davis wrote: Wild stab in the dark, but would something like this work: void myfunction() { int dummy; auto self = __traits(parent, dummy); } though it would be better if something like __traits

Re: reference to 'self' inside a function

2012-09-22 Thread Ben Davis
On 19/09/2012 08:24, Jacob Carlborg wrote: On 2012-09-19 01:21, Rob T wrote: Actually I find the __traits system a bit convoluted and inconsistent with other similar features. There seems to be a real need to unify the different methods of reflection in D. For example, I can do this without usi

Re: reference to 'self' inside a function

2012-09-23 Thread Ben Davis
Here's another one that might work, and be less error-prone: mixin template Self() { auto self = __traits(identifier, __traits(parent, {})); } void test() { mixin Self; writeln(self); } On 23/09/2012 09:58, Rob T wrote: string scopeName() { return q{__traits(identifier, __traits(pare

Re: reference to 'self' inside a function

2012-09-23 Thread Ben Davis
On 23/09/2012 20:58, Philippe Sigaud wrote: On Sun, Sep 23, 2012 at 7:16 PM, Ben Davis wrote: Here's another one that might work, and be less error-prone: mixin template Self() { auto self = __traits(identifier, __traits(parent, {})); } void test() { mixin Self; writeln

Re: Ch-ch-changes

2012-09-25 Thread Ben Davis
Seems like as good a time as any to say how awesome I think D is, and how much the world needs it! Where I work, we have a monstrosity of a project using all of Java, C++ and Lua, with all three interoperating in all directions. We've been asked to write all new code in C++ for reasons of porta

Re: Should this be flagged as a warning?

2012-09-26 Thread Ben Davis
On 26/09/2012 10:45, Don Clugston wrote: On 25/09/12 21:30, Bernard Helyer wrote: I tried to post this last night, but the NG wasn't having any of it. I found myself writing a bug that looked like this match(ts, TokenType.Is); match(ts, TokenType.OpenParen); isExp.type == parseT

Re: I have a feature request: "Named enum scope inference"

2012-09-29 Thread Ben Davis
On 29/09/2012 04:11, Andrej Mitrovic wrote: On 9/29/12, David Piepgrass wrote: I like the spirit of this feature, but as Alex pointed out, ambiguity is possible (which could theoretically cause errors in existing code) It could also cause subtle problems because enum values are implicitly con

Re: DMD 2.060

2012-10-08 Thread Ben Davis
On 07/10/2012 11:39, Walter Bright wrote: On 10/7/2012 3:12 AM, Alex Rønne Petersen wrote: On 07-10-2012 11:11, Russel Winder wrote: Any news on the "regressions" relating to threads in the 2.059 → 2.060 change? Is a 2.061 with fixes pending? I'm still not clear on what these regressions are?

Re: Will the D GC be awesome?

2012-10-08 Thread Ben Davis
On 06/10/2012 04:03, Chad J wrote: Try to do array slicing in Java or C#. You probably won't be able to do it. You'll get string /copies/ and this will incur heap allocations in the GC heap. Those languages /need/ good garbage collection to be performant because they abuse the poor GC heavily.

Ref local variables?

2012-01-10 Thread Ben Davis
Hi, Please excuse the cross-post with D.learn. People have been helpful there with workarounds, but I'm bringing it here in the hope that we can discuss a language enhancement. So - could support for 'ref' local variables be added, or is there a reason not to? I want to write something like:

Re: Ref local variables?

2012-01-11 Thread Ben Davis
Jan 11, 2012 at 8:16 AM, Robert Jacques wrote: On Tue, 10 Jan 2012 21:55:53 -0600, Nick Sabalausky wrote: "Ben Davis" wrote in message news:jeinah$2pnj$1...@digitalmars.com... Hi, Please excuse the cross-post with D.learn. People have been helpful there with workarounds, but I

When are associative arrays meant to throw a RangeError?

2012-02-17 Thread Ben Davis
I can't easily see what the rules are. Specifically, I'm finding: Chunk[][char[4]] chunks; //chunks["DATA"] is an array of Chunk objects, where Chunk is a class. //I'm using this structure to remember positions of chunks in a file format. //These both work: chunks[""]~=new Chunk(); chunks["B

Associative arrays - non-intuitive 'in' semantics

2012-02-17 Thread Ben Davis
Same example as in the other message: Chunk[][char[4]] chunks; chunks["DATA"]~=new Chunk(); if ("DATA" !in chunks) throw new Exception("No DATA chunk"); The exception is thrown. Changing it as follows fixes it: if (cast(char[4])"DATA" !in chunks) throw new Exception("No DATA chunk"); I can sor

Re: Associative arrays - non-intuitive 'in' semantics

2012-02-18 Thread Ben Davis
On 18/02/2012 03:04, Andrej Mitrovic wrote: AA's seem to be full of bugs. You shouldn't be able to use a mutable keytype. For now your best option is probably to just use string as the key type. The good news is I didn't intend for the key to be mutable. I've updated my code to make it explici

Re: When are associative arrays meant to throw a RangeError?

2012-02-18 Thread Ben Davis
Starting with magic initialisation then... Is it vital that e[nonexistentKey] throw a RangeError, or could it just always return the type's default value if the key is absent? If you change that, then you can make assignment evaluate the RHS fully before even creating the LHS entry, and you w

Re: Associative arrays - non-intuitive 'in' semantics

2012-02-18 Thread Ben Davis
On 18/02/2012 03:04, Andrej Mitrovic wrote: AA's seem to be full of bugs. You shouldn't be able to use a mutable keytype. For now your best option is probably to just use string as the key type. Another thought here actually: Static arrays have value semantics, so char[4] is no more mutable th

Re: When are associative arrays meant to throw a RangeError?

2012-02-18 Thread Ben Davis
On 18/02/2012 13:22, Daniel Murphy wrote: "Ben Davis" wrote in message news:jho2mf$2a1t$1...@digitalmars.com... Starting with magic initialisation then... I meant a different magic initialization: int[int] aa = null; aa[3] = 7; // aa is magically not null any more Is it vi

Re: When are associative arrays meant to throw a RangeError?

2012-02-18 Thread Ben Davis
On 18/02/2012 13:22, Daniel Murphy wrote: "Ben Davis" wrote in message news:jho2mf$2a1t$1...@digitalmars.com... Starting with magic initialisation then... I meant a different magic initialization: int[int] aa = null; aa[3] = 7; // aa is magically not null any more I've

Re: When are associative arrays meant to throw a RangeError?

2012-02-18 Thread Ben Davis
Self-correction: I evidently didn't read that array.init returns null for static arrays. But the point holds for dynamic ones. On 18/02/2012 19:15, Ben Davis wrote: On 18/02/2012 13:22, Daniel Murphy wrote: "Ben Davis" wrote in message news:jho2mf$2a1t$1...@digitalmars.com...

Re: When are associative arrays meant to throw a RangeError?

2012-02-18 Thread Ben Davis
On 18/02/2012 20:54, Andrej Mitrovic wrote: Returning the default initializer of the value type when the key doesn't exist is a bad idea. Consider an integer, it's .init value is 0. If I want to check if a value of a key is zero I could easily end up with a silent bug: int[string] aa; aa["foobar

Re: When are associative arrays meant to throw a RangeError?

2012-02-18 Thread Ben Davis
On 18/02/2012 21:42, Ben Davis wrote: On 18/02/2012 20:54, Andrej Mitrovic wrote: Returning the default initializer of the value type when the key doesn't exist is a bad idea. Consider an integer, it's .init value is 0. If I want to check if a value of a key is zero I could easily end

Re: When are associative arrays meant to throw a RangeError?

2012-02-18 Thread Ben Davis
On 18/02/2012 22:57, Andrej Mitrovic wrote: Are you familiar with cases where you want regular arrays to return Type.init when you go out of bounds? The front page says D isn't meant to be an orthogonal language :P If you want orthogonality, then associative arrays will have to work something

Re: When are associative arrays meant to throw a RangeError?

2012-02-18 Thread Ben Davis
t not to work and make people's existing code crash, you can :) On 18/02/2012 23:08, Ben Davis wrote: On 18/02/2012 22:57, Andrej Mitrovic wrote: Are you familiar with cases where you want regular arrays to return Type.init when you go out of bounds? The front page says D isn't

Re: When are associative arrays meant to throw a RangeError?

2012-02-18 Thread Ben Davis
On 18/02/2012 23:33, Andrej Mitrovic wrote: Well it's probably too late to change this behavior. Both the sample on the hash page and TDPL itself shows the usage of that trick. That's fine - but let's document it :) A few things seem to be missing: - You get a RangeError for reading a nonexis

Re: The Right Approach to Exceptions

2012-02-18 Thread Ben Davis
On 18/02/2012 21:07, Andrej Mitrovic wrote: On 2/18/12, Nathan M. Swan wrote: It would be nice if there was a mixin template that creates an exception class that acts like this; making similar exception classes is annoying. It would be even nicer if we didn't need a mixin for classes that sim

Re: The Right Approach to Exceptions

2012-02-18 Thread Ben Davis
On 19/02/2012 00:48, Jonathan M Davis wrote: On Saturday, February 18, 2012 16:46:43 H. S. Teoh wrote: I can't believe something this simple has to be explained so elaborately. I thought all of us here knew how to use OO?? I think that the problem stems from people frequently using exceptions

Re: The Right Approach to Exceptions

2012-02-19 Thread Ben Davis
On 19/02/2012 02:19, Timon Gehr wrote: On 02/19/2012 02:23 AM, Jonathan M Davis wrote: One potential issue though is that not all base classes necessarily share the same constructors. Which ones would be grabbed? The ones from the immediate base class? All of them? Only the ones common to all?

Re: The Right Approach to Exceptions

2012-02-19 Thread Ben Davis
On 19/02/2012 01:54, Jonathan M Davis wrote: On Sunday, February 19, 2012 01:43:27 Ben Davis wrote: - distinguish between 'bug' exceptions (e.g. null) and 'you're more likely to want to catch this' exceptions (e.g. IO). Maybe the bug ones should have been Errors, sin

Re: When are associative arrays meant to throw a RangeError?

2012-02-19 Thread Ben Davis
On 19/02/2012 03:31, Daniel Murphy wrote: "Ben Davis" wrote in message news:jhotcm$13ag$1...@digitalmars.com... I've seen some line-blurring between 'null' and 'empty' for dynamic arrays (non-associative). Specifically, I read that array.init returns null

Re: When are associative arrays meant to throw a RangeError?

2012-02-19 Thread Ben Davis
On 19/02/2012 15:05, Daniel Murphy wrote: "Ben Davis" wrote in message news:jhr0qf$24sj$1...@digitalmars.com... On 19/02/2012 03:31, Daniel Murphy wrote: Except for this magic initialization, AAs behave the same as classes - ie a reference type. That's not quite true, beca

DLL crash inside removethreadtableentry - where's the source code for that?

2013-02-16 Thread Ben Davis
Hi, The user-mode driver I'm working on (a 32-bit DLL) is crashing Windows Media Player on exit. (Two other host apps exit fine.) I can catch it in the Visual Studio debugger, but only see assembly language. Initially I'm just after tips on where to find source for the bits of D that are invo

Re: DLL crash inside removethreadtableentry - where's the source code for that?

2013-02-16 Thread Ben Davis
Correction to my hideous analysis inside free :P On 17/02/2013 03:07, Ben Davis wrote: RTLMultiPool::SelectFree: 05C0AC34 pushecx //This reads 0x05c29b97 into eax 05C0AC35 mov eax,dword ptr [esp+8] //This reads an address from where eax points, and edx is 0 05C0AC39 mov

Re: DLL crash inside removethreadtableentry - where's the source code for that?

2013-02-17 Thread Ben Davis
On 17/02/2013 07:56, Rainer Schuetze wrote: _removethreadtableentry is a function in the DM C runtime library. It has the bug that it tries to free a data record that has never been allocated if the thread that loaded the DLL is terminated. This is the entry at index 1. That's a good start :)

Does the spec preclude objects being movable by the GC?

2013-02-25 Thread Ben Davis
Unless I'm mistaken, this page: http://dlang.org/garbage.html states that it's safe to use a union to share storage with a pointer, e.g. union U { void* ptr; int value } But that wouldn't be safe if the GC ever moved objects. Should the page be tweaked? Especially as further down on that page

Re: Does the spec preclude objects being movable by the GC?

2013-02-25 Thread Ben Davis
On 25/02/2013 23:15, Ben Davis wrote: Unless I'm mistaken, this page: http://dlang.org/garbage.html states that it's safe to use a union to share storage with a pointer, e.g. union U { void* ptr; int value } But that wouldn't be safe if the GC ever moved objects. Should the