Re: Enumerating structs?

2012-01-04 Thread Heywood Floyd
Yeah, D feels like that to me too, sometimes. Anyways, for your question - would using the struct name be good enough? They're easy to get hold of and usable in switch statements. If not, how about this: import std.typetuple; struct TypeEnum( T... ) { static pure nothrow @property

Enumerating structs?

2012-01-03 Thread Heywood Floyd
Hello! I have some structs struct A { int a; } struct B { int b, c; } and I'd like to be able to enumerate them (preferrably as integers) based on their names. I've no idea how this would look, but some pseudo code that would use this feature: // pseudo int type = stream.read!int();

Re: Catching signals with D

2011-12-22 Thread Heywood Floyd
On 12/22/11 23:51 , Matej Nanut wrote: Hello everyone, I've been fascinated by D lately and have been using it for all my school assignments (like simple ray casting and simulated annealing). What I can't find anywhere is how to do something like signal(SIGINT, myhandler) (I'm in a Linux

Re: d2 file input performance

2011-08-28 Thread Heywood Floyd
Christian Köstlin Wrote: after some optimizing i got better, but was still way slower than c++. so i started some small microbenchmarks regarding fileio: https://github.com/gizmomogwai/performance in c++, java and d2. christian Hello! Thanks for you effort in putting this together! I

Create a foreach-able struct? Multi-dimensional even?

2011-08-25 Thread Heywood Floyd
Hello! 1) How do I create a struct that I can foreach over? I get the impression opApply has something do to with this, but I can't find any documentation on it? (And I'm abroad without my TDPL.) 2) Also, is it possible to do something like this? MyData!(100,100,100) data; foreach(x,

Re: Create a foreach-able struct? Multi-dimensional even?

2011-08-25 Thread Heywood Floyd
Heywood Floyd Wrote: Hello! 1) How do I create a struct that I can foreach over? I get the impression opApply has something do to with this, but I can't find any documentation on it? (And I'm abroad without my TDPL.) 2) Also, is it possible to do something like this? MyData

Re: Create a foreach-able struct? Multi-dimensional even?

2011-08-25 Thread Heywood Floyd
Christophe Wrote: Still, is the multi-dimensional part possible? Sure, you have to make an opApply that takes several parameters in its delegate. An exemple: struct TwoDArray(int nx, int ny) { int[nx][ny] data; int opApply(int delegate(ref int i, ref int j, ref int cell)

Re: Get address of label?

2010-12-26 Thread Heywood Floyd
Thank you bearophile and Simen for your replies! Very helpful! I'll keep looking into it... BR /HF bearophile Wrote: Simen kjaeraas: Essentially, mark the switch as final, and cover every option. Likely, the optimizer does that for you if you cover every option but don't mark the

Get address of label?

2010-12-25 Thread Heywood Floyd
Is this possible somehow: int op(int r, int i) { static auto tbl = [add, sub, mul]; goto tbl[i % 3]; add: r++; goto end; sub: r--;

Re: Get address of label?

2010-12-25 Thread Heywood Floyd
. (Or is it a stupid idea to begin with? Is this overkill? : ) cheers! BR /HF PS. How do you export assembler code from the DMD-compiler? Simen kjaeraas Wrote: Heywood Floyd soul...@gmail.com wrote: Is this possible somehow: int op(int r, int i) { static auto

Re: Is libdruntime deprecated in 2.051?

2010-12-24 Thread Heywood Floyd
/libphobos2.a, /usr/local/lib/libdruntime.a); }; to CommandLineArgs = { NO = (); otherwise = (/usr/local/lib/libphobos2.a); }; and restart Xcode. (Sorry for the boring post. Just documenting for future reference.) BR /HF Heywood Floyd Wrote: Build fails after upgrade to 2.051 with gcc

Re: Strange socket error

2010-12-23 Thread Heywood Floyd
to be getting away with on Windows. If it's a bug in the compiler or libraries I think I'm stuffed as I wouldn't know where to start. Regards bob On 23/12/2010 00:20, Heywood Floyd wrote: Hi Bob! My guess: You're listener is set to be non-blocking. That means that when you call

Re: Strange socket error

2010-12-22 Thread Heywood Floyd
Hi Bob! My guess: You're listener is set to be non-blocking. That means that when you call listener.accept() it will return immediately with an SocketAcceptException, if there's no connection. And you're basically calling listener.accept() over and over again in an infinite loop. The

Concurrency and transfering ownership of data between threads?

2010-12-13 Thread Heywood Floyd
and have a third thread work on the copied data, without barriers or guards or stuff like that during the time of actual work? Kind regards and sorry for a lengthy sporadic post /Heywood Floyd

Re: atomicOp problem

2010-10-21 Thread Heywood Floyd
Interesting! I get the same result, ie an infinite loop, with the CPU at 100% Some things I noticed: - Changing the for-loops to 100 or 10 doesn't help. - Changing the atomicOp from += to just + makes it work (although the account doesn't get changed) - Adding a Thread.sleep(1000) in one of the

Stripping D symbols?

2010-10-16 Thread Heywood Floyd
Hello! I've been trying to strip an executable created with DMD from symbols. Has anyone any experience with this? I can't seem to rid my execs of more or less containing the entire class-tree. Example: // sym.d - - - - import std.stdio; class Bunny{ int x; int getX()

Re: Stripping D symbols?

2010-10-16 Thread Heywood Floyd
? Seems the OSX-strip is acting funny? Or could it have something to do with DMD still? Maybe I should ask in some darwin-forum about strip... BR /HF Heywood Floyd Wrote: Hello! I've been trying to strip an executable created with DMD from symbols. Has anyone any experience

Linking D and Obj-C code into a Cocoa app proper? (Mac)

2010-10-05 Thread Heywood Floyd
Good Evenening Ladies and Gentlemen! == Background == So I currently have a bare-bones Cocoa-app. It's just a window with an OpenGL-view. In the view's draw-function I make the gl-view the current OpenGL context and then call extern (C) render(). Meanwhile, in a D-file I have the

Re: Linking D and Obj-C code into a Cocoa app proper? (Mac)

2010-10-05 Thread Heywood Floyd
Ok! Thanks for the advice! Great work on the plugin—it got me into D :) /FH Michel Fortin Wrote: On 2010-10-05 10:02:45 -0400, Heywood Floyd soul...@gmail.com said: But, sometimes I get reeeaally weird bugs. I had one bug where if I added an empty function to a class in D I got

