Re: Real OOP with D

2015-08-16 Thread Rikki Cattermole via Digitalmars-d-learn
On 17/08/2015 5:57 p.m., Ozan wrote: Hi Working with objectoriented concepts results often in large trees of related classes. Every instance of a class knows his methods and data. An example like following would work: import std.stdio; class Family { } class Dad : Family { void greeting() { wri

Re: Real OOP with D

2015-08-16 Thread Ali Çehreli via Digitalmars-d-learn
On 08/16/2015 10:57 PM, Ozan wrote: > Working with objectoriented concepts results often in large trees of > related classes. Every instance of a class knows his methods and data. > An example like following would work: > > import std.stdio; > class Family { } From the way you use it below, a be

Real OOP with D

2015-08-16 Thread Ozan via Digitalmars-d-learn
Hi Working with objectoriented concepts results often in large trees of related classes. Every instance of a class knows his methods and data. An example like following would work: import std.stdio; class Family { } class Dad : Family { void greeting() { writeln("I'm dad"); } } class Boy : F

Re: pragma(mangle, on a template)

2015-08-16 Thread BBasile via Digitalmars-d-learn
On Monday, 17 August 2015 at 02:46:02 UTC, Freddy wrote: I can't get pragma(mangle) to work on templates(or structs). [...] I don't know why but it looks like it only works on functions. Even if a struct is not a template the custom symbol mangle won't be handled: --- import std.stdio; pra

Re: pragma(mangle, on a template)

2015-08-16 Thread Freddy via Digitalmars-d-learn
On Monday, 17 August 2015 at 03:14:16 UTC, Adam D. Ruppe wrote: On Monday, 17 August 2015 at 02:46:02 UTC, Freddy wrote: Mangling is done at a different level in the compiler than aliases, so I don't think this is intended to work. Is there any way I can mangle a template struct then?

Re: pragma(mangle, on a template)

2015-08-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 17 August 2015 at 02:46:02 UTC, Freddy wrote: pragma(mangle, "MyAlias") alias MyAlias = MyStruct!("a", "b", "c" /+very long symbol bloating list+/ ); Mangling is done at a different level in the compiler than aliases, so I don't think this is intended to work.

Re: Weird error message.

2015-08-16 Thread BBasile via Digitalmars-d-learn
On Monday, 17 August 2015 at 00:00:11 UTC, Jonathan M Davis wrote: On Sunday, August 16, 2015 21:32:08 Warwick via Digitalmars-d-learn wrote: Dont know what to make of this, I pretty much get it every other time I call rdmd. It'll alternate between running fine and then giving me this error...

Re: Pointers to Dynamic Arrays

2015-08-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 17 August 2015 at 02:45:22 UTC, Brandon Ragland wrote: Since Dynamic Arrays / Slices are a D feature, using pointers to these has me a bit confused... Short answer: pointers to slices are usually a mistake, you probably don't actually want it, but rather should be using a regular s

Re: Pointers to Dynamic Arrays

2015-08-16 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 17 August 2015 at 02:45:22 UTC, Brandon Ragland wrote: Howdy, Since Dynamic Arrays / Slices are a D feature, using pointers to these has me a bit confused... Consider: Now what is especially confusing about this, is that the above seems to works fine, while this does not: if(

Re: Pointers to Dynamic Arrays

2015-08-16 Thread Freddy via Digitalmars-d-learn
On Monday, 17 August 2015 at 02:45:22 UTC, Brandon Ragland wrote: if(file[(*pos + i)] == '}'){ *pos += i; return; } That code doesn't do what you want it do. file is a ((char[])*) you are indexing the pointer(accessing invalid memory) and getting a char[].

pragma(mangle, on a template)

2015-08-16 Thread Freddy via Digitalmars-d-learn
I can't get pragma(mangle) to work on templates(or structs). import std.stdio; struct MyStruct(T...) { int var; void func() { writeln(var); } } pragma(mangle, "MyAlias") alias MyAlias = MyStruct!("a", "b", "c" /+very long symbol bloating list+/ ); void main() {

Pointers to Dynamic Arrays

2015-08-16 Thread Brandon Ragland via Digitalmars-d-learn
Howdy, Since Dynamic Arrays / Slices are a D feature, using pointers to these has me a bit confused... Consider: string c2s(int* pos, char[]* file, int l){ char[] s; for(int i = 0; i < l; i++){ s ~= file[(*pos + i)]; } return s.dup; } Now what

Re: App Build Error

2015-08-16 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 16 August 2015 at 17:33:52 UTC, Benjamin wrote: I'm having an issue with building my app - even a simple trivial app (shown below). [...] OS X version? Have you configured your dmd.conf? iirc it requires linker path changes or something. Have you looked in /usr/local/lib for li

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 16 August 2015 at 23:40:41 UTC, Brandon Ragland wrote: On Sunday, 16 August 2015 at 23:31:46 UTC, Ali Çehreli wrote: On 08/16/2015 04:13 PM, Brandon Ragland wrote: > That makes more sense. Though it does make the ref method > signature unclear, as it only applies to literals at this

Re: Weird error message.

2015-08-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, August 16, 2015 21:32:08 Warwick via Digitalmars-d-learn wrote: > Dont know what to make of this, I pretty much get it every other > time I call rdmd. It'll alternate between running fine and then > giving me this error... > > C:\Program Files (x86)\Notepad++>rdmd J:\Code\statproc.d > st

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Brandon Ragland via Digitalmars-d-learn
On Sunday, 16 August 2015 at 23:31:46 UTC, Ali Çehreli wrote: On 08/16/2015 04:13 PM, Brandon Ragland wrote: > That makes more sense. Though it does make the ref method > signature unclear, as it only applies to literals at this > point? As long as the returned object will be valid after the fu

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Ali Çehreli via Digitalmars-d-learn
On 08/16/2015 04:13 PM, Brandon Ragland wrote: > That makes more sense. Though it does make the ref method > signature unclear, as it only applies to literals at this > point? As long as the returned object will be valid after the function leaves, it can be anything: one of the ref parameters,

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Brandon Ragland via Digitalmars-d-learn
On Sunday, 16 August 2015 at 22:35:15 UTC, Alex Parrill wrote: On Sunday, 16 August 2015 at 22:31:02 UTC, Brandon Ragland wrote: Hi All, I'm a bit confused as to how Classes in D are passed in arguments and returns. Take this for example: class MyClass{ int x = 2; } And then in app.d ref My

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread Ali Çehreli via Digitalmars-d-learn
On 08/16/2015 03:36 PM, cym13 wrote: On Sunday, 16 August 2015 at 22:22:07 UTC, Ali Çehreli wrote: // HERE: // Error: function deneme.func @nogc function allocates //a closure with the GC @nogc auto func(uint[] arr, DelegateRef d) { return arr.map!(a => d.d(a)); } Aren't you makin

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 16 August 2015 at 22:31:02 UTC, Brandon Ragland wrote: Hi All, I'm a bit confused as to how Classes in D are passed in arguments and returns. Take this for example: class MyClass{ int x = 2; } And then in app.d ref MyClass doStuff(){ MyClass mc = new MyClass() // Heap allocation,

Re: D Classes Passed By Reference or Value?

2015-08-16 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 16 August 2015 at 22:31:02 UTC, Brandon Ragland wrote: ref MyClass doStuff(){ MyClass mc = new MyClass() // Heap allocation, using new return mc; } This attempts to return a reference to the _variable_ `mc`, not a reference to the class. Just remove `ref` from the function sig

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread cym13 via Digitalmars-d-learn
On Sunday, 16 August 2015 at 22:22:07 UTC, Ali Çehreli wrote: // HERE: // Error: function deneme.func @nogc function allocates //a closure with the GC @nogc auto func(uint[] arr, DelegateRef d) { return arr.map!(a => d.d(a)); } Aren't you making another delegate in the map by using

D Classes Passed By Reference or Value?

2015-08-16 Thread Brandon Ragland via Digitalmars-d-learn
Hi All, I'm a bit confused as to how Classes in D are passed in arguments and returns. Take this for example: class MyClass{ int x = 2; } And then in app.d ref MyClass doStuff(){ MyClass mc = new MyClass() // Heap allocation, using new return mc; } The above fails, as "escaping reference

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread Ali Çehreli via Digitalmars-d-learn
On 08/16/2015 09:26 AM, FreeSlave wrote: >> It still says it needs allocation: >> >> test.d(17): Error: function test.func @nogc function allocates a >> closure with the GC I wrapped it inside a class object but it still thinks it needs to allocate: import std.stdio; import std.range; import st

Weird error message.

2015-08-16 Thread Warwick via Digitalmars-d-learn
Dont know what to make of this, I pretty much get it every other time I call rdmd. It'll alternate between running fine and then giving me this error... C:\Program Files (x86)\Notepad++>rdmd J:\Code\statproc.d std.process.ProcessException@std\process.d(550): Failed to spawn new process (The pr

GDB for D debugging on OS X seems to be broken

2015-08-16 Thread Jack Stouffer via Digitalmars-d-learn
For reference: OSX 10.10.5 GDB 7.9.1 (non apple; from homebrew) yes, it is code signed Compiling with dub: "dflags": ["-gc", "-gs"] I would also like to preface this post by saying that everything works fine in GDB on linux. When finding that a bug in my program was a null poin

App Build Error

2015-08-16 Thread Benjamin via Digitalmars-d-learn
I'm having an issue with building my app - even a simple trivial app (shown below). I receive the following error message: cc -arch i386 -framework CoreFoundation -lobjc -liconv: No such file or directory --- errorlevel 255 I've removed and reinstalled DMD - same issue. I

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 16 August 2015 at 16:23:05 UTC, FreeSlave wrote: On Sunday, 16 August 2015 at 15:29:10 UTC, Ali Çehreli wrote: On 08/16/2015 04:53 AM, FreeSlave wrote: > The problem is that this allocates delegate, so it can't be used in > @nogc code. Would constructing the delegate by setting its

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 16 August 2015 at 15:29:10 UTC, Ali Çehreli wrote: On 08/16/2015 04:53 AM, FreeSlave wrote: > The problem is that this allocates delegate, so it can't be used in > @nogc code. Would constructing the delegate by setting its .funcptr and .ptr properties work in this case? You can have

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread Ali Çehreli via Digitalmars-d-learn
On 08/16/2015 04:53 AM, FreeSlave wrote: > The problem is that this allocates delegate, so it can't be used in > @nogc code. Would constructing the delegate by setting its .funcptr and .ptr properties work in this case? You can have a pool of context objects which become the context for the de

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 16 August 2015 at 12:30:54 UTC, cym13 wrote: On Sunday, 16 August 2015 at 11:53:42 UTC, FreeSlave wrote: [...] Ok, so as my lambda proposition obviously doesn't work, here is one way that does using a templated function. There may be a way to make it shorter, I don't know.

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread cym13 via Digitalmars-d-learn
On Sunday, 16 August 2015 at 11:53:42 UTC, FreeSlave wrote: Let's say I want to map some range using some context. The obvious way is to do: uint[3] arr = [1,2,3]; uint context = 2; auto r = arr[].map!(delegate(value) { return value * context; }); The problem is that this allocates delegate,

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 16 August 2015 at 12:04:51 UTC, cym13 wrote: To me the obvious way is to use a lambda, not a delegate: Lambdas and delegates are the same thing, just different syntax.

Re: 2.068 Regression in EnumMembers?

2015-08-16 Thread anonymous via Digitalmars-d-learn
On Sunday, 16 August 2015 at 11:25:48 UTC, Nordlöw wrote: I tried rebuilding my knowledge graph project at https://github.com/nordlow/justd/tree/master/knet with DMD 2.068 and it seems like we have a regression in std.traits: EnumMembers: [...] It builds without errors nor warnings on 2.067

Re: How to provide this arg or functor for algorithm?

2015-08-16 Thread cym13 via Digitalmars-d-learn
On Sunday, 16 August 2015 at 11:53:42 UTC, FreeSlave wrote: Let's say I want to map some range using some context. The obvious way is to do: uint[3] arr = [1,2,3]; uint context = 2; auto r = arr[].map!(delegate(value) { return value * context; }); To me the obvious way is to use a lambda, not

Re: How to convert a ubyte to a byte without losing information?

2015-08-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 16 August 2015 at 11:43:24 UTC, CharmingChocolate wrote: I can cast a ubyte to a byte, but as far as I know I'd only get positive values out of that conversion. ubyte b = 255; byte b2 = cast(byte) b; assert(b2 == -1); No information is lost by that cast, all the bits remain exactly

How to provide this arg or functor for algorithm?

2015-08-16 Thread FreeSlave via Digitalmars-d-learn
Let's say I want to map some range using some context. The obvious way is to do: uint[3] arr = [1,2,3]; uint context = 2; auto r = arr[].map!(delegate(value) { return value * context; }); The problem is that this allocates delegate, so it can't be used in @nogc code. What I want to do might lo

How to convert a ubyte to a byte without losing information?

2015-08-16 Thread CharmingChocolate via Digitalmars-d-learn
I can cast a ubyte to a byte, but as far as I know I'd only get positive values out of that conversion. If I was instead getting a ubyte out of a function and I want to assign those bits to a byte and have some of those numbers be interpreted as negative values by the new type they're in, how w

Re: 2.068 Regression in EnumMembers?

2015-08-16 Thread Nordlöw
On Sunday, 16 August 2015 at 11:25:48 UTC, Nordlöw wrote: Try cloning https://github.com/nordlow/justd/tree Should be: git clone https://github.com/nordlow/justd

Re: 2.068 Regression in EnumMembers?

2015-08-16 Thread Nordlöw
On Sunday, 16 August 2015 at 11:25:48 UTC, Nordlöw wrote: I tried rebuilding my knowledge graph project at https://github.com/nordlow/justd/tree/master/knet Should be, https://github.com/nordlow/justd.

2.068 Regression in EnumMembers?

2015-08-16 Thread Nordlöw
I tried rebuilding my knowledge graph project at https://github.com/nordlow/justd/tree/master/knet with DMD 2.068 and it seems like we have a regression in std.traits: EnumMembers: /usr/include/dmd/phobos/std/traits.d(3432,21): Error: template instance std.traits.EnumMembers!(Lang).WithIdent

Re: Using replaceInPlace, string and char[]

2015-08-16 Thread TSalm via Digitalmars-d-learn
> Must create a ticket for it ? I think so. Unless others object in 10 minutes... :) :-) Done : https://issues.dlang.org/show_bug.cgi?id=14925 Thanks for your help