Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
class A { string getName(this Klass)() { return Klass.stringof; } } class B : A {} void main() { import std.stdio; auto a = new A; auto b = new B; writeln(a.getName()); writeln(b.getName()); } ## This i

Re: Value of floating in JSONValue

2014-08-21 Thread nrgyzer via Digitalmars-d-learn
On Thursday, 21 August 2014 at 23:29:56 UTC, Idan Arye wrote: On Thursday, 21 August 2014 at 23:05:48 UTC, Ali Çehreli wrote: I don't think it is a concern as JSON does not encode types. It is up to the receiver how to interpret the data. Here is the output of the program above: {"value":"1.2

Re: RAII limitations in D?

2014-08-21 Thread Kagamin via Digitalmars-d-learn
On Friday, 22 August 2014 at 02:22:16 UTC, Timothee Cour via Digitalmars-d-learn wrote: Especially the part mentioning D:{ D’s scope keyword, Python’s with statement and C#’s using declaration all provide limited RAII, by allowing resources to have a scoped lifetime, but none of them readily or

Re: RAII limitations in D?

2014-08-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, 22 August 2014 at 03:00:01 UTC, Timothee Cour via Digitalmars-d-learn wrote: On Thu, Aug 21, 2014 at 7:26 PM, Dicebot via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: http://dlang.org/phobos/std_typecons.html#.RefCounted That doesn't work with classes though; i

Re: new error message in 2.066, type bool (const)

2014-08-21 Thread Paul D Anderson via Digitalmars-d-learn
On Friday, 22 August 2014 at 01:25:05 UTC, Paul D Anderson wrote: On Wednesday, 20 August 2014 at 20:46:20 UTC, Paul D Anderson I don't know if this is expected behavior that just wasn't enforced before, or if this is something new. Either way I don't like it. And I'm a little surprised I'm the

Re: RAII limitations in D?

2014-08-21 Thread Timothee Cour via Digitalmars-d-learn
On Thu, Aug 21, 2014 at 7:26 PM, Dicebot via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > http://dlang.org/phobos/std_typecons.html#.RefCounted That doesn't work with classes though; is there any way to get a ref counted class? (and btw RefCounted should definitely appear i

Re: RAII limitations in D?

2014-08-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 22 August 2014 at 02:22:16 UTC, Timothee Cour via Digitalmars-d-learn wrote: What would be a good answer to this article? It's own publication date: Feb 2009. The D struct has changed a lot since then, getting new features (@disable, postblit, more reliable destructor) and bugs not

Re: RAII limitations in D?

2014-08-21 Thread Dicebot via Digitalmars-d-learn
http://dlang.org/phobos/std_typecons.html#.RefCounted

RAII limitations in D?

2014-08-21 Thread Timothee Cour via Digitalmars-d-learn
What would be a good answer to this article? http://swiftcoder.wordpress.com/2009/02/18/raii-why-is-it-unique-to-c/ Especially the part mentioning D:{ D’s scope keyword, Python’s with statement and C#’s using declaration all provide limited RAII, by allowing resources to have a scoped lifetime, bu

Re: Trouble reproducing compilation error

2014-08-21 Thread Xinok via Digitalmars-d-learn
This is the full compiler output: combsort.d(90): Error: template D main.pred cannot deduce function from argument types !()(uint, uint), candidates are: benchsort.d(37):benchsort.main.pred(T)(T a, T b) benchsort.d(81): Error: template instance combsort.combSortLinear!(pred, uint[]) e

Trouble reproducing compilation error

2014-08-21 Thread Xinok via Digitalmars-d-learn
I'm currently receiving several errors when trying to compile this code with DMD 2.066 (beginning with RC1): https://github.com/Xinok/XSort The compiler throws an error because it's unable to deduce a type for the predicate in a few places. This repository compiles just fine in DMD 2.065 and

Re: new error message in 2.066, type bool (const)

2014-08-21 Thread Paul D Anderson via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 20:46:20 UTC, Paul D Anderson wrote: Re-compiling existing code with version 2.066 generates a lot of errors complaining about implicit conversion to const. Typical is this call (inside a struct with properties 1 & 2): z.sign = x.sign ^ y.sign; Error: N

Re: Value of floating in JSONValue

2014-08-21 Thread Idan Arye via Digitalmars-d-learn
On Thursday, 21 August 2014 at 23:05:48 UTC, Ali Çehreli wrote: I don't think it is a concern as JSON does not encode types. It is up to the receiver how to interpret the data. Here is the output of the program above: {"value":"1.234567889998901"} Ali JSON may not encode the very specif

Re: Value of floating in JSONValue

2014-08-21 Thread Ali Çehreli via Digitalmars-d-learn
On 08/21/2014 11:53 AM, nrgyzer wrote: > double d = 1.23456789; > JSONValue j = d; > sendToRemote(toJSON(&j)); > } > > My problem is that the remote PC receives 1.23457 instead of > 1.23456789. I think it is due to the following code simply calling to!string in std/phobos/json.d:

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread MarisaLovesUsAll via Digitalmars-d-learn
On Thursday, 21 August 2014 at 20:16:33 UTC, anonymous wrote: Maybe you can explain what you're trying to achieve with all this. There may be a different/better way to do it. Sure. Class tree: GameObject->Component->Sprite. GameObject structure: Component[]; Component addComponent(Compo

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread anonymous via Digitalmars-d-learn
On Thursday, 21 August 2014 at 20:05:13 UTC, Ary Borenszweig wrote: I'll tell you how it's done in Crystal in case someone wants to come up with a proposal to make it work in D. ~~~ class Foo macro inherited def method_in_{{@class_name.downcase.id}} puts "Hello {{@class_name.id}}!"

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread anonymous via Digitalmars-d-learn
On Thursday, 21 August 2014 at 19:58:18 UTC, MarisaLovesUsAll wrote: When I make mixin injection in one class, I want auto-injection in another class. How can I do this? class Component:GameObject { //second injection must be here and must be automatic }; class Sprite:Component { mixin

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread Ary Borenszweig via Digitalmars-d-learn
On 8/21/14, 6:38 AM, MarisaLovesUsAll wrote: tl;dr - how to get child classname from inherited parent function at compile time? class A { string getName(); }; class B { }; B foo = new B; assert(foo.getName() == "B"); ... Hi! I'm stuck at one issue, and I don't know how to solve it. I think this

Re: new error message in 2.066, type bool (const)

2014-08-21 Thread Brad Anderson via Digitalmars-d-learn
On Thursday, 21 August 2014 at 03:02:53 UTC, Paul D Anderson wrote: What changed? It ran okay with early beta versions, but not with the release. Paul It compiles in beta-5 but not beta-6. Is the list of changes in the beta testing wiki complete? None seem pertinent. monarch_dodra: Thank

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread MarisaLovesUsAll via Digitalmars-d-learn
On Thursday, 21 August 2014 at 13:19:06 UTC, anonymous wrote: 1) How to make mixin inject automatic? You could use this pattern: interface Component {} class ComponentImpl(T) {} class Sprite : ComponentImpl!Sprite {} From my view, it's an architectural crutch. %) You can use `typeof(this)`

