Re: BigInt and

2014-12-19 Thread bearophile via Digitalmars-d-learn
Andre: Do you have any idea how to translate the coding correctly? Try: i += long(buffer[3]) 24 0; But I also suggest to add parentheses, to make the code less unreadable for humans. Bye, bearophile

Re: Memoizing methods

2014-12-19 Thread Dicebot via Digitalmars-d-learn
On Friday, 19 December 2014 at 02:45:13 UTC, kyle wrote: If you memoize a method inside a class definition using std.functional.memoize is caching done in a per-object manner, or do all objects of this class share cached return values? Thank you. Memoize uses one hash table per symbol it is

Re: BigInt and

2014-12-19 Thread Andre via Digitalmars-d-learn
Great! Thanks a lot. Kind regards André On Friday, 19 December 2014 at 08:47:50 UTC, bearophile wrote: Andre: Do you have any idea how to translate the coding correctly? Try: i += long(buffer[3]) 24 0; But I also suggest to add parentheses, to make the code less unreadable for humans.

Re: std.file.readText() extra Line Feed character

2014-12-19 Thread Colin via Digitalmars-d-learn
On Thursday, 18 December 2014 at 22:29:30 UTC, Ali Çehreli wrote: On 12/18/2014 02:51 AM, Colin wrote: vi, and it does indeed have a '\n' at the end of file. Ah, I see. That's a little annoying. It looks like there are ways of dealing with it:

Re: Derelict SDL2 library not loading on OS X

2014-12-19 Thread Joel via Digitalmars-d-learn
Now I get this: Joels-MacBook-Pro:dere joelcnz$ ./app derelict.util.exception.SymbolLoadException@source/derelict/util/exception.d(35): Failed to load symbol SDL_GameControllerAddMapping from shared library /usr/local/lib/libSDL2.dylib

Loops versus ranges

