Re: get number of items in DList

2014-07-15 Thread pgtkda via Digitalmars-d-learn
On Friday, 11 July 2014 at 14:48:26 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Fri, Jul 11, 2014 at 10:23:58AM -0300, Ary Borenszweig via Digitalmars-d-learn wrote: On 7/11/14, 4:46 AM, bearophile wrote: pgtkda: How can i get the number of items which are currently hold in a DList?

Get folders in path

2014-07-15 Thread pgtkda via Digitalmars-d-learn
How can i get all folders from a given path?

Re: Get folders in path

2014-07-15 Thread sigod via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 08:31:10 UTC, pgtkda wrote: How can i get all folders from a given path? If I understood you correctly: http://dlang.org/phobos/std_file.html#.dirEntries

Re: Get folders in path

2014-07-15 Thread pgtkda via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 08:38:30 UTC, sigod wrote: On Tuesday, 15 July 2014 at 08:31:10 UTC, pgtkda wrote: How can i get all folders from a given path? If I understood you correctly: http://dlang.org/phobos/std_file.html#.dirEntries Thanks, that's exactly what i was looking for.

Re: DMDScript

2014-07-15 Thread Chris via Digitalmars-d-learn
On Monday, 14 July 2014 at 21:22:12 UTC, Jason King wrote: My idea is to use (at least test) DMDScript for server side JS. I don't mean to sound like a D-hater here, but V8 has had about 2 years more work on it than DMDScript. At one time they were. IIRC, quite close performance-wise but

Read whole file

2014-07-15 Thread pgtkda via Digitalmars-d-learn
How can i read the whole file if i use this: File(C:\\Users\\text\\Desktop\\test.csv, r);

Re: is there a way to pause a program and resume with just a key press (or enter key)

2014-07-15 Thread rumbu via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 02:49:56 UTC, WhatMeWorry wrote: Sorry if this is an incredibly naive question. I prefer to pragmatically pause my programs periodically so that I can peruse output statements. Ideally, I'd like to continue by just hitting any old key. My feeble attempt below

Re: Read whole file

2014-07-15 Thread bearophile via Digitalmars-d-learn
pgtkda: How can i read the whole file if i use this: File(C:\\Users\\text\\Desktop\\test.csv, r); In std.file there are two functions to read a file or read a text file, named read and readText. Bye, bearophile

Re: get number of items in DList

2014-07-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Fri, 11 Jul 2014 07:46:37 -0700 H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Fri, Jul 11, 2014 at 10:23:58AM -0300, Ary Borenszweig via Digitalmars-d-learn wrote: On 7/11/14, 4:46 AM, bearophile wrote: pgtkda: How can i get the number of items which

lazy construction of an immutable object

2014-07-15 Thread Puming via Digitalmars-d-learn
Hi, I'd like to use immutable data, but instead of a one time constructor, I would like to `build` the data lazily, by setting its fields separately. In java version of protocol-buffer, there is a pattern for this mechanism: 1. Every data class in protobuf is immutable. 2. Each data class

Re: new properties for basic types

2014-07-15 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 05:26:57 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: @property allows you to call a function without the parenthesis (), to imitate a field in a struct or class. Ah, ok. That means without @property I would need to write defaultInit!T() instead of

Re: Compile time regex matching

2014-07-15 Thread Jason den Dulk via Digitalmars-d-learn
On Monday, 14 July 2014 at 11:43:01 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: You can try Pegged, a parser generator that works at compile-time (both the generator and the generated parser). I did, and I got it to work. Unfortunately, the code used to in the CTFE is left in the

phobos iterate through json subkeys?

2014-07-15 Thread Sean Campbell via Digitalmars-d-learn
How Can I Iterate through JSON Subkeys using std.json? Or Do I Have To Use An External Library For that

String to int exception