Value of floating in JSONValue

2014-08-21 Thread nrgyzer via Digitalmars-d-learn
Hi everyone, I'm facing a problem with the JSON functions. I've to communicate with another PC using JSON. Here's a simple snipped which shows my problem: import std.json; import std.stdio; void main() { double d = 1.23456789; JSONValue j = d; sendToRemote(toJSON(&j)); }

Re: goto skips declaration of variable

2014-08-21 Thread nrgyzer via Digitalmars-d-learn
On Thursday, 21 August 2014 at 17:39:16 UTC, Ali Çehreli wrote: On 08/21/2014 04:12 AM, nrgyzer wrote: > I'm using the goto-command to exit my function > if an error (not necessarily an exception) occured. Sorry to repeat myself but if an exception occurs in code before the goto, the exit code

Re: D with no druntime

2014-08-21 Thread maarten van damme via Digitalmars-d-learn
There were 2 talks about bare metal D this year at the D conference. The first one is about someone able to use D on microcontrollers with a few k ram.: https://www.youtube.com/watch?v=o5m0m_ZG9e8 The second one is about someone trying to strip almost everything out and see what works: https://ww

Re: goto skips declaration of variable

2014-08-21 Thread Ali Çehreli via Digitalmars-d-learn
On 08/21/2014 04:12 AM, nrgyzer wrote: > I'm using the goto-command to exit my function > if an error (not necessarily an exception) occured. Sorry to repeat myself but if an exception occurs in code before the goto, the exit code will not be executed. Of course, it may be that the function is

