Raw Binary into the console

2014-07-12 Thread Sean Campbell via Digitalmars-d-learn
How Can I Print Raw Binary Into The Console? I Have Variable Of Type ubyte which equals 0b011 How Can I Get The Variable To Print Out As 011

Re: Raw Binary into the console

2014-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 07/11/2014 10:56 PM, Sean Campbell wrote: How Can I Print Raw Binary Into The Console? Taking a step back, a D program prints to stdout, not console. However, in most cases a D program's output ends up on the console when it is started in a console. So, one can print any byte value to

Const problems

2014-07-12 Thread bearophile via Digitalmars-d-learn
In case you have missed the thread: http://www.reddit.com/r/programming/comments/2ag8qe/the_constness_problem/ Bye, bearophile

Something like Python's psutils for D?

2014-07-12 Thread Thomas Mader via Digitalmars-d-learn
The Subject says it all, is something like psutils available in D? [1] I need it to measure memory usage of a process. [1] https://github.com/giampaolo/psutil thank you Thomas

Re: Something like Python's psutils for D?

2014-07-12 Thread Thomas Mader via Digitalmars-d-learn
I also need to get the user and system time of a process, doesn't seem to be available in Phobos. (e.g. getrusage in Linux but platform independent)

Re: Value Reference Type Traits

2014-07-12 Thread Nordlöw
On Friday, 11 July 2014 at 16:22:37 UTC, anonymous wrote: There's http://dlang.org/phobos/std_traits.html#hasIndirections Thx.

Help to find crash in simple stack type?

2014-07-12 Thread Gary Willoughby via Digitalmars-d-learn
I've created a simple stack type using calloc/free which seems to work nicely. Then instead of using C functions i've tried to implement the same type using the GC. However i'm experiencing a crash. I've been staring at this snippet for hours now any help would be appreciated. This is a

Re: Help to find crash in simple stack type?

