idup class
trying to follow: http://ddili.org/ders/d.en/class.html //--- OSX 10.9 DMD 2.065 module test; class Foo { int num; this(int num) { this.num = num; } Foo dup() const { return new Foo(this.num); } immutable(Foo) idup() const { return new immutable(Foo)(this.num); } } void main() { auto foo = new Foo(1); auto mfoo = foo.dup(); auto ifoo = foo.idup(); } * test.d(15): Error: mutable method test.Foo.this is not callable using a immutable object * test.d(15): Error: no constructor for Foo * Failed: [dmd, -v, -o-, test.d, -I.] //--- What am i missing?
Re: idup class
On Friday, 16 May 2014 at 20:36:37 UTC, Ali Çehreli wrote: My apologies. The code was written for an older version of dmd. The simplest fix is to define the constructor as pure: pure this(int num) { this.num = num; } Ali Ahh great thanks guys. No worries Ali, great book, i refer to it all the time :)
Re: core.sync.rwmutex example
Hi Charles, would the following work (just a shot in the dark) ? //--- module test; import std.stdio; import std.concurrency; void spawnedFuncFoo(Tid tid, Tid tidBar) { receive( (int i) { writeln(Foo Received the number , i); send(tidBar, i, thisTid); auto barSuccessful = receiveOnly!(string); writeln(Bar got my (Foo) message); } ); send(tid, true); } void spawnedFuncBar(Tid tid) { receive( (int i, Tid tidFoo) { writeln(Foo passed me (Bar) the number , i); send(tidFoo, done); } ); receive( (string sig) { writeln(Main says I'm (Bar) done.); send(tid, 42); } ); } void main() { auto tidBar = spawn(spawnedFuncBar, thisTid); auto tidFoo = spawn(spawnedFuncFoo, thisTid, tidBar); send(tidFoo, 42); auto fooWasSuccessful = receiveOnly!(bool); assert(fooWasSuccessful); send(tidBar, your done); auto barWasSuccessful = receiveOnly!(int); assert(barWasSuccessful == 42); writeln(Successfully had two separate threads communicate with each other); } //---
Atom text editor
FYI: If anyone is using GitHub's text editor Atom and would like basic D syntax highlighting: apm init --package ~/.atom/packages/language-d --convert https://github.com/textmate/d.tmbundle https://atom.io/docs/v0.94.0/converting-a-text-mate-bundle