Re: Generating a tree structure

2014-08-21 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 21 August 2014 at 14:09:24 UTC, Ricky C wrote: TileTree* self; Don't do that. D has banned internal pointers to implement its move semantics. branches[index] = tile_trees[index]; This will make a *value-copy* of your TileTree nodes. There are good chances it'll break your tr

Re: Generating a tree structure

2014-08-21 Thread anonymous via Digitalmars-d-learn
On Thursday, 21 August 2014 at 14:09:24 UTC, Ricky C wrote: I'm trying to make a tree data structure in part of my first non-trivial D-based program. Turns out that DMD likes to re-use PODs - sounds good, but that trapped me, and I'm not sure how to clear myself out of the problem nicely. My

Generating a tree structure

2014-08-21 Thread Ricky C via Digitalmars-d-learn
I'm trying to make a tree data structure in part of my first non-trivial D-based program. Turns out that DMD likes to re-use PODs - sounds good, but that trapped me, and I'm not sure how to clear myself out of the problem nicely. My simplified, but not oversimplified, example is http://dpast

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread anonymous via Digitalmars-d-learn
On Thursday, 21 August 2014 at 12:58:13 UTC, MarisaLovesUsAll wrote: I found a rough solution. It's not ideal and I still want to make autoinject, but it works. mixin template Manager(T) {}; class Component {}; class Sprite:Component { mixin Manager!Sprite; }; 1) How to make mixin inject

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread MarisaLovesUsAll via Digitalmars-d-learn
I found a rough solution. It's not ideal and I still want to make autoinject, but it works. mixin template Manager(T) {}; class Component {}; class Sprite:Component { mixin Manager!Sprite; }; 1) How to make mixin inject automatic? 2) If it's impossible, how to use "mixin Manager;" without

Re: goto skips declaration of variable

2014-08-21 Thread nrgyzer via Digitalmars-d-learn
On Tuesday, 19 August 2014 at 20:33:00 UTC, monarch_dodra wrote: On Monday, 18 August 2014 at 13:51:14 UTC, nrgyzer wrote: Hi all, I've the following code snipped: import std.bigint; void main(string[] args) { BigInt i = "12345"; if (args.length > 1) { g

Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread MarisaLovesUsAll via Digitalmars-d-learn
tl;dr - how to get child classname from inherited parent function at compile time? class A { string getName(); }; class B { }; B foo = new B; assert(foo.getName() == "B"); ... Hi! I'm stuck at one issue, and I don't know how to solve it. I think this is about mixins/templates, isn't it? When in

Re: Can you explain this?

2014-08-21 Thread Colin via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 20:18:15 UTC, Dicebot wrote: On Wednesday, 20 August 2014 at 20:01:05 UTC, Colin wrote: I see 3 distinct parts playing a role in my confusion: A) The 'is' keyword. What does it do when you have is(expression); http://dlang.org/expression.html#IsExpression It i