2014-07-12 Thread Rainer Schuetze via Digitalmars-d-learn
On 12.07.2014 16:24, anonymous wrote: No explanation or solution, but a reduction: import core.memory; void main() { alias T = ubyte; enum size1 = 2_049; /* 2_048 = 2^^11 */ enum size2 = 1_048_577; /* 1_048_576 = 2^^20 */ T* _data; _data =

Re: Help to find crash in simple stack type?

2014-07-12 Thread Rainer Schuetze via Digitalmars-d-learn
On 12.07.2014 19:05, Rainer Schuetze wrote: Thanks for the reduction. GC.realloc seems broken for reallocations to sizes larger than the current GC pool. Please file a bug report. Actually done that myself: https://issues.dlang.org/show_bug.cgi?id=13111

OSX, Need help with Compiling and linking errors

2014-07-12 Thread Israel Rodriguez via Digitalmars-d-learn
Ive been reading the OSX notes for the DMD compiler but not everything is clear to me as i dont know how exactly the compiler looks for things. i wanted to test it out first using this package from code.dlang.org http://code.dlang.org/packages/colorize I downloaded the zip, extracted it, and

DStyle: Braces on same line

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn
Hi, I noticed that in Andrei's talks and his book, he used braces on the same line of delcaration, however Phobos and other D libraries I know use braces on their own line. Now I'm in a position where I need to take decision on coding style of my library and I get accustomed to use braces on

struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
Please consider the following struct arc(T,U) { T some_var; U someother_var; } /* things */ class myclass { this(){} ~this(){} void MYfunction() { arc!(string, string[]) * a; a.some_var = hello; } } void main() { c = new myclass(); c.MYfunction(); } This leads to a

Re: struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
Also, (*c).MYfunction() is leading to segmentation fault

Re: struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
sorry, I meant (*a).some_var not (*c).MYfunction()

Re: struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:16:52 UTC, Danyal Zia wrote: On Saturday, 12 July 2014 at 19:09:44 UTC, seany wrote: Please consider the following struct arc(T,U) { T some_var; U someother_var; } /* things */ class myclass { this(){} ~this(){} void MYfunction() { arc!(string,

Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:19:28 UTC, seany wrote: For reasons further down in the software, I need to do this with a pointer. How do I do it with a pointer, please? I don't know what are you trying to achieve, but if that's what you want, you can do: void MYfunction() { auto

Re: struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
do I have to initialize all variables of the struct? or may I also use a this(){} in the struct and initialize only those which are known at a given moment?

Re: struct template help

2014-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 07/12/2014 12:19 PM, seany wrote: On Saturday, 12 July 2014 at 19:16:52 UTC, Danyal Zia wrote: On Saturday, 12 July 2014 at 19:09:44 UTC, seany wrote: arc!(string, string[]) * a; a.some_var = hello; a has not been instantiated. You are declaring it as a pointer to struct and

Re: struct template help

2014-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 07/12/2014 12:32 PM, seany wrote: do I have to initialize all variables of the struct? No. The uninitialized ones get their .init values. or may I also use a this(){} in the struct and initialize only those which are known at a given moment? That already works with structs. You don't

Re: DStyle: Braces on same line

2014-07-12 Thread Dicebot via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:01:56 UTC, Danyal Zia wrote: Should I worry about it? Or is that's just a debatable style that won't really matter if it's persistent throughout library? Depends entirely on whenever you want to match style of standard library - no one will blame you for having

Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:32:48 UTC, seany wrote: do I have to initialize all variables of the struct? or may I also use a this(){} in the struct and initialize only those which are known at a given moment? You can initialize in constructor this(), but you can't initialize partial

Re: DStyle: Braces on same line

2014-07-12 Thread anonymous via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:01:56 UTC, Danyal Zia wrote: Hi, I noticed that in Andrei's talks and his book, he used braces on the same line of delcaration, however Phobos and other D libraries I know use braces on their own line. Now I'm in a position where I need to take decision on

Re: struct template help

2014-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 07/12/2014 12:38 PM, Danyal Zia wrote: You can initialize in constructor this(), but you can't initialize partial fields of struct when using pointer to struct. Actually, that works too but members must be initialized from the beginning. The trailing ones are left with .init values:

Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:42:13 UTC, Ali Çehreli wrote: Actually, that works too but members must be initialized from the beginning. The trailing ones are left with .init values: struct S { int i; string s; } void main() { auto s = new S(42); static assert(is (typeof(s)

Re: DStyle: Braces on same line

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:35:11 UTC, anonymous wrote: There is another stylistic choice which I do find confusing: capitalized identifiers for non-types, e.g. variables and functions. Please don't do that. Agreed about variables and functions. However I personally prefer to use

Template help

2014-07-12 Thread Anonymous via Digitalmars-d-learn
I got to typing one day and came up with this. What it does is search an aggregate for a member named match. If it's a direct member, it evaluates to that. If it's not, then it searches any aggregate type sub-members (deep members) for match. If there's only one deep member tree with match, it

Re: Template help

2014-07-12 Thread Anonymous via Digitalmars-d-learn
One way I've used it in code struct MapBy(T,string key) if (hasDeepMember!(T,key)) { alias key_t = DeepMemberType!(T,key); private const(T)[key_t] _map; bool has(key_t id) const nothrow { if ((id in _map) != null) return true; else return

Re: Insert a char in string

2014-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 07/10/2014 09:05 AM, Alexandre wrote: I have a string X and I need to insert a char in that string... auto X = 100; And I need to inser a ',' in position 3 of this string..., I try to use the array.insertInPlace, but, not work... I try this: auto X = 100; auto N =

Re: Something like Python's psutils for D?

2014-07-12 Thread Ellery Newcomer via Digitalmars-d-learn
On Saturday, 12 July 2014 at 08:34:41 UTC, Thomas Mader wrote: The Subject says it all, is something like psutils available in D? would psutils itself be acceptable? https://bitbucket.org/ariovistus/pyd

Re: I don't get it. version(unittest) can't seem to use local variable

2014-07-12 Thread dysmondad via Digitalmars-d-learn
. try: unittest { Velocity v = new Velocity( 2.0f, 5.0f ); v *= 5.0f; // - line 110 printf( v = %s\n, to!string(v) ); } instead. Basically version is like static if, it doesn't indicate its a function. Instead it changes what code gets compiled. Where as a unittest

Re: I don't get it. version(unittest) can't seem to use local variable

2014-07-12 Thread Rikki Cattermole via Digitalmars-d-learn
On 13/07/2014 2:35 p.m., dysmondad wrote: . try: unittest { Velocity v = new Velocity( 2.0f, 5.0f ); v *= 5.0f; // - line 110 printf( v = %s\n, to!string(v) ); } instead. Basically version is like static if, it doesn't indicate its a function. Instead it changes what

Re: I don't get it. version(unittest) can't seem to use local variable

2014-07-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jul 13, 2014 at 02:35:11AM +, dysmondad via Digitalmars-d-learn wrote: [...] So, what is the generally accepted way include unit testing? TDD is all the rage these days and I though I would try my hand at it as well as D. Just include unittest blocks in your program and compile

Re: I don't get it. version(unittest) can't seem to use local variable

2014-07-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jul 13, 2014 at 02:39:00AM +, dysmondad via Digitalmars-d-learn wrote: On Saturday, 12 July 2014 at 05:23:29 UTC, Ali Çehreli wrote: On 07/11/2014 10:08 PM, dysmondad wrote: class Velocity { [...] ref Velocity opOpAssign(string op) ( in float multiplier )

Re: I don't get it. version(unittest) can't seem to use local variable

2014-07-12 Thread dysmondad via Digitalmars-d-learn
... https://github.com/rikkimax/skeleton/blob/master/source/skeleton/syntax/download_mkdir.d#L175 Of course there will be better ones, just something I was doing last night however. Thanks for the link and the information. That's looks like what I need so I'm going to rip off your code

Re: DStyle: Braces on same line

2014-07-12 Thread dysmondad via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:01:56 UTC, Danyal Zia wrote: Hi, I noticed that in Andrei's talks and his book, he used braces on the same line of delcaration, however Phobos and other D libraries I know use braces on their own line. Now I'm in a position where I need to take decision on

Re: I don't get it. version(unittest) can't seem to use local variable

2014-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 07/12/2014 08:37 PM, H. S. Teoh via Digitalmars-d-learn wrote: ref makes it possible for the caller to modify the pointer returned by the callee. For example: class D { int x; } class C { D d; this(D _d) { d = _d; } ref D getPtr() { return d; }

Re: I don't get it. version(unittest) can't seem to use local variable

2014-07-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jul 12, 2014 at 09:30:44PM -0700, H. S. Teoh via Digitalmars-d-learn wrote: On Sat, Jul 12, 2014 at 09:20:06PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] The twist here is that the OP's function returned 'this' by reference. Changing that not only not have any effect

Re: OSX, Need help with Compiling and linking errors

2014-07-12 Thread Israel Rodriguez via Digitalmars-d-learn
On Sunday, 13 July 2014 at 01:53:10 UTC, Mike Parker wrote: On 7/13/2014 3:54 AM, Israel Rodriguez wrote: The linker errors do not refer to libcolorize. Notice this: _D4dlib4math6matrix. That is a dlib.math.matrix module. Is that a source module in your project or something from another