Reducing array.length triggers reallocation

2015-12-27 Thread milentin via Digitalmars-d-learn
I've just started learning D and noticed a bug, but wanted to confirm it here before reporting it. According to spec: "If the new array length is shorter, the array is not reallocated, and no data is copied. It is equivalent to slicing the array". Contradicted by a trivial program: void

Re: What's wrong with my debugger?

2015-12-27 Thread Rainer Schuetze via Digitalmars-d-learn
On 24.12.2015 14:57, Chris wrote: On Thursday, 24 December 2015 at 09:30:24 UTC, Rainer Schuetze wrote: In the locals window, mago displays all instances of variables, but with the same value (which might be some uninitialized value of a different declaration than expected). The Visual Studio

Re: How to use GDC to get .a file on Linux?

2015-12-27 Thread tcak via Digitalmars-d-learn
On Sunday, 27 December 2015 at 15:19:21 UTC, FrankLike wrote: Hi, Now I need get the .a file on Linux,target system is ARM. If you use gcc ,you will use the 'ar' to get .a file, but how to do by GDC ? And how to get the execute file by .a file and .d file? Thank you. I couldn't have

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread SimonN via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:41:10 UTC, TheDGuy wrote: It looks like the debugger is not working correctly because i changed the code to this: [...] and the same problem appears. I can't watch youtube here. What numbers does your input generate? Which 'if' doesn't fire? What results

Re: specifying an auto array type

