Re: r/w binary

2011-06-30 Thread Ali Çehreli
On Thu, 30 Jun 2011 15:52:59 +1200, Joel Christensen wrote: I'm thinking more about handling binary files. With the C version I would write a int for how many letters in the string, then put in the the string along side ([0005][house]). That way I can have any character at all (though I just

Re: Forcing compile time evaluation of pure functions

2011-06-30 Thread bearophile
scarrow: Annoyingly, however, I can't do the following at compile time: f(Hash(foo)); I'm not sure what the point is in distinguishing between these two cases. Walter has decided that he doesn't like the D compiler to arbitrary run at compile time arbitrary long to run code. This is

Re: Forcing compile time evaluation of pure functions

2011-06-30 Thread Simen Kjaeraas
On Thu, 30 Jun 2011 07:11:44 +0200, scarrow shawn.ba...@gmail.com wrote: Hey all, I'd like to embed hashed strings into my code. The C++ version of this engine ran an external tool to preprocess the files. In D my strongly pure function is only evaluated if I assign it to something like

Re: r/w binary

2011-06-30 Thread Joel Christensen
Yes, portability, I hadn't thought of that. Shouldn't file.rawWrite((i)[0..1]); have [0..4]? Or am I missing some thing? - Joel On 30-Jun-11 7:53 PM, Ali Çehreli wrote: On Thu, 30 Jun 2011 15:52:59 +1200, Joel Christensen wrote: I'm thinking more about handling binary files. With the C

Re: r/w binary

2011-06-30 Thread Ali Çehreli
On Fri, 01 Jul 2011 05:28:56 +1200, Joel Christensen wrote: Shouldn't file.rawWrite((i)[0..1]); have [0..4]? Or am I missing some thing? [0..1] follows the regular slicing syntax there: those are element indexes. Since i is an int*, [0..1] slices the first int. It would be different if it

Re: C callback receives bad pointer argument

2011-06-30 Thread bearophile
Marco Cosentino: Translated correctly the C callback style into D delegates types with alias. D has function pointers too. Managed some segment faluts happened when not using toStringz() with some strings For this kind of bugs I suggest to use the D type system in a smarter way. With

Re: C callback receives bad pointer argument

2011-06-30 Thread Andrej Mitrovic
Try this: int process (jack_nframes_t nframes, void *arg) - extern(C) int process (jack_nframes_t nframes, void *arg)

Re: C callback receives bad pointer argument

2011-06-30 Thread bearophile
Now that typedef is deprecated what solution do you suggest instead? Something like this, I think: struct ccharPtr { const char* ptr; alias ptr this; } ccharPtr toStringz2(string s) { return ccharPtr(toStringz(s)); } Bye, bearophile

Why does std.string use public imports?

2011-06-30 Thread Andrej Mitrovic
I'm referring to these two in std.string: public import std.algorithm : startsWith, endsWith, cmp, count; public import std.array : join, split; Because whenever I try to use .count in my code: import std.stdio; import std.string; import std.utf; void main() { writeln(foo.count); }

Re: Why does std.string use public imports?

2011-06-30 Thread simendsjo
On 01.07.2011 01:14, Andrej Mitrovic wrote: I'm referring to these two in std.string: public import std.algorithm : startsWith, endsWith, cmp, count; public import std.array : join, split; Because whenever I try to use .count in my code: import std.stdio; import std.string; import std.utf;

Re: Why does std.string use public imports?

2011-06-30 Thread Andrej Mitrovic
That makes sense, I understand. But I hate these conflicts. I've got `alias std.bla.foo foo` scattered in most of my code due to constant conflicts. :/

Passing a generic struct as parameter

2011-06-30 Thread Zardoz
I have a parametrized struct (Vector!(T, dim)) that takes two parameters (Type and a number). And made some Alias with defaults parameters. In other struct (Matrix!(T, dim)), that uses these struct to represent a matrix in column-major order. I have a internall alias for Vector using

Re: Passing a generic struct as parameter

2011-06-30 Thread Jonathan M Davis
On 2011-06-30 16:39, Zardoz wrote: I have a parametrized struct (Vector!(T, dim)) that takes two parameters (Type and a number). And made some Alias with defaults parameters. In other struct (Matrix!(T, dim)), that uses these struct to represent a matrix in column-major order. I have a

Re: Why does std.string use public imports?

2011-06-30 Thread Jonathan M Davis
On 2011-06-30 16:14, Andrej Mitrovic wrote: I'm referring to these two in std.string: public import std.algorithm : startsWith, endsWith, cmp, count; public import std.array : join, split; Because whenever I try to use .count in my code: import std.stdio; import std.string; import

Re: Passing a generic struct as parameter

2011-06-30 Thread Simen Kjaeraas
On Fri, 01 Jul 2011 01:39:53 +0200, Zardoz luis.panad...@gmail.com wrote: I have a parametrized struct (Vector!(T, dim)) that takes two parameters (Type and a number). And made some Alias with defaults parameters. In other struct (Matrix!(T, dim)), that uses these struct to represent a matrix

Generic invert function?

2011-06-30 Thread Andrej Mitrovic
So I thought this would be in Phobos, basically I want to reverse the polarity of a value in a range. What I mean is if I have a possible range of 0 .. 127, then the values of the left would equal the inverted values on the right: 0 - 127 10 - 117 20 - 107 50 - 77 77 - 50 and so on.. Quite easy

Re: Generic invert function?

2011-06-30 Thread Andrej Mitrovic
Stupid brain, LOL. auto arr = array(retro(iota(0, 127))); Problem solved.

Re: Generic invert function?

2011-06-30 Thread Andrej Mitrovic
Woops, bug, right side not inclusive. Fixed: auto arr = array(retro(iota(0, 128)));

Re: Why does std.string use public imports?

2011-06-30 Thread Jesse Phillips
Andrej Mitrovic Wrote: I'm referring to these two in std.string: public import std.algorithm : startsWith, endsWith, cmp, count; public import std.array : join, split; I'm not sure why they are public, but selective/named imports have been publicly imported for some time. Bugzilla 3?? I

Creating a thread-local duplicate of a globally shared array

2011-06-30 Thread Andrej Mitrovic
I have two functions running concurrently and they share data via a globally shared array. Generally one thread modifies an array and potentially changes its length, the other thread reads from it. I have to avoid too many locks and message passing wouldn't really work since I need fast access to