Re: How to sort a range

2016-03-09 Thread Ali Çehreli via Digitalmars-d-learn
On 03/09/2016 06:50 PM, rcorre wrote: > sort calls to quicksort (for unstable, at least) which uses > swapAt. swapAt takes the range by value, so it just swaps the values in > its local copy. Remembering that a range is not the collection, swapAt takes the range by value but it does not copy

Re: How to import for mixin contents only.

2016-03-09 Thread Taylor Hillegeist via Digitalmars-d-learn
On Thursday, 10 March 2016 at 04:56:52 UTC, Mike Parker wrote: On Thursday, 10 March 2016 at 04:07:54 UTC, Taylor Hillegeist wrote: So i want bitfields for just a little bit. but i dont want its dependencies. How is it done. I have tried this. but it doesnt seem to work on gdc. :( struct

Re: How to import for mixin contents only.

2016-03-09 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 10 March 2016 at 04:07:54 UTC, Taylor Hillegeist wrote: So i want bitfields for just a little bit. but i dont want its dependencies. How is it done. I have tried this. but it doesnt seem to work on gdc. :( struct Color_t { static if(__ctfe){ import

How to import for mixin contents only.

2016-03-09 Thread Taylor Hillegeist via Digitalmars-d-learn
So i want bitfields for just a little bit. but i dont want its dependencies. How is it done. I have tried this. but it doesnt seem to work on gdc. :( struct Color_t { static if(__ctfe){ import std.bitmanip:bitfields; } mixin(bitfields!(

Re: How to sort a range

2016-03-09 Thread rcorre via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 16:53:08 UTC, Xinok wrote: On Wednesday, 9 March 2016 at 15:39:55 UTC, rcorre wrote: Still curious as to why it fails; maybe the range is getting copied at some point? I guess I need to step through it. That's my suspicion as well. It seems that OnlyResult is

Re: Is it safe to use 'is' to compare types?

2016-03-09 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 10, 2016 at 01:33:41AM +, Yuxuan Shui via Digitalmars-d-learn wrote: > On Wednesday, 9 March 2016 at 22:26:38 UTC, Ali Çehreli wrote: > >On 03/09/2016 07:05 AM, Yuxuan Shui wrote: > > > >> Can we left TypeInfo symbol undefined in the shared libraries? i.e. > >> D compiler will

Re: Is it safe to use 'is' to compare types?

2016-03-09 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 22:26:38 UTC, Ali Çehreli wrote: On 03/09/2016 07:05 AM, Yuxuan Shui wrote: > Can we left TypeInfo symbol undefined in the shared libraries? i.e. D > compiler will strip out TypeInfo definition when creating .so. > (Alternatively, we can have TypeInfo always

Re: Memory Efficient HashSet

2016-03-09 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 8 March 2016 at 12:25:36 UTC, Ola Fosheim Grøstad wrote: On Tuesday, 8 March 2016 at 08:12:04 UTC, Nordlöw wrote: sparse_hash_set<> contained in https://github.com/sparsehash/sparsehash It appears to be very slow? What do you need it for? My knowledge database engine I'm

Re: Is it safe to use 'is' to compare types?

2016-03-09 Thread Ali Çehreli via Digitalmars-d-learn
On 03/09/2016 07:05 AM, Yuxuan Shui wrote: > Can we left TypeInfo symbol undefined in the shared libraries? i.e. D > compiler will strip out TypeInfo definition when creating .so. > (Alternatively, we can have TypeInfo always undefined in .o, and > generate them in linking stage only when

Re: Use of GUID constants

2016-03-09 Thread Ali Çehreli via Digitalmars-d-learn
On 03/09/2016 10:35 AM, KlausO wrote: > IUnknown pUnk; > > // > // Does not compile: > // > // Error: function > core.sys.windows.unknwn.IUnknown.QueryInterface(const(GUID)* riid, > void** pvObject) is not callable using argument types (const(GUID),

Re: Trying to build a Scheme interpreter in D

2016-03-09 Thread Guillaume Piolat via Digitalmars-d-learn
On Tuesday, 8 March 2016 at 18:11:24 UTC, John wrote: * For this kind of implementation, is the Algebraic type a good choice ? Is a simple union perhaps better ? You can go with Algebraic. I used to do that in scheme-d. Then I switched to a tagged union by hand to avoid a compiler

Re: What can _not_ be marked pure?

2016-03-09 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Mar 09, 2016 at 05:12:18AM -0800, Jonathan M Davis via Digitalmars-d-learn wrote: [...] > So, in general, you can slap pure on most anything, though it will > rarely buy you anything in terms of performance. IMO, this is an area where the compiler could be improved to take better

Use of GUID constants

2016-03-09 Thread KlausO via Digitalmars-d-learn
Dear list, I use DMD 2.070.0 I try to access COM Interfaces via the declarations in core.sys.windows.* I have some problems and maybe someone could give me a usage hint. Have a look at the following (relatively meaningless) sample program which demonstrates the problem. IMHO the problem is

Re: GC scan for pointers

2016-03-09 Thread Chris Wright via Digitalmars-d-learn
On Wed, 09 Mar 2016 15:50:43 +, Adam D. Ruppe wrote: > Or static > arrays of int on the stack will also be scanned, since the GC doesn't > actually know much about local variables It's especially tricky because compilers can reuse memory on the stack -- for instance, if I use one variable

Re: How to sort a range

2016-03-09 Thread Chris Wright via Digitalmars-d-learn
On Wed, 09 Mar 2016 14:28:11 +, cym13 wrote: > Note that an input range isn't even remotely a container Which is why sort() has template constraints beyond isInputRange. The constraints ensure that it is possible to swap values in the range.

Re: How to sort a range

2016-03-09 Thread Xinok via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 15:39:55 UTC, rcorre wrote: Still curious as to why it fails; maybe the range is getting copied at some point? I guess I need to step through it. That's my suspicion as well. It seems that OnlyResult is pass-by-value so every time it gets passed to another

Re: Cannot compile program with DMD built from source

2016-03-09 Thread Minas Mina via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 16:13:38 UTC, Minas Mina wrote: Hello, I have followed the instructions here (http://wiki.dlang.org/Starting_as_a_Contributor#POSIX) to install DMD, druntime and phobos from source. My platform is Ubuntu 15.10 x64. This is the error I get:

Cannot compile program with DMD built from source

2016-03-09 Thread Minas Mina via Digitalmars-d-learn
Hello, I have followed the instructions here (http://wiki.dlang.org/Starting_as_a_Contributor#POSIX) to install DMD, druntime and phobos from source. My platform is Ubuntu 15.10 x64. This is the error I get: http://pastebin.com/kWCv0ymn

Re: How to sort a range

2016-03-09 Thread rcorre via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 14:28:11 UTC, cym13 wrote: Note that an input range isn't even remotely a container, it's a way to iterate on a container. As you don't have all elements at hand you can't sort them, that's why you have to use array here. Oh, I think it just clicked. I was

Re: GC scan for pointers

2016-03-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 15:14:02 UTC, Gerald Jansen wrote: will the large memory blocks allocated for a, b and/or c actually be scanned for pointers to GC-allocated memory during a garbage collection? If so, why? No. It knows that the type has no pointers in it, so it will not scan it

Re: How to sort a range

2016-03-09 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 15:39:55 UTC, rcorre wrote: On Wednesday, 9 March 2016 at 14:28:11 UTC, cym13 wrote: Still curious as to why it fails; maybe the range is getting copied at some point? I guess I need to step through it. I did try different SwapStrategies with no luck. Since

Re: How to sort a range

2016-03-09 Thread rcorre via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 14:28:11 UTC, cym13 wrote: On Wednesday, 9 March 2016 at 12:21:55 UTC, rcorre wrote: On Wednesday, 9 March 2016 at 09:15:01 UTC, Edwin van Leeuwen wrote: I'm not sure why your fix didn't work, but generally I work around this by converting the OnlyResult into an

Re: Is it safe to use 'is' to compare types?

2016-03-09 Thread Yuxuan Shui via Digitalmars-d-learn
On Tuesday, 8 March 2016 at 23:13:32 UTC, Anon wrote: On Tuesday, 8 March 2016 at 20:26:04 UTC, Yuxuan Shui wrote: [...] [Note: I phrase my answer in terms of Linux shared libraries (*.so) because D doesn't actually have proper Windows DLL support yet. The same would apply to DLLs, it just

GC scan for pointers

2016-03-09 Thread Gerald Jansen via Digitalmars-d-learn
I've studied [1] and [2] but don't understand everything there. Hence these dumb questions: Given enum n = 100_000_000; // some big number auto a = new ulong[](n); auto b = new char[8][](n); struct S { ulong x; char[8] y; } auto c = new S[](n); will the large memory blocks allocated

Re: How to sort a range

2016-03-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 12:21:55 UTC, rcorre wrote: On Wednesday, 9 March 2016 at 09:15:01 UTC, Edwin van Leeuwen wrote: I'm not sure why your fix didn't work, but generally I work around this by converting the OnlyResult into an array: import std.array : array;

Re: What can _not_ be marked pure?

2016-03-09 Thread Guillaume Piolat via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 13:12:18 UTC, Jonathan M Davis wrote: In general though, you should use pure wherever possible. - Jonathan M Davis Thanks for the detailed answer and gotchas. It thought compilers would use pure in alias analysis to ensure everything did not mutate during a

Re: How to sort a range

2016-03-09 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 13:04:31 UTC, rcorre wrote: On Wednesday, 9 March 2016 at 12:31:18 UTC, Edwin van Leeuwen wrote: On Wednesday, 9 March 2016 at 12:21:55 UTC, rcorre wrote: If you are looking for a lazy uniq that works on non sorted ranges, I implemented one not to long ago:

Re: What can _not_ be marked pure?

2016-03-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 09, 2016 09:56:05 Guillaume Piolat via Digitalmars-d-learn wrote: > If I understand purity correctly > (http://klickverbot.at/blog/2012/05/purity-in-d/), every function > out there can be marked pure as long as it doesn't modify > globals, shared variables or do I/O? > > It

Re: How to sort a range

2016-03-09 Thread rcorre via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 12:31:18 UTC, Edwin van Leeuwen wrote: On Wednesday, 9 March 2016 at 12:21:55 UTC, rcorre wrote: If you are looking for a lazy uniq that works on non sorted ranges, I implemented one not to long ago:

Re: How to sort a range

2016-03-09 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 12:21:55 UTC, rcorre wrote: If you are looking for a lazy uniq that works on non sorted ranges, I implemented one not to long ago: http://github.com/BlackEdder/ggplotd/blob/master/source/ggplotd/range.d That sounds like the kind of thing I was looking for. I'll

Re: How to sort a range

2016-03-09 Thread rcorre via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 09:15:01 UTC, Edwin van Leeuwen wrote: I'm not sure why your fix didn't work, but generally I work around this by converting the OnlyResult into an array: import std.array : array; assert(only(3,1,2).array.sort.equal(only(1,2,3))); I'd like to avoid allocating

Re: What can _not_ be marked pure?

2016-03-09 Thread Daniel Kozak via Digitalmars-d-learn
Dne 9.3.2016 v 11:26 Guillaume Piolat via Digitalmars-d-learn napsal(a): On Wednesday, 9 March 2016 at 10:08:33 UTC, ag0aep6g wrote: On 09.03.2016 10:56, Guillaume Piolat wrote: If I understand purity correctly (http://klickverbot.at/blog/2012/05/purity-in-d/), every function out there can

Re: RAII and classes

2016-03-09 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 10:48:30 UTC, cym13 wrote: On Wednesday, 9 March 2016 at 10:28:06 UTC, John Colvin wrote: Potential for leaking references from alias this aside, is there some reason that I shouldn't do this for all my C++-like RAII needs: class A { ~this(){ import

Re: RAII and classes

2016-03-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 10:28:06 UTC, John Colvin wrote: Potential for leaking references from alias this aside, is there some reason that I shouldn't do this for all my C++-like RAII needs: class A { ~this(){ import std.stdio; writeln("hello"); } } auto RAII(T)() if (is(T ==

RAII and classes

2016-03-09 Thread John Colvin via Digitalmars-d-learn
Potential for leaking references from alias this aside, is there some reason that I shouldn't do this for all my C++-like RAII needs: class A { ~this(){ import std.stdio; writeln("hello"); } } auto RAII(T)() if (is(T == class)) { struct Inner { private

Re: What can _not_ be marked pure?

2016-03-09 Thread Guillaume Piolat via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 10:08:33 UTC, ag0aep6g wrote: On 09.03.2016 10:56, Guillaume Piolat wrote: If I understand purity correctly (http://klickverbot.at/blog/2012/05/purity-in-d/), every function out there can be marked pure as long as it doesn't modify globals, shared variables or

Re: What can _not_ be marked pure?

2016-03-09 Thread ag0aep6g via Digitalmars-d-learn
On 09.03.2016 10:57, Guillaume Piolat wrote: Another question that ensues is: will the compiler prevent incorrect use of pure, so that it's safe to spam it in your code? The compiler should catch wrong usage of `pure`, yes. Function declarations without implementation are an exception, of

Re: What can _not_ be marked pure?

2016-03-09 Thread ag0aep6g via Digitalmars-d-learn
On 09.03.2016 10:56, Guillaume Piolat wrote: If I understand purity correctly (http://klickverbot.at/blog/2012/05/purity-in-d/), every function out there can be marked pure as long as it doesn't modify globals, shared variables or do I/O? Pure functions also can't *read* mutable globals. But

Re: What can _not_ be marked pure?

2016-03-09 Thread Guillaume Piolat via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 09:56:05 UTC, Guillaume Piolat wrote: If I understand purity correctly (http://klickverbot.at/blog/2012/05/purity-in-d/), every function out there can be marked pure as long as it doesn't modify globals, shared variables or do I/O? It seems more function can be

What can _not_ be marked pure?

2016-03-09 Thread Guillaume Piolat via Digitalmars-d-learn
If I understand purity correctly (http://klickverbot.at/blog/2012/05/purity-in-d/), every function out there can be marked pure as long as it doesn't modify globals, shared variables or do I/O? It seems more function can be marked pure that I previously thought.

Re: How to sort a range

2016-03-09 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 03:05:52 UTC, rcorre wrote: I was in a situation where I wanted to remove duplicates from an OnlyResult. To do this with uniq, I needed to sort it. OnlyResult doesn't satisfy the template constraints of sort, but this seems easy enough to fix. I made front, back,