Re: std.socket.TcpSocket.flush

2010-07-26 Thread Heywood Floyd
Rory Mcguire Wrote: Hi, What is one supposed to use to flush a TcpSocket. flush doesn't seem to exist, should I really just use the c function? -Rory Was in a similar situation, found this: http://stackoverflow.com/questions/855544/is-there-a-way-to-flush-a-posix-socket I

Re: string[int[][]] ??

2010-07-23 Thread Heywood Floyd
string[int[2]] board; board[[0,0]] = Rook; board[[0,1]] = Knight; foreach( pos, val; board) { writefln( %s: %s, pos, val); } Output: 2 9903680: Knight 2 9903696: Rook Changing the declaration to string[int[]] board; makes it work (for me). BR /HF

Re: Multi dimensional array question.

2010-07-16 Thread Heywood Floyd
Mafi Wrote: I don't really like it. Of course the order of indices feels better but it breaks the rule of reading types from right to left. It also introduces more parenthesis and a new keyword into types (amongst const, immutable and delegate etc). Consider: shared array[3](const(

Is synchronized(mutex) == mutex.lock()?

2010-07-14 Thread Heywood Floyd
Hi! Breakfast toast: Is there any chance a) and b) below are identical in what they do? auto mutex = new Mutex(); auto cond = new Condition(mutex); // a) synchronized(mutex){ cond.wait(); } // b) mutex.lock(); cond.wait(); mutex.unlock(); I was sprinkling my code with

Re: Multi dimensional array question.

2010-07-12 Thread Heywood Floyd
This had me crazy. I ended up putting the brackets on the variable, like int marr[3][5]; then it worked like marr[2][4] = 9;

Re: Multi dimensional array question.

2010-07-12 Thread Heywood Floyd
bearophile Wrote: Heywood Floyd: This had me crazy. I ended up putting the brackets on the variable, like int marr[3][5]; then it worked like marr[2][4] = 9; That's present only for compatibility with C syntax, this means that you can use it to perform a quicker port of C code

Is the memory address of classinfo the same for all instances of a class?

2010-07-02 Thread Heywood Floyd
Good day! Consider // - - - - class Foo{} auto one = new Foo(); auto two = new Foo(); writefln(one: %x two: %x, one.classinfo, two.classinfo); // - - - - For me this results in two identical memory addresses every time. Can I rely on this? Can I design software based on the assumption that

Re: Is the memory address of classinfo the same for all instances of a class?

2010-07-02 Thread Heywood Floyd
On Jul 2, 2010, at 15:34 , Steven Schveighoffer wrote: On Fri, 02 Jul 2010 09:32:39 -0400, Steven Schveighoffer schvei...@yahoo.com wrote: On Fri, 02 Jul 2010 09:24:20 -0400, Heywood Floyd soul...@gmail.com wrote: Good day! Consider // - - - - class Foo{} auto one = new Foo

How to call receiveTimout? (std.concurrency)

2010-06-29 Thread Heywood Floyd
Hello and Good morning! I'm trying to use receiveTimeout: // import std.stdio, std.concurrency; int main(string[] args){ receiveTimeout( 1000L, (int i){writefln(Received: %d,i);} ) ; return 0; } //

Re: How to call receiveTimout? (std.concurrency)

2010-06-29 Thread Heywood Floyd
:53:25 -0400, Simen kjaeraas simen.kja...@gmail.com wrote: Heywood Floyd soul...@gmail.com wrote: ops = ops[1 .. $]; // === line 335 Well, this looks like a bug to me. Should be Ops = ops[1 .. $]; Ops is a type, isn't it? Don't you need a variable there? I agree it's a bug

Re: How to call receiveTimout? (std.concurrency)

2010-06-29 Thread Heywood Floyd
Thanks! I will! /heywood PS. I like D. On Jun 29, 2010, at 19:37 , Steven Schveighoffer wrote: On Tue, 29 Jun 2010 13:05:50 -0400, Heywood Floyd soul...@gmail.com wrote: Ok, thanks! How does the chain of command/responsibility work here? Should I file this to bugzilla