2015-12-27 Thread Jay Norwood via Digitalmars-d-learn
On Sunday, 27 December 2015 at 07:40:55 UTC, Ali Çehreli wrote: It looks like you need map(), not each(): import std.algorithm; import std.typecons; import std.array; void main() { auto a = [ 1, 2 ]; auto arr = a.map!(e => tuple(2 * e, e * e)).array; static assert(is(typeof(arr)

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:39:18 UTC, SimonN wrote: On Sunday, 27 December 2015 at 16:01:37 UTC, TheDGuy wrote: Sry: if((x1 < 0) & (x2 >= 0)){ This looks like a bug, with & instead of &&. -- Simon It looks like the debugger is not working correctly because i

Re: How to use GDC to get .a file on Linux?

2015-12-27 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 27 December 2015 at 15:19:21 UTC, FrankLike wrote: Hi, Now I need get the .a file on Linux,target system is ARM. If you use gcc ,you will use the 'ar' to get .a file, but how to do by GDC ? And how to get the execute file by .a file and .d file? Thank you. Just use ar on the

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
On Sunday, 27 December 2015 at 18:03:16 UTC, Bubbasaur wrote: On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 Tell me one thing, what is the value returned? Well It's working here:

Variable below zero but if statement doesn't grab?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread SimonN via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:01:37 UTC, TheDGuy wrote: Sry: if((x1 < 0) & (x2 >= 0)){ This looks like a bug, with & instead of &&. -- Simon

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:48:44 UTC, SimonN wrote: On Sunday, 27 December 2015 at 16:41:10 UTC, TheDGuy wrote: It looks like the debugger is not working correctly because i changed the code to this: [...] and the same problem appears. I can't watch youtube here. What numbers does

Re: How to instantiate a map with multiple functions

2015-12-27 Thread karthikeyan via Digitalmars-d-learn
On Sunday, 27 December 2015 at 02:21:11 UTC, Ali Çehreli wrote: On 12/26/2015 05:26 PM, Karthikeyan wrote: > if I need to map on a array of tuples will that work with the tuple being > unpacked or do I need to get it as single element and do unpacking myself? Unfortunately, there is no

Is it possible to elegantly create a range over a binary heap?

2015-12-27 Thread Gary Willoughby via Digitalmars-d-learn
I have a binary tree storing ints implemented using an array. The internal state looks like this: 8,7,6,4,1,3,5,2 When extracting this data, it is returned as 8,7,6,5,4,3,2,1. Is it possible to elegantly add a range on top of the internal state to return the correct value order I would

Re: How to use GDC to get .a file on Linux?

2015-12-27 Thread FrankLike via Digitalmars-d-learn
On Sunday, 27 December 2015 at 15:24:17 UTC, tcak wrote: On Sunday, 27 December 2015 at 15:19:21 UTC, FrankLike wrote: Hi, Now I need get the .a file on Linux,target system is ARM. If you use gcc ,you will use the 'ar' to get .a file, but how to do by GDC ? And how to get the execute

Is this an rvalue reference problem?

2015-12-27 Thread Gary Willoughby via Digitalmars-d-learn
See the following code: import std.stdio; void foo(ref int x) { writefln("%s", x); } void main(string[] args) { int y = 0; foo(y++); } When compiled it produces this error: test.d(11): Error: function test.foo (ref int x) is not callable using argument types (int)

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread SimonN via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:52:39 UTC, TheDGuy wrote: I don't understand why my program goes into the if statement if the debugger shows, that the variable "discriminant" is below zero even though: "if(discriminant > 0)"? I have a hard time believing this. Does the problem persist if

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread Bubbasaur via Digitalmars-d-learn
On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 Tell me one thing, what is the value returned? Well It's working here: http://dpaste.dzfl.pl/18b27ea26b08 Maybe you would like to change the code above to

Re: Is this an rvalue reference problem?

2015-12-27 Thread tsbockman via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:05:39 UTC, Gary Willoughby wrote: If I remove the post-increment of the y variable if works. Is this an rvalue reference issue? Would you expect this to work? This should work with *pre*-increment, but not post-increment. Post-increment works like this: int

Re: Is this an rvalue reference problem?

2015-12-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:05:39 UTC, Gary Willoughby wrote: void foo(ref int x) foo(y++); If I remove the post-increment of the y variable if works. Is this an rvalue reference issue? Yes, but more than that, what, exactly, would you expect from that? The order of operations

Re: Struct destructors not always called?

2015-12-27 Thread Jeremy DeHaan via Digitalmars-d-learn
On Sunday, 27 December 2015 at 18:47:52 UTC, Adam D. Ruppe wrote: On Sunday, 27 December 2015 at 18:40:55 UTC, Jeremy DeHaan wrote: I was playing around with some code today and I noticed that in some cases struct destructors are not called. struct destructors are called when the struct

Re: Is it possible to elegantly create a range over a binary heap?

2015-12-27 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 27 December 2015 at 17:23:35 UTC, Gary Willoughby wrote: I have a binary tree storing ints implemented using an array. The internal state looks like this: 8,7,6,4,1,3,5,2 When extracting this data, it is returned as 8,7,6,5,4,3,2,1. Is it possible to elegantly add a range on top

Re: Is this an rvalue reference problem?

2015-12-27 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 27 December 2015 at 18:54:25 UTC, Adam D. Ruppe wrote: On Sunday, 27 December 2015 at 16:05:39 UTC, Gary Willoughby wrote: [...] Yes, but more than that, what, exactly, would you expect from that? The order of operations with the postfix ++ operator and ref would probably lead to

Re: Ranges: How to take N last of elements of range

2015-12-27 Thread Jakob Ovrum via Digitalmars-d-learn
On Saturday, 26 December 2015 at 05:31:59 UTC, Ur@nuz wrote: On Friday, 25 December 2015 at 20:06:04 UTC, drug wrote: 25.12.2015 17:13, Ur@nuz пишет: [...] You can do following http://dpaste.dzfl.pl/41c57f89a5a0 The reason of compile error is your using a range as a separator, change it

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote: On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 You could post the code also, personnaly I'm always almost at 2 meters from my screen, with zoom,

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread jkpl via Digitalmars-d-learn
On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 You could post the code also, personnaly I'm always almost at 2 meters from my screen, with zoom, so I can't read the code...

Re: Struct destructors not always called?

2015-12-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 27 December 2015 at 18:40:55 UTC, Jeremy DeHaan wrote: I was playing around with some code today and I noticed that in some cases struct destructors are not called. struct destructors are called when the struct ceases to exist in the program. A global variable never ceases to

Re: Struct destructors not always called?

2015-12-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 27 December 2015 at 19:04:11 UTC, Jeremy DeHaan wrote: So are these left dangling or do they actually get cleaned up at the program exit? They are left dangling right now. You can clear it yourself by defining a `static ~this() { .destroy(your struct); }` somewhere in the module.

each! vs foreach parallel timings

2015-12-27 Thread Jay Norwood via Digitalmars-d-learn
I'm doing some re-writing and measuring. The basic task is to take 10K samples (in struct S samples below) and calculate some metrics (just per sample for now). It isn't evident to me how to write the parallel foreach in the same format as each!, so I just used the loop form that I

Re: Double precision?

2015-12-27 Thread Bubbasaur via Digitalmars-d-learn
On Sunday, 27 December 2015 at 20:06:53 UTC, TheDGuy wrote: I don't know what my computer is doing today: x and y are coordinates and if x is any number from 0 to 150 the result of x/width is always zero Dividing Integers will result in Integer: int x = 10, width = 50;

How to use GDC to get .a file on Linux?

2015-12-27 Thread FrankLike via Digitalmars-d-learn
Hi, Now I need get the .a file on Linux,target system is ARM. If you use gcc ,you will use the 'ar' to get .a file, but how to do by GDC ? And how to get the execute file by .a file and .d file? Thank you.

Struct destructors not always called?

2015-12-27 Thread Jeremy DeHaan via Digitalmars-d-learn
I was playing around with some code today and I noticed that in some cases struct destructors are not called. for example: impost std.stdio; SomeStruct global; void main() { SomeStruct inMain; writeln(global.thing); writeln(inMain.thing); writeln(getSomeInt()); } int

Double precision?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
I don't know what my computer is doing today: code: double normalized_i = (x / width) - 0.5; double normalized_j = (y / height) - 0.5; writeln(x); writeln(normalized_i); writeln(y);

Re: Reducing array.length triggers reallocation

2015-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/2015 02:09 AM, milentin wrote: > I've just started learning D and noticed a bug, but wanted to confirm it > here before reporting it. > > According to spec: "If the new array length is shorter, the array is not > reallocated, and no data is copied. It is equivalent to slicing the >

Re: each! vs foreach parallel timings

2015-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/2015 04:17 PM, Jay Norwood wrote: On Sunday, 27 December 2015 at 23:42:57 UTC, Ali Çehreli wrote: That does not compile because i is size_t but apply_metrics() takes an int. One solution is to call to!int: foreach( i, ref a; parallel(samples[])){ apply_metrics(i.to!int,a);}

Re: each! vs foreach parallel timings

2015-12-27 Thread Jay Norwood via Digitalmars-d-learn
On Sunday, 27 December 2015 at 23:42:57 UTC, Ali Çehreli wrote: On 12/27/2015 11:30 AM, Jay Norwood wrote: > samples[].each!((int i, ref a)=>apply_metrics(i,a)); Are you using an older compiler? That tuple expansion does not work any more at least with dmd v2.069.0 but you can use

Re: Reducing array.length triggers reallocation

2015-12-27 Thread Ivan Kazmenko via Digitalmars-d-learn
On Sunday, 27 December 2015 at 22:36:32 UTC, Ali Çehreli wrote: [Several hours later...] You know what... I bet there is no actual allocation at all. I think what happens is, the code calls GC.realloc(24) and realloc() does not do anything. However, it still reports to the profiler that

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
On Sunday, 27 December 2015 at 22:51:27 UTC, Ali Çehreli wrote: On 12/27/2015 07:53 AM, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 YouTube says that the video has been removed by the user. That's exactly the reason why I don't like even dpaste.

Re: each! vs foreach parallel timings

2015-12-27 Thread Jay Norwood via Digitalmars-d-learn
On Sunday, 27 December 2015 at 23:42:57 UTC, Ali Çehreli wrote: That does not compile because i is size_t but apply_metrics() takes an int. One solution is to call to!int: foreach( i, ref a; parallel(samples[])){ apply_metrics(i.to!int,a);} It builds for me still, and executes ok,

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/2015 07:53 AM, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 YouTube says that the video has been removed by the user. That's exactly the reason why I don't like even dpaste. There is no guarantee that such threads will be useful forever.

Re: specifying an auto array type

2015-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/2015 08:42 AM, Jay Norwood wrote: > However, I was trying to use each!, with the intention of then moving to > parallel processing by samples blocks. My guess is this would be more > efficient than using parallel map or amap, which would parallel process > by function application, if I

GTKD drawing area remains white even SourceRgb is changed

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
My code: http://dpaste.com/1X3E1HW i store colors in the accumulator-array and draw them via "cr.rectangle()". Because i have some problems with the code i set the SourceRgb-color to a constant value but if i execute the program, the window remains white.

Re: each! vs foreach parallel timings

2015-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/2015 11:30 AM, Jay Norwood wrote: > samples[].each!((int i, ref a)=>apply_metrics(i,a)); Are you using an older compiler? That tuple expansion does not work any more at least with dmd v2.069.0 but you can use enumerate():

How to config the GDC on linux target for ARM linux?

2015-12-27 Thread FrankLike via Digitalmars-d-learn
Now I build a project for ARM linux on ubuntu 15.04 ,but build error. I download the 'wiringPi' from http://wiringPi.com,convert the *.h to *.d.then build the 'aa.so' file: #! /bin/sh dfiles="max31855.d max5322.d mcp23008.d mcp23016.d mcp23016reg.d mcp23017.d mcp23s08.d mcp23s17.d mcp23x08.d

Re: Is it possible to elegantly create a range over a binary heap?

2015-12-27 Thread Ivan Kazmenko via Digitalmars-d-learn
On Sunday, 27 December 2015 at 20:01:47 UTC, Gary Willoughby wrote: On Sunday, 27 December 2015 at 17:23:35 UTC, Gary Willoughby wrote: I have a binary tree storing ints implemented using an array. The internal state looks like this: 8,7,6,4,1,3,5,2 When extracting this data, it is returned

Re: Reducing array.length triggers reallocation

2015-12-27 Thread milentin via Digitalmars-d-learn
On Sunday, 27 December 2015 at 22:36:32 UTC, Ali Çehreli wrote: I don't understand why that happens. I found one related bug: https://issues.dlang.org/show_bug.cgi?id=13750 I can understand that assignment to arr.length cannot be @nogc but I would expect a check against length so that there