2014-07-15 Thread Alexandre via Digitalmars-d-learn
Hi :) I made this function to inverse the bytes in intger or T (possible) type... int reverseBytes(T)(T val) { int retVal = 0; static if(is(T == string)) retVal = to!int(val); return (retVal 0x00FF) 24 | (retVal 0xFF00) 8

Re: String to int exception

2014-07-15 Thread bearophile via Digitalmars-d-learn
Alexandre: return (retVal 0x00FF) 24 | (retVal 0xFF00) 8 | (retVal 0x00FF) 8 | (retVal 0xFF00) 24; See also core.bitop.bswap. Bye, bearophile

Re: lazy construction of an immutable object

2014-07-15 Thread Puming via Digitalmars-d-learn
I found another way to do this, namely first create a class that is mutable, then cast it to an immutable object before using it. ```d class A { int a; B b; this(int a, int b) { this.a = a; this.b = new B(b); } } class B

Re: String to int exception

2014-07-15 Thread Alexandre via Digitalmars-d-learn
Thanks, but, when I convert I recive a 'c' in the front of my number... uint reverseBytes(uint val) { import core.bitop : bitswap; return bitswap(val); } //... writefln(%x, reverseBytes(0x00402030)); //... // output: c040200 On Tuesday, 15 July 2014 at 12:16:26 UTC,

Re: String to int exception

2014-07-15 Thread bearophile via Digitalmars-d-learn
Alexandre: Thanks, but, when I convert I recive a 'c' in the front of my number... This shows it inverts all bits, not just the four byte positions. I don't understand: import core.bitop: bitswap; uint reverseBytes(in uint val) pure nothrow @safe @nogc { return val.bitswap; } void

Re: String to int exception

2014-07-15 Thread Alexandre via Digitalmars-d-learn
Something is wrong between our communication... I am wanting to do something better to order the bytes, for this my code... https://gist.github.com/bencz/3576dfc8a217a34c05a9 For example, in that case: injectData(image[0x207], x30204000); It's more simple to use something like:

Re: String to int exception

2014-07-15 Thread Ali Çehreli via Digitalmars-d-learn
On 07/15/2014 04:56 AM, Alexandre wrote: retVal = to!int(val); std.conv.ConvException@C:\D\dmd2\src\phobos\std\conv.d(1968): Unexpected '@' when converting from type string to type int That means to!int failed because 'val' contained a '@' character in it: import std.conv; void

Re: lazy construction of an immutable object

2014-07-15 Thread Ali Çehreli via Digitalmars-d-learn
On 07/15/2014 05:20 AM, Puming wrote: I found another way to do this, namely first create a class that is mutable, then cast it to an immutable object before using it. ```d class A { int a; B b; this(int a, int b) { this.a = a; this.b = new B(b); } }

Re: String to int exception

2014-07-15 Thread anonymous via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 14:05:14 UTC, Alexandre wrote: Strange..., why '@' ? because x40 == @

Re: String to int exception

2014-07-15 Thread safety0ff via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 12:24:48 UTC, Alexandre wrote: Thanks, but, when I convert I recive a 'c' in the front of my number... uint reverseBytes(uint val) { import core.bitop : bitswap; return bitswap(val); } You confused bswap with bitswap. The former reverses bytes,

Re: String to int exception

2014-07-15 Thread Alexandre via Digitalmars-d-learn
Strange..., why '@' ? PS: Ali Çehreli, thanks for your book, your book is wonderful!!! On Tuesday, 15 July 2014 at 13:49:51 UTC, Ali Çehreli wrote: On 07/15/2014 04:56 AM, Alexandre wrote: retVal = to!int(val); std.conv.ConvException@C:\D\dmd2\src\phobos\std\conv.d(1968):

Re: SImple C++ code to D

2014-07-15 Thread bearophile via Digitalmars-d-learn
Alexandre: RefCounted!(DWORD) addr; I think RefCounted is for advanced usages in D :-) template Wrap(T) { struct Wrap { T val; this(T val){val = val;} } } Simpler: struct Wrap(T) { T val; this(T val_) { this.val =

Re: SImple C++ code to D

2014-07-15 Thread Alexandre via Digitalmars-d-learn
Oh! I used the RefCounted because this: The proposed C++ shared_ptr, which implements ref counting, suffers from all these faults. I haven't seen a heads up benchmark of shared_ptr vs mark/sweep, but I wouldn't be surprised if shared_ptr turned out to be a significant loser in terms of both

Re: SImple C++ code to D

2014-07-15 Thread Alexandre via Digitalmars-d-learn
I have this struct: enum AddrType { Abs, RVA, Rel }; struct Address { shared_ptrDWORD addr; AddrType type; Address(): type(Abs) {} Address(DWORD addr, AddrType type): addr(shared_ptrDWORD(new DWORD(addr))), type(type) {} Address(shared_ptrDWORD addr, AddrType type):

Re: SImple C++ code to D

2014-07-15 Thread bearophile via Digitalmars-d-learn
Alexandre: as rc is better for managing scarce resources like file handles. File instances are ref counted in D. Is this useful for you? Bye, bearophile

Re: Compile time regex matching

2014-07-15 Thread Philippe Sigaud via Digitalmars-d-learn
I did, and I got it to work. Unfortunately, the code used to in the CTFE is left in the final executable even though it is not used at runtime. So now the question is, is there away to get rid of the excess baggage? Not that I know of. Once code is injected, it's compiled into the executable.

Re: lazy construction of an immutable object

2014-07-15 Thread Puming via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 13:59:24 UTC, Ali Çehreli wrote: On 07/15/2014 05:20 AM, Puming wrote: I found another way to do this, namely first create a class that is mutable, then cast it to an immutable object before using it. ```d class A { int a; B b; this(int a, int b) {

Re: SImple C++ code to D

2014-07-15 Thread Alexandre via Digitalmars-d-learn
Yes yes, I will use the ref... is more safer! I will try to re-create my logic... btw, how is the best way to reinterpret this ??: mapstring, Address syms; and: vectorpairDWORD, Address values; vectorpairDWORD, shared_ptrDWORD addrs; On Tuesday, 15 July 2014 at 14:55:36 UTC, bearophile wrote:

Re: SImple C++ code to D

2014-07-15 Thread bearophile via Digitalmars-d-learn
Alexandre: mapstring, Address syms; If you don't need the key ordering then use a built-in associative array: Address[string] syms; Otherwise use a RedBlackTree from std.container. vectorpairDWORD, Address values; vectorpairDWORD, shared_ptrDWORD addrs; Tuple!(DWORD, Address)[]

Handle to some object, call its methods

2014-07-15 Thread Anonymous via Digitalmars-d-learn
struct Subscription { const Object handle; private immutable size_t index; @disable this(); private this(Object o, size_t i) { handle = o; index = i; } } I'd like this to be constructed with a handle to some object, and

Re: reference to delegates and garbage collection

2014-07-15 Thread Kagamin via Digitalmars-d-learn
Since you access a field through `a` instance, this is usually done by loading the instance address into some register and reading from a location at a certain offset from that register mov esi, [ebp-4] # the instance address mov eax, [esi+8] # first field ... mov [ebp-4], 0 # clear stack

Re: Handle to some object, call its methods

2014-07-15 Thread Ali Çehreli via Digitalmars-d-learn
On 07/15/2014 09:39 AM, Anonymous wrote: struct Subscription { const Object handle; private immutable size_t index; @disable this(); private this(Object o, size_t i) { handle = o; index = i; } } I'd like this to be constructed with a handle

Re: lazy construction of an immutable object

2014-07-15 Thread Meta via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 15:48:10 UTC, Puming wrote: wow, that's interesting :-) Is it the idiomatic approach to initiate immutable objects lazily? Or do people use data class with immutable fields and generate a companion builder class at compile time? There's no real idiomatic approach,

Re: SImple C++ code to D

2014-07-15 Thread Ali Çehreli via Digitalmars-d-learn
On 07/15/2014 07:40 AM, Alexandre wrote: I have this struct: I think many short discussion threads are more efficient than a single long thread. Many different C++ and D concepts are making this thread difficult to follow for me. :) Ali

Re: new properties for basic types

2014-07-15 Thread via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 05:26:57 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: @property allows you to call a function without the parenthesis (), to imitate a field in a struct or class. That was the original idea, but today the situation is that for all argument-less method calls

Re: Generating Strings with Random Contents

2014-07-15 Thread bearophile via Digitalmars-d-learn
Nordlöw: Could someone elaborate shortly which cases this means? All cases where you really can't live without it :-) It's like a cast(. Bye, bearophile

Re: Generating Strings with Random Contents

2014-07-15 Thread Nordlöw
On Tuesday, 15 July 2014 at 00:03:04 UTC, bearophile wrote: to avoid using @trusted in most cases. Could someone elaborate shortly which cases this means?

Regex match in for loop

2014-07-15 Thread seany via Digitalmars-d-learn
Consider this: import std.stdio, std.regex, std.array, std.algorithms ; void main(string args[]) { string[] greetings = [hello, hallo, hoi, salut]; regex r = regex(hello, g); for(short i = 0; i greetings.count(); i++) { auto m = match(greetings[i], r); } } To the best of my knowledge,

Re: Regex match in for loop

2014-07-15 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 15, 2014 at 08:18:55PM +, seany via Digitalmars-d-learn wrote: Consider this: import std.stdio, std.regex, std.array, std.algorithms ; void main(string args[]) { string[] greetings = [hello, hallo, hoi, salut]; regex r = regex(hello, g); for(short i = 0; i

Re: Regex match in for loop

2014-07-15 Thread Brad Anderson via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 20:18:58 UTC, seany wrote: Consider this: import std.stdio, std.regex, std.array, std.algorithms ; void main(string args[]) { string[] greetings = [hello, hallo, hoi, salut]; regex r = regex(hello, g); for(short i = 0; i greetings.count(); i++) { auto m =

Extended math library

2014-07-15 Thread Martijn Pot via Digitalmars-d-learn
To make a long story short: Is there any math library with e.g. mean, std, polynomial fitting, ...?

Re: is there a way to pause a program and resume with just a key press (or enter key)

2014-07-15 Thread Meta via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 10:22:52 UTC, rumbu wrote: getch() reads any key and continues; On Windows you can pipe you executable with the more command to pause after each page: your.exe | more Don't forget that getch() is also Windows-specific.

Re: is there a way to pause a program and resume with just a key press (or enter key)

2014-07-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 02:49:56 UTC, WhatMeWorry wrote: Is there a way to continue with any old key press? or just the enter key? Yeah. It is more complex than you'd think but my terminal library can do it: https://github.com/adamdruppe/arsd/blob/master/terminal.d Example usage:

Re: is there a way to pause a program and resume with just a key press (or enter key)

2014-07-15 Thread ponce via Digitalmars-d-learn
I don't know about Windows, but on Linux, you can just press ctrl-s and ctrl-q to pause/resume the console. (This is a Linux terminal function, not specific to D.) In the Windows shell, the pause key will halt a program and return will resume it.

Re: Extended math library

2014-07-15 Thread ponce via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 20:46:32 UTC, Martijn Pot wrote: To make a long story short: Is there any math library with e.g. mean, std, polynomial fitting, ...? https://github.com/kyllingstad/scid https://github.com/dsimcha/dstats

Re: Generating Strings with Random Contents

2014-07-15 Thread Nordlöw
On Tuesday, 15 July 2014 at 18:50:06 UTC, bearophile wrote: All cases where you really can't live without it :-) It's like Hmm. I guess I'm gonna have to remove some @trusted tagging then ;)

what is exactly stack stomp -gx new switch ?

2014-07-15 Thread Klb via Digitalmars-d-learn
...and any example where this switch will be usefull ?

Re: what is exactly stack stomp -gx new switch ?

2014-07-15 Thread bearophile via Digitalmars-d-learn
Klb: ...and any example where this switch will be usefull ? I guess it was added to D in the spirit of If you have to ask what it is, then you don't need to use it. More seriously, I too would like more documentation about its use cases. Bye, bearophile

Re: what is exactly stack stomp -gx new switch ?

2014-07-15 Thread Ali Çehreli via Digitalmars-d-learn
On 07/15/2014 04:33 PM, bearophile wrote: Klb: ...and any example where this switch will be usefull ? I guess it was added to D in the spirit of If you have to ask what it is, then you don't need to use it. More seriously, I too would like more documentation about its use cases. Bye,

Re: what is exactly stack stomp -gx new switch ?

2014-07-15 Thread Ali Çehreli via Digitalmars-d-learn
On 07/15/2014 04:56 PM, Ali Çehreli wrote: char buffer[100]; [...] char buffer[100] = void; Before others point out, those are in C syntax by mistake. :) They should preferably be: char[100] buffer; [...] char[100] buffer = void; Ali

Re: lazy construction of an immutable object

2014-07-15 Thread Puming via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 17:09:04 UTC, Meta wrote: On Tuesday, 15 July 2014 at 15:48:10 UTC, Puming wrote: wow, that's interesting :-) Is it the idiomatic approach to initiate immutable objects lazily? Or do people use data class with immutable fields and generate a companion builder class

Re: Handle to some object, call its methods

2014-07-15 Thread Anonymous via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 17:06:14 UTC, Ali Çehreli wrote: On 07/15/2014 09:39 AM, Anonymous wrote: struct Subscription { const Object handle; private immutable size_t index; @disable this(); private this(Object o, size_t i) { handle = o; index =

Re: lazy construction of an immutable object

2014-07-15 Thread Jason den Dulk via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 12:20:57 UTC, Puming wrote: @property immutable(T) freeze(T)(T obj) { return cast(immutable(T))(obj); } What is the idiomatic approach to do this in D? There is a Phobos function std.exception.assumeUnique which performs this for arrays. According to

How can I express the type '(int) = int' where it is a function or a delegate

2014-07-15 Thread Puming via Digitalmars-d-learn
I'd like to have a Command class, where their is a name and a handler field: ```d class Command { string name; string delegate(string[]) handler; } ``` this is ok, but sometimes I want the handler also accept a function (lambdas are init to functions if no capture of outer scope

Re: How can I express the type '(int) = int' where it is a function or a delegate

2014-07-15 Thread Rikki Cattermole via Digitalmars-d-learn
On 16/07/2014 3:50 p.m., Puming wrote: I'd like to have a Command class, where their is a name and a handler field: ```d class Command { string name; string delegate(string[]) handler; } ``` this is ok, but sometimes I want the handler also accept a function (lambdas are init to