Re: BitArray - incomplete implementation?
Yes, that error is caused by a bug of BitArray(https://issues.dlang.org/show_bug.cgi?id=13806). Having "init" function broke template constraints of "chain"(and must break dozen of other templates). pragma(msg, ElementType!(BitArray[])) // prints 'pure nothrow void(bool[] ba)' - ElementType uses "init" property to determine types. Thanks for this. If I recompile phobos with the pull request (having edited out the init property entirely) then the code mostly works. However, I still can't use join, joiner, or chain on two BitArrays. Eg auto x=joiner(a,b).array; I can chain two arrays of BitArrays, but not join or joiner them. If this is what ought to happen, why?
Re: why spawn crash?
thanks,you are right. window console show chinese char is not right, so i try to add this code: " extern(C) int setlocale(int, char*); static this() { fwide(core.stdc.stdio.stdout, 1); setlocale(LC_CTYPE, cast(char*)"china"); } " it's looks like solve the problem,but caused another problem. now i use "chcp 65001" command to change the code page and change the font to "lucida console".it works correctly!
Re: BitArray - incomplete implementation?
On Saturday, 24 January 2015 at 00:13:34 UTC, Laeeth Isharc wrote: Hi. Should the following code work? Yes, that error is caused by a bug of BitArray(https://issues.dlang.org/show_bug.cgi?id=13806). Having "init" function broke template constraints of "chain"(and must break dozen of other templates). pragma(msg, ElementType!(BitArray[])) // prints 'pure nothrow void(bool[] ba)' - ElementType uses "init" property to determine types. import std.bitmanip; import std.stdio; import std.array; import std.range:chain; void test() { int[] a=[1,2,3,4,5]; int[] b=[5,4,3,2,1]; int[] c = chain(a,b).array; // chain two arrays of int writefln("%s",c); } void test2() { BitArray a; a.init([1,0,1,0]); BitArray b; b.init([0,1,0,1]); BitArray[] d; d~=a; d~=b; BitArray[] c=chain([a],[b]).array; // cannot chain two bitarrays BitArray[] e=chain(d,d).array; // cannot chain two arrays of bitarrays writefln("%s",c); } int main(string[] args) { test(); test2(); return 1; } bitmanip.d(23): Error: template std.range.chain cannot deduce function from argument types !()(BitArray, BitArray), candidates are: /usr/include/dmd/phobos/std/range.d(2493): std.range.chain(Ranges...)(Ranges rs) if (Ranges.length > 0 && allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) && !is(CommonType!(staticMap!(ElementType, staticMap!(Unqual, Ranges))) == void)) bitmanip.d(24): Error: template std.range.chain cannot deduce function from argument types !()(BitArray[], BitArray[]), candidates are: /usr/include/dmd/phobos/std/range.d(2493): std.range.chain(Ranges...)(Ranges rs) if (Ranges.length > 0 && allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) && !is(CommonType!(staticMap!(ElementType, staticMap!(Unqual, Ranges))) == void)) bitmanip.d(24): Error: declaration bitmanip.test2.c is already defined bitmanip.d(25): Error: template std.range.chain cannot deduce function from argument types !()(BitArray[], BitArray[]), candidates are: /usr/include/dmd/phobos/std/range.d(2493): std.range.chain(Ranges...)(Ranges rs) if (Ranges.length > 0 && allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) && !is(CommonType!(staticMap!(ElementType, staticMap!(Unqual, Ranges))) == void)) I cannot seem to concatenate - directly, or using chain - two bitarrays, or two arrays of bitarrays.
Re: BitArray - incomplete implementation?
To avoid confusion, the below is the code that fits the error message: import std.bitmanip; import std.stdio; import std.array; import std.range:chain; void test() { int[] a=[1,2,3,4,5]; int[] b=[5,4,3,2,1]; int[] c = chain(a,b).array; // chain two arrays of int writefln("%s",c); } void test2() { BitArray a; a.init([1,0,1,0]); BitArray b; b.init([0,1,0,1]); BitArray[] d; d~=a; d~=b; BitArray[] c=chain(a,b).array; // cannot chain two bitarrays BitArray[] c=chain([a],[b]).array; // cannot chain two bitarrays BitArray[] e=chain(d,d).array; // cannot chain two arrays of bitarrays writefln("%s",c); } int main(string[] args) { test(); test2(); return 1; }
BitArray - incomplete implementation?
Hi. Should the following code work? import std.bitmanip; import std.stdio; import std.array; import std.range:chain; void test() { int[] a=[1,2,3,4,5]; int[] b=[5,4,3,2,1]; int[] c = chain(a,b).array; // chain two arrays of int writefln("%s",c); } void test2() { BitArray a; a.init([1,0,1,0]); BitArray b; b.init([0,1,0,1]); BitArray[] d; d~=a; d~=b; BitArray[] c=chain([a],[b]).array; // cannot chain two bitarrays BitArray[] e=chain(d,d).array; // cannot chain two arrays of bitarrays writefln("%s",c); } int main(string[] args) { test(); test2(); return 1; } bitmanip.d(23): Error: template std.range.chain cannot deduce function from argument types !()(BitArray, BitArray), candidates are: /usr/include/dmd/phobos/std/range.d(2493): std.range.chain(Ranges...)(Ranges rs) if (Ranges.length > 0 && allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) && !is(CommonType!(staticMap!(ElementType, staticMap!(Unqual, Ranges))) == void)) bitmanip.d(24): Error: template std.range.chain cannot deduce function from argument types !()(BitArray[], BitArray[]), candidates are: /usr/include/dmd/phobos/std/range.d(2493): std.range.chain(Ranges...)(Ranges rs) if (Ranges.length > 0 && allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) && !is(CommonType!(staticMap!(ElementType, staticMap!(Unqual, Ranges))) == void)) bitmanip.d(24): Error: declaration bitmanip.test2.c is already defined bitmanip.d(25): Error: template std.range.chain cannot deduce function from argument types !()(BitArray[], BitArray[]), candidates are: /usr/include/dmd/phobos/std/range.d(2493): std.range.chain(Ranges...)(Ranges rs) if (Ranges.length > 0 && allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) && !is(CommonType!(staticMap!(ElementType, staticMap!(Unqual, Ranges))) == void)) I cannot seem to concatenate - directly, or using chain - two bitarrays, or two arrays of bitarrays.
Re: What D related (or interesting development based) twitter accounts do you guys follow?
On Sunday, 28 July 2013 at 16:57:54 UTC, Gary Willoughby wrote: What D related (or interesting development based) twitter accounts do you guys follow? I'm pretty new to twitter and trying to follow accounts that i find interesting. Just remembered when reading this: http://www.viva64.com/en/b/0302/ "Twitter for C++ Programmers (updated)" it appeared here: https://isocpp.org/blog/2015/01/twitter-for-c-programmers-andrey-karpov Yes, it's about C++, but it mentions: WalterBright - @WalterBright - Digital Mars C, C++, D programming language compilers, and Javascript compiler. Andrei Alexandrescu - @incomputable - Please refer to my website for bio and contact information.
Re: What to do with InvalidMemoryOperationError
On Friday, 23 January 2015 at 21:25:01 UTC, Nordlöw wrote: On Friday, 23 January 2015 at 10:13:43 UTC, Joakim wrote: InvalidMemoryOperationError generally means that you are performing certain disallowed memory operations during a full garbage collection, such as allocating while the gc is running. If my app is single-threaded this cannot happen then. Single-/multi-threaded doesn't make a difference. This happens with a single thread, too. The GC calls destructors. When a destructor allocates then, it allocates during a GC run.
Re: What to do with InvalidMemoryOperationError
On Friday, 23 January 2015 at 10:13:43 UTC, Joakim wrote: InvalidMemoryOperationError generally means that you are performing certain disallowed memory operations during a full garbage collection, such as allocating while the gc is running. If my app is single-threaded this cannot happen then. This usually happens when you call a function that allocates in a destructor, which will trigger this error as the destructor is run by the gc. It appears that the gc issues mentioned above can also trigger it. If you're running off git head, maybe you can apply that PR 2794 and see if it helps. Otherwise, maybe you've hit some other gc issue somewhere. So if GC.disable prevents the error from occurring I will have a clue, right?
Re: Cross platform Development
On Friday, 23 January 2015 at 17:32:09 UTC, seany wrote: Hello I read this page, but I still have questions : http://forum.dlang.org/thread/fzbaxwcrbztqedqgm...@forum.dlang.org#post-mailman.1142.1332716016.4860.digitalmars-d:40puremagic.com I also read this : http://stackoverflow.com/questions/1510989/can-c-be-compiled-into-platform-independent-code-why-not However, I am wondering what are the ways to develop in a native 64 bit linux machine, and deploy similar linux machines as well as in 64 + 32 bit windowes machines. Are there ways to do so? I will need some detailed guidance. I think you need to ask a more detailed question. Do you want source compatibility or binary compatibility? Are you using GUI stuff? Cuz that's gonna add a world of hurt. Are you wanting to take a bit of source, compile it, and have that single executable run on all 32/64/linux/windows machines? If this is what you want, I'd recommend perl. One bit of code ... runs everywhere! -Andy
Cross platform Development
Hello I read this page, but I still have questions : http://forum.dlang.org/thread/fzbaxwcrbztqedqgm...@forum.dlang.org#post-mailman.1142.1332716016.4860.digitalmars-d:40puremagic.com I also read this : http://stackoverflow.com/questions/1510989/can-c-be-compiled-into-platform-independent-code-why-not However, I am wondering what are the ways to develop in a native 64 bit linux machine, and deploy similar linux machines as well as in 64 + 32 bit windowes machines. Are there ways to do so? I will need some detailed guidance.
Dub subPackage buildType and output file name
Currently I'm using dub for the first time and I've run into two problems so far. 1) I have defined buildTypes in dub.json, as well as subPackages. However, I want to always build all subPackages in release mode, regardless of the --build option I'm using to build the main program. I'm not clear if it's possible to do this, and if so, how to specify this. 2) I would like the file name of my final executable to depend on my chosen --build and --config options (i.e. --). Is this possible to do? Kind regards, Stefan
Error: closures are not yet supported in CTFE
I tried: -- import std.stdio, std.algorithm; auto unique(){ bool[int] c; return (int a){ if (a in c) return false; else{ c[a] = true; return true; } }; } void main() { [1, 5, 5, 2, 1, 5, 6, 6].filter!(unique()).writeln; } -- And got: Error: closures are not yet supported in CTFE This works: void main() { auto x = unique(); [1, 5, 5, 2, 1, 5, 6, 6].filter!x.writeln; } Is first version near?
Re: for ranges
On 1/23/15 4:44 AM, ixid wrote: On Thursday, 22 January 2015 at 16:41:49 UTC, Russel Winder wrote: Playing with factorial implementations, as you do. I had a D implementation using ulong. Not sensible obviously since overflow is a bit of a problem. But the code worked, as did the tests. Now converting to BigInt and… The standard explicit iteration form uses a loop: for(i; 2..n+1) for n = 0 or 1 this loop doesn't loop since the range is [,). However for BigInt: for(i; two..n + one) the loop starts at 0 and just keeps on going. This is clearly not good. Am I having a mental breakdown or is this a real bug? In general it feels as if BigInt needs more work as it doesn't work with simple generic code in too many cases. Templates get confused by invocation with a literal and a BigInt for example when it should have a single type. Literals feel too strongly typed or too weakly implicitly convertible. This is not a BigInt problem, it's an inconsistency with foreach range. See my earlier post. -Steve
Re: why spawn crash?
On 1/22/15 10:20 PM, mzf wrote: i wrote a test code: void worker(int firstNumber) { Thread.sleep(1.msecs); } void main() { foreach (i; 1 .. 1000) { spawn(&worker, i ); writeln(i); } thread_joinAll(); writeln("ok"); } sometimes it's ok,sometimes it's crashed ! why ? here is one of times callstack message: test.exe!_free() test.exe!_fwide() test.exe!_fwide() test.exe!__ReleaseSemaphore() test.exe!_fwide() test.exe!main@__modctor() 行 3 test.exe!rt@minfo@__T14runModuleFuncsS482rt5minfo11ModuleGroup11runTlsCtorsMFZ9__lambda1Z@runModuleFuncs() test.exe!___threadstartex@4() That sounds like a bug in stdio. fwide is the horrible attempt of C stdio to do wide character output. -Steve
Re: What to do with InvalidMemoryOperationError
On Wednesday, 21 January 2015 at 12:00:47 UTC, Nordlöw wrote: My executable throws as core.exception.InvalidMemoryOperationError@(0) when compiled with DMD git master. I get no stack trace in GDB. What to do? InvalidMemoryOperationError generally means that you are performing certain disallowed memory operations during a full garbage collection, such as allocating while the gc is running. This usually happens when you call a function that allocates in a destructor, which will trigger this error as the destructor is run by the gc. It appears that the gc issues mentioned above can also trigger it. If you're running off git head, maybe you can apply that PR 2794 and see if it helps. Otherwise, maybe you've hit some other gc issue somewhere.
Re: for ranges
On Thursday, 22 January 2015 at 16:41:49 UTC, Russel Winder wrote: Playing with factorial implementations, as you do. I had a D implementation using ulong. Not sensible obviously since overflow is a bit of a problem. But the code worked, as did the tests. Now converting to BigInt and… The standard explicit iteration form uses a loop: for(i; 2..n+1) for n = 0 or 1 this loop doesn't loop since the range is [,). However for BigInt: for(i; two..n + one) the loop starts at 0 and just keeps on going. This is clearly not good. Am I having a mental breakdown or is this a real bug? In general it feels as if BigInt needs more work as it doesn't work with simple generic code in too many cases. Templates get confused by invocation with a literal and a BigInt for example when it should have a single type. Literals feel too strongly typed or too weakly implicitly convertible.