Re: How to detect current executable file name?

2013-02-17 Thread eGust
On Monday, 18 February 2013 at 07:07:42 UTC, Jonathan M Davis wrote: On Monday, February 18, 2013 07:59:08 SaltySugar wrote: On Monday, 18 February 2013 at 03:28:59 UTC, eGust wrote: > I need to locate the directory of current executable file, > but > I can't find how to do that in Phobos. I t

Re: How to detect current executable file name?

2013-02-17 Thread Jacob Carlborg
On 2013-02-18 04:28, eGust wrote: I need to locate the directory of current executable file, but I can't find how to do that in Phobos. I tried core.runtime.Runtime.args[0], but failed. Is there a standard method of Phobos to do that? I only know the way of Windows (GetModuleFileName), but I thin

Re: How to detect current executable file name?

2013-02-17 Thread Jonathan M Davis
On Monday, February 18, 2013 07:59:08 SaltySugar wrote: > On Monday, 18 February 2013 at 03:28:59 UTC, eGust wrote: > > I need to locate the directory of current executable file, but > > I can't find how to do that in Phobos. I tried > > core.runtime.Runtime.args[0], but failed. Is there a standard

Re: How to detect current executable file name?

2013-02-17 Thread SaltySugar
On Monday, 18 February 2013 at 03:28:59 UTC, eGust wrote: I need to locate the directory of current executable file, but I can't find how to do that in Phobos. I tried core.runtime.Runtime.args[0], but failed. Is there a standard method of Phobos to do that? I only know the way of Windows (Get

Re: How to dynamically alias a struct to a byte array?

2013-02-17 Thread Ali Çehreli
On 02/17/2013 12:12 PM, jerro wrote: > You don't need to cast it each time, you can do something like: > > auto structPointer = cast(MyStruct*) byteArray.ptr; And that pointer can be converted to a D slice: MyStruct[] slice = structPointer[0..number_of_struct_objects]; Use 'slice' as a regul

Re: Creating Structs/Classes at runtime?

2013-02-17 Thread Ali Çehreli
On 02/17/2013 04:44 PM, Brian Brady wrote: > 1) my full csv is 4000 variables wide, and I really don't want to > declare each variable in the struct (I've created a smaller one to test) Looking at the sample file you provide, what you call "variables" look like data points. > 2) what if I wan

Re: How to dynamically alias a struct to a byte array?

2013-02-17 Thread Charles Hixson
On 02/17/2013 12:12 PM, jerro wrote: The only thing I've though of so far is to declare a class that holds a bunch of abstract methods, and then have multiple descendants that each have a special variant of the struct. And even then I've either got to copy it again, or to cast it each time I use

Re: Creating Structs/Classes at runtime?