2014-12-19 Thread bearophile via Digitalmars-d-learn
A case where the usage of ranges (UFCS chains) leads to very bad performance: import std.stdio: writeln; import std.algorithm: map, join; uint count1, count2; const(int)[] foo1(in int[] data, in int i, in int max) { count1++; if (i max) { typeof(return) result;

Re: Loops versus ranges

2014-12-19 Thread aldanor via Digitalmars-d-learn
On Friday, 19 December 2014 at 10:41:04 UTC, bearophile wrote: A case where the usage of ranges (UFCS chains) leads to very bad performance: import std.stdio: writeln; import std.algorithm: map, join; uint count1, count2; const(int)[] foo1(in int[] data, in int i, in int max) {

Re: Loops versus ranges

2014-12-19 Thread aldanor via Digitalmars-d-learn
On Friday, 19 December 2014 at 10:57:47 UTC, aldanor wrote: Something about the loop in the first case not depending on n and the compiler being able to figure it is out and only drop into recursion once? That's just a wild guess, but does it get transformed into something like this?

Re: Loops versus ranges

2014-12-19 Thread anon via Digitalmars-d-learn
On Friday, 19 December 2014 at 10:41:04 UTC, bearophile wrote: A case where the usage of ranges (UFCS chains) leads to very bad performance: import std.stdio: writeln; import std.algorithm: map, join; uint count1, count2; const(int)[] foo1(in int[] data, in int i, in int max) {

Re: Loops versus ranges

2014-12-19 Thread bearophile via Digitalmars-d-learn
aldanor: On Friday, 19 December 2014 at 10:57:47 UTC, aldanor wrote: Something about the loop in the first case not depending on n and the compiler being able to figure it is out and only drop into recursion once? That's just a wild guess, but does it get transformed into something like

Re: std.file.readText() extra Line Feed character

2014-12-19 Thread ketmar via Digitalmars-d-learn
On Fri, 19 Dec 2014 10:22:01 + Colin via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Thursday, 18 December 2014 at 22:29:30 UTC, Ali Çehreli wrote: On 12/18/2014 02:51 AM, Colin wrote: vi, and it does indeed have a '\n' at the end of file. Ah, I see. That's

Re: std.file.readText() extra Line Feed character

2014-12-19 Thread ketmar via Digitalmars-d-learn
On Fri, 19 Dec 2014 10:22:01 + Colin via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Thursday, 18 December 2014 at 22:29:30 UTC, Ali Çehreli wrote: On 12/18/2014 02:51 AM, Colin wrote: vi, and it does indeed have a '\n' at the end of file. Ah, I see. That's

Re: Loops versus ranges

2014-12-19 Thread ketmar via Digitalmars-d-learn
On Fri, 19 Dec 2014 10:41:03 + bearophile via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Can you tell why? :-) 'cause lazy ranges can't be optimised in compile time? ;-) signature.asc Description: PGP signature

Re: Loops versus ranges

2014-12-19 Thread bearophile via Digitalmars-d-learn
anon: Changed to return data.map!(n = foo2(data, i + 1, max)).cache.joiner.array; then it produced the same result as array version. `map.cache.join` resulted in 597871. This is close to tell what the cause is :-) Bye, bearophile

Re: Derelict SDL2 library not loading on OS X

2014-12-19 Thread Mike Parker via Digitalmars-d-learn
On 12/19/2014 7:35 PM, Joel wrote: Now I get this: Joels-MacBook-Pro:dere joelcnz$ ./app derelict.util.exception.SymbolLoadException@source/derelict/util/exception.d(35): Failed to load symbol SDL_GameControllerAddMapping from shared library /usr/local/lib/libSDL2.dylib OK, it looks like

Re: Loops versus ranges

2014-12-19 Thread ketmar via Digitalmars-d-learn
On Fri, 19 Dec 2014 12:20:34 + bearophile via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: anon: Changed to return data.map!(n = foo2(data, i + 1, max)).cache.joiner.array; then it produced the same result as array version. `map.cache.join` resulted in

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread Anonymous via Digitalmars-d-learn
On Thursday, 18 December 2014 at 22:27:06 UTC, zeljkog wrote: On 18.12.14 14:50, Steven Schveighoffer wrote: I wonder how your code compares to this: void append(T)(ref T[] arr, T[] args...) { arr ~= args; } This is ~20% slower for ints, but it difference increases for bigger structs.

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/18/14 5:27 PM, zeljkog wrote: On 18.12.14 14:50, Steven Schveighoffer wrote: I wonder how your code compares to this: void append(T)(ref T[] arr, T[] args...) { arr ~= args; } This is ~20% slower for ints, but it difference increases for bigger structs. This is surprising to

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread zeljkog via Digitalmars-d-learn
On 19.12.14 16:25, Steven Schveighoffer wrote: This is surprising to me. I would expect especially ints to be faster. In reality, there is no difference between arr ~= args and arr.length += args.length, and then copying, it's just how you do the copying. Perhaps it's the call to memcpy in the

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/19/14 10:42 AM, zeljkog wrote: On 19.12.14 16:25, Steven Schveighoffer wrote: This is surprising to me. I would expect especially ints to be faster. In reality, there is no difference between arr ~= args and arr.length += args.length, and then copying, it's just how you do the copying.

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread Anonymous via Digitalmars-d-learn
On Friday, 19 December 2014 at 15:25:46 UTC, Steven Schveighoffer wrote: On 12/18/14 5:27 PM, zeljkog wrote: On 18.12.14 14:50, Steven Schveighoffer wrote: I wonder how your code compares to this: void append(T)(ref T[] arr, T[] args...) { arr ~= args; } This is ~20% slower for ints,

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/19/14 12:15 PM, Anonymous wrote: On Friday, 19 December 2014 at 15:25:46 UTC, Steven Schveighoffer wrote: This is surprising to me. Ho ho ho, this year he has brought your surprise sooner than expected... It would be nice if this was the only time this year I was surprised because

Re: PyD-like wrapping for Excel/VBA and Julia?

2014-12-19 Thread Kagamin via Digitalmars-d-learn
On Thursday, 18 December 2014 at 20:41:39 UTC, Laeeth Isharc wrote: (There may be more efficient purer ways of doing this, but I don't wish to spend time learning Excel internals/object models, and I know my route will work reasonably well). ActiveX is not internal to Excel. Being a generic

Re: Garbage collector collects live objects

2014-12-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/12/14 10:50 AM, Steven Schveighoffer wrote: On 12/12/14 7:52 AM, Ruslan Mullakhmetov wrote: btw, i used suggested trackallocs.d and GC defenetely receives NO_SCAN before tag: 1 len: 2 ptr: 103A78058 root: 103A77000:8192 attr: APPENDABLE gc_qalloc(41, NO_SCAN APPENDABLE ) cc: 29106 asz:

Re: PyD-like wrapping for Excel/VBA and Julia?

2014-12-19 Thread Laeeth Isharc via Digitalmars-d-learn
On Friday, 19 December 2014 at 01:59:05 UTC, Ellery Newcomer wrote: On 12/18/2014 12:41 PM, Laeeth Isharc wrote: I have a bunch of D functions I would like to make available to Excel (and possibly Julia) without having to write wrappers for each function individually. I've thought about

Get vars in current scope at compile time?

2014-12-19 Thread Tofu Ninja via Digitalmars-d-learn
Is there some way to get a list of the variables that are in the current scope via traits? Some things like allMembers? I would like to be able to call this from a mixin to grab the locals in the scope that the mixin is being dropped into.

Unittest in a windows app

2014-12-19 Thread Dan Nestor via Digitalmars-d-learn
Hello everybody, this is my first post on this forum. I have a question about unit testing a Windows application. I have slightly modified Visual D's default Windows application stub to the following: code module winmain; import core.runtime; import core.sys.windows.windows; unittest {

DUB build questions

2014-12-19 Thread uri via Digitalmars-d-learn
Hi All, I'm very happy with CMakeD but thought I'd try dub because CMake script is a PITA. So I have a couple of questions. a) Can dub do out out of source builds and how would I set that up. b) Can I do parallel builds with dub. CMake gives me Makefiles so I can make -j does dub have a

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread Anonymous via Digitalmars-d-learn
On Friday, 19 December 2014 at 18:38:32 UTC, Steven Schveighoffer wrote: On 12/19/14 12:15 PM, Anonymous wrote: On Friday, 19 December 2014 at 15:25:46 UTC, Steven Schveighoffer wrote: This is surprising to me. Ho ho ho, this year he has brought your surprise sooner than expected...

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/19/14 5:28 PM, Anonymous wrote: What a big surprise. If you make an array of struct, each item of your array has the length of the struct. structs a values. If you want to append a struct to an array just append a pointer to the struct: -- struct arg{uint a,r,g,h;}; arg * []

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread Ali Çehreli via Digitalmars-d-learn
On 12/19/2014 07:42 AM, zeljkog wrote: On 19.12.14 16:25, Steven Schveighoffer wrote: Did you compile both tests with the same command line parameters? Yes. Can we see the test code please. Ali

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread zeljkog via Digitalmars-d-learn
On 19.12.14 23:56, Ali Çehreli wrote: Can we see the test code please. Ali import std.stdio, std.datetime, std.random; int N = 10_000; int len = 1000; int k = 4; struct S{ int n1, n2; //~ this(this){ //~ writeln(this(this)); //~ } } ref T[] append(T, Args...)(ref T[]

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread MarcelDuchamp via Digitalmars-d-learn
On Friday, 19 December 2014 at 23:24:13 UTC, zeljkog wrote: On 19.12.14 23:56, Ali Çehreli wrote: Can we see the test code please. Ali import std.stdio, std.datetime, std.random; int N = 10_000; int len = 1000; int k = 4; struct S{ int n1, n2; //~ this(this){ //~

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread MarcelDuchamp via Digitalmars-d-learn
On Saturday, 20 December 2014 at 00:15:21 UTC, MarcelDuchamp wrote: On Friday, 19 December 2014 at 23:24:13 UTC, zeljkog wrote: On 19.12.14 23:56, Ali Çehreli wrote: Can we see the test code please. Ali import std.stdio, std.datetime, std.random; int N = 10_000; int len = 1000; int k = 4;

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread zeljkog via Digitalmars-d-learn
If you wish run this just add: struct S{ int n1, n2, n3, n4, n5 ...; }

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread MarcelDuchamp via Digitalmars-d-learn
On Saturday, 20 December 2014 at 00:44:54 UTC, zeljkog wrote: If you wish run this just add: struct S{ int n1, n2, n3, n4, n5 ...; } I wish. And I also wish you to get that to append in an array or a in a list some ptr its not the same as appending structs, particularly when the structs

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread anonymous via Digitalmars-d-learn
On Friday, 19 December 2014 at 14:41:07 UTC, Anonymous wrote: What a big surprise. If you make an array of struct, each item of your array has the length of the struct. structs a values. If you want to append a struct to an array just append a pointer to the struct: -- struct arg{uint

Re: Derelict SDL2 library not loading on OS X

2014-12-19 Thread Joel via Digitalmars-d-learn
[snip] In this case, I used the online mercurial repo browser for SDL 2 [1]. I selected the release-2.0.0 tag, then clicked include, then clicked the file link for SDL_GameController.h. I used Ctrl-f in my web browser to search for SDL_GameControllerAddMapping and found it was there. I then

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-19 Thread anonymous via Digitalmars-d-learn
On Saturday, 20 December 2014 at 00:15:21 UTC, MarcelDuchamp wrote: You've forget the array of ref version. (append the address of the first data) What array of ref version? Sounds like it would be a different data structure, which would be beyond the scope the topic. And adding S to an array

Re: DUB build questions

2014-12-19 Thread Rikki Cattermole via Digitalmars-d-learn
On 20/12/2014 11:14 a.m., uri wrote: Hi All, I'm very happy with CMakeD but thought I'd try dub because CMake script is a PITA. So I have a couple of questions. a) Can dub do out out of source builds and how would I set that up. There is e.g. preBuildCommands. b) Can I do parallel builds

Re: Get vars in current scope at compile time?

2014-12-19 Thread Rikki Cattermole via Digitalmars-d-learn
On 20/12/2014 10:09 a.m., Tofu Ninja wrote: Is there some way to get a list of the variables that are in the current scope via traits? Some things like allMembers? I would like to be able to call this from a mixin to grab the locals in the scope that the mixin is being dropped into. No way to

Re: DUB build questions

2014-12-19 Thread uri via Digitalmars-d-learn
On Saturday, 20 December 2014 at 04:15:00 UTC, Rikki Cattermole wrote: On 20/12/2014 11:14 a.m., uri wrote: Hi All, I'm very happy with CMakeD but thought I'd try dub because CMake script is a PITA. So I have a couple of questions. a) Can dub do out out of source builds and how would I set

Re: DUB build questions

2014-12-19 Thread Dicebot via Digitalmars-d-learn
On Saturday, 20 December 2014 at 04:15:00 UTC, Rikki Cattermole wrote: b) Can I do parallel builds with dub. CMake gives me Makefiles so I can make -j does dub have a similar option? No Worth noting that it is not actually a dub problem as much, it is simply not worth adding parallel