2013-02-17 Thread Brian Brady
On Monday, 18 February 2013 at 00:52:12 UTC, Adam D. Ruppe wrote: [...] --- auto text = "Name,Occupation,Salary\r" "Joe,Carpenter,30\nFred,Blacksmith,40\r\n"; foreach(record; csvReader!(string[string]) (text, null)) { writefln("%s works as a %s and earns $%s pe

How to detect current executable file name?

2013-02-17 Thread eGust
I need to locate the directory of current executable file, but I can't find how to do that in Phobos. I tried core.runtime.Runtime.args[0], but failed. Is there a standard method of Phobos to do that? I only know the way of Windows (GetModuleFileName), but I think as a common task there should

Re: static class

2013-02-17 Thread Steven Schveighoffer
On Sun, 17 Feb 2013 18:26:37 -0500, Ben Davis wrote: On 17/02/2013 22:25, Jonathan M Davis wrote: On Sunday, February 17, 2013 23:00:19 Michael wrote: That's not the meaning of static in that context. As I understand a static class can't be instantiated. I have no idea how you came to tha

Re: Creating Structs/Classes at runtime?

2013-02-17 Thread H. S. Teoh
On Mon, Feb 18, 2013 at 01:44:49AM +0100, Brian Brady wrote: [...] > I was reading in some data from a csv and wanted to read it into a > struct called. > My problem is > 1) my full csv is 4000 variables wide, and I really don't want to > declare each variable in the struct (I've created a smaller

Re: Creating Structs/Classes at runtime?

2013-02-17 Thread Adam D. Ruppe
There is a way to get what you described, and your code is fairly close... but there's a much simpler way too. from the std.csv docs: == When an input contains a header the $(D Contents) can be specified as an associative array. Passing null to signify that a header is present. ---

Creating Structs/Classes at runtime?

2013-02-17 Thread Brian Brady
Hi Ok first ... is this possible? Or wise? Being mostly self taught with regards to programming I sometimes wonder if the way I'm going about something is even the right approach, never mind whether my code is logical. So if this seems ludicrous then please tell me my approach is silly and poi

Re: static class

2013-02-17 Thread Jonathan M Davis
On Sunday, February 17, 2013 23:26:37 Ben Davis wrote: > On 17/02/2013 22:25, Jonathan M Davis wrote: > > However, non-static nested classes are associated with an instance of the > > outer class, and therefore only one can exist per class instance. > > That's not true, is it? You can make as many

Re: static class

2013-02-17 Thread Ben Davis
On 17/02/2013 22:25, Jonathan M Davis wrote: On Sunday, February 17, 2013 23:00:19 Michael wrote: That's not the meaning of static in that context. As I understand a static class can't be instantiated. I have no idea how you came to that conclusion. In fairness, it is the natural guess you

Re: static class

2013-02-17 Thread Jonathan M Davis
On Sunday, February 17, 2013 14:47:12 H. S. Teoh wrote: > On Sun, Feb 17, 2013 at 11:46:24PM +0100, Andrej Mitrovic wrote: > > On 2/17/13, Steven Schveighoffer wrote: > > > A class that can't be instantiated has a private constructor. > > > > An alternative to that is: > > > > final abstract cla

Re: static class

2013-02-17 Thread H. S. Teoh
On Sun, Feb 17, 2013 at 11:46:24PM +0100, Andrej Mitrovic wrote: > On 2/17/13, Steven Schveighoffer wrote: > > A class that can't be instantiated has a private constructor. > > An alternative to that is: > > final abstract class C > { > static: > } > > You can't derive from it and you can't

Re: static class

2013-02-17 Thread Jonathan M Davis
On Sunday, February 17, 2013 23:00:19 Michael wrote: > > That's not the meaning of static in that context. > > As I understand a static class can't be instantiated. I have no idea how you came to that conclusion. That's not what it means for a class to be static at all. The only place that stati

Re: A little of coordination for Rosettacode

2013-02-17 Thread bearophile
so when you print the tape you trim the blanks away at both ends. A wrong trimming code: string toString() const { // Blank-stripped tape. const t2 = tape .find!(c => c != blank)() .retro() .find!(c => c != blank)() .retro();

Re: static class

2013-02-17 Thread Steven Schveighoffer
On Sun, 17 Feb 2013 17:00:19 -0500, Michael wrote: That's not the meaning of static in that context. As I understand a static class can't be instantiated. Static in that position is a no-op. The compiler (infuriatingly sometimes) accepts attributes that have no meaning silently. So i

Re: static class

2013-02-17 Thread Michael
That's not the meaning of static in that context. As I understand a static class can't be instantiated. The above is useful in nested classes. I just read it. Holy s.. cow. Instead you can use: class Test { static: void foo() { } } So in mine case if I want purely static class I nee

Re: A little of coordination for Rosettacode

2013-02-17 Thread bearophile
Jos van Uden: I've split the tape in left and right. It does make the code a bit harder to understand and debug. You have used three tapes and a unsigned position, while I think a signed position and two tapes is enough: static struct TapeHead { immutable Symbol blank; Symbol[] tape

Re: static class

2013-02-17 Thread Andrej Mitrovic
On 2/17/13, Michael wrote: > Why members of static class are not implicitly static? > > static class Test > { > void foo() {} > } > That's not the meaning of static in that context. The above is useful in nested classes. Instead you can use: class Test { static: void foo() { } }

static class

2013-02-17 Thread Michael
Why members of static class are not implicitly static? static class Test { void foo() {} } Error: need 'this' for foo type void()

Re: How to dynamically alias a struct to a byte array?

2013-02-17 Thread jerro
The only thing I've though of so far is to declare a class that holds a bunch of abstract methods, and then have multiple descendants that each have a special variant of the struct. And even then I've either got to copy it again, or to cast it each time I use it. (Though at least with this ap

How to dynamically alias a struct to a byte array?

2013-02-17 Thread Charles Hixson
The situation is I have a C library routine that returns a pointer to a malloc_ed byte array. The handler routine that I've written immediately copies the unmanaged byte array to a byte[], and then calls std.stdlib.free(barray). Then it returns the byte array. So I've already copied it once.

Re: A little of coordination for Rosettacode

2013-02-17 Thread Jos van Uden
On 16-2-2013 21:23, bearophile wrote: Jos van Uden: Yes, that was your original suggestion, but I didn't quite understand it, When you don't understand something I say, please ask for more info :-) You would reverse the left array when printing, is that correct? Right, the second half of

Re: How to interface to a C struct with volatile variables?

2013-02-17 Thread Charles Hixson
On 02/16/2013 08:16 AM, Ben Davis wrote: On 16/02/2013 15:19, Jacob Carlborg wrote: On 2013-02-16 15:13, Ben Davis wrote: As for 'volatile', there's some info at http://dlang.org/deprecate.html#volatile about how it used to be available for marking statements as 'do not optimise field accesses'

Re: Is there a weak pointer or references in D?

2013-02-17 Thread Charles Hixson
On 01/13/2013 09:01 PM, Alex Rønne Petersen wrote: On 14-01-2013 00:18, Charles Hixson wrote: On 01/12/2013 09:24 PM, Alex Rønne Petersen wrote: On 11-01-2013 19:15, Charles Hixson wrote: I was looking for a way to create a weak reference to either a struct or a class. I need to be able to use

Re: How to specify number of worker threads for Taskpool

2013-02-17 Thread Sparsh Mittal
Thanks a lot for your reply. It was very helpful.

Re: How to specify number of worker threads for Taskpool

2013-02-17 Thread Ali Çehreli
On 02/17/2013 08:23 AM, Sparsh Mittal wrote: > I am seeing > > http://dlang.org/phobos/std_parallelism.html#.TaskPool Please also consider: http://ddili.org/ders/d.en/parallelism.html > I am running the example of parallel foreach given in that section. > > Sorry if it is too obvious, but my

SocketStream and weird 0xA character

2013-02-17 Thread Lubos Pintes
I am writing little program which downloads simple data file from server through HTTP. The file is static, but updated regularly, so I am using "Range: bytes" header to optimize the traffic a bit. After I analyzed HTTP status line and headers, I started to read the raw data through SocketStream.

Re: Issues with std.regex

2013-02-17 Thread Dmitry Olshansky
17-Feb-2013 01:36, MrAppleseed пишет: On Saturday, 16 February 2013 at 20:33:15 UTC, FG wrote: On 2013-02-16 21:22, MrAppleseed wrote: auto reg = regex("[ 0-9a-zA-Z.*=+-;()\"\'\[\]<>,{}^#/\\]"); When I try to run the code above, I get: parser.d(64): Error: undefined escape sequence \[ parser.d