Re: what wrong with this alias
On 1/8/23 12:42 AM, Qusatlegadus wrote: auto s = 1234.to!string.map!q{a - '0'}.sum; works fine. but if i do an alias alias comb = to!string.map!q{a - '0'} Error: unknown, please file report on issues.dlang.org What's wrong with this alias? Aside from the problem with the code, that error alone deserves a bug report so... https://issues.dlang.org/show_bug.cgi?id=23615 -Steve
Re: what wrong with this alias
On Sunday, 8 January 2023 at 09:45:09 UTC, Krzysztof Jajeśnica wrote: ## Simple explanation `to!string` is a function expecting 1 argument, which you're not providing in your alias. Convert your alias to a lambda expression: ```D alias comb = x => x.to!string.map!q{a - '0'} ``` A logical solution... Since your goal is to manipulate numbers, it is possible to convert directly to char type: ```d import std.algorithm : map, sum; import std.conv : toChars; alias comb = (uint x) => x.toChars.map!"a - '0'"; void main() { auto s = 2234.comb.sum; assert(s.comb.sum == 2); } ``` SDB@79
Re: what wrong with this alias
On Sunday, 8 January 2023 at 05:42:46 UTC, Qusatlegadus wrote: auto s = 1234.to!string.map!q{a - '0'}.sum; works fine. but if i do an alias alias comb = to!string.map!q{a - '0'} Error: unknown, please file report on issues.dlang.org What's wrong with this ## Simple explanation `to!string` is a function expecting 1 argument, which you're not providing in your alias. Convert your alias to a lambda expression: ```D alias comb = x => x.to!string.map!q{a - '0'} ``` ## Complicated explanation `to` is a template defined like this: ```D // https://github.com/dlang/phobos/blob/master/std/conv.d template to(T) { T to(A...)(A args) if (A.length > 0) { return toImpl!T(args); } // some overloads omitted for brevity } ``` `to` needs at least 2 template arguments - the first one for the outer template is passed explicitly (what you did with `to!string`), the other ones are inferred from the arguments passed to the `to` function. Since you did not pass an argument to `to!string`, the inner template doesn't get instantiated. Basically what happens is you're trying to pass an uninstantiated template as argument to `map`. This is quite an exotic situation, so probably there isn't a dedicated error message for it or you're hitting a bug in the compiler (hence the unknown error message).
Re: what wrong with this alias
On Sunday, 8 January 2023 at 05:42:46 UTC, Qusatlegadus wrote: What's wrong with this alias? ```d import std; alias comb = map!q{a - '0'}; void main() { auto s = 2234.to!string.map!q{a - '0'}.sum; s.to!string.comb.sum.writeln; // thiS works: "2" } ``` SDB@79
what wrong with this alias
auto s = 1234.to!string.map!q{a - '0'}.sum; works fine. but if i do an alias alias comb = to!string.map!q{a - '0'} Error: unknown, please file report on issues.dlang.org What's wrong with this alias?
Re: What wrong?
On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) based on DMD v2.066.1 and LLVM 3.5.0. $ ./z TUQLUE 42 11 Compiled by DMD v2.067.1 the program crashes: $ ./aa TUQLUE Segmentation fault What I'm doing wrong? (Copying my reply to the post in the main group here:) I investigated this further. std.variant is to blame. I filed an issue an made a pull request to fix it: https://issues.dlang.org/show_bug.cgi?id=14585 https://github.com/D-Programming-Language/phobos/pull/3284
Re: What wrong?
On Friday, 15 May 2015 at 09:20:32 UTC, Gary Willoughby wrote: On Friday, 15 May 2015 at 07:51:29 UTC, thedeemon wrote: On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ What I'm doing wrong? Try using class instead of struct. Last time I played with std.concurrency it used Variants to store the messages, so when something bigger than a little basic value or a reference, like a class object, is sent it behaves unpredictably: can crash or shit garbage. Trying to send structs larger than ~20 bytes usually caused problems. Please raise a bugzilla issue for this. this commit cause the issue: https://github.com/D-Programming-Language/phobos/commit/45fda72192ff5b878ebe915db0ffb9f6504cca8f but it is probably just a trigger not a real cause.
Re: What wrong?
On Friday, 15 May 2015 at 07:51:29 UTC, thedeemon wrote: On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ What I'm doing wrong? Try using class instead of struct. Last time I played with std.concurrency it used Variants to store the messages, so when something bigger than a little basic value or a reference, like a class object, is sent it behaves unpredictably: can crash or shit garbage. Trying to send structs larger than ~20 bytes usually caused problems. Please raise a bugzilla issue for this.
Re: What wrong?
On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ What I'm doing wrong? Try using class instead of struct. Last time I played with std.concurrency it used Variants to store the messages, so when something bigger than a little basic value or a reference, like a class object, is sent it behaves unpredictably: can crash or shit garbage. Trying to send structs larger than ~20 bytes usually caused problems.
Re: What wrong?
On Tuesday, 5 May 2015 at 07:41:04 UTC, sclytrack wrote: On Monday, 4 May 2015 at 01:03:43 UTC, Fyodor Ustinov wrote: On Saturday, 2 May 2015 at 20:46:32 UTC, Dennis Ritchie wrote: On Saturday, 2 May 2015 at 19:38:01 UTC, Fyodor Ustinov wrote: I see it by the lack of "42". :) But why is this "receive" breaks down? import std.stdio; import std.variant; struct SoMany { int number = 10; ~this() { writeln(number); } } void main() { Variant v = SoMany(); } DMD64 D Compiler v2.067.1 10 10 10 10 gdc (Debian 4.9.2-10) 4.9.2 10 10 For DMD I'm getting 4x10 and for gdc 2x10
Re: What wrong?
On Monday, 4 May 2015 at 01:03:43 UTC, Fyodor Ustinov wrote: On Saturday, 2 May 2015 at 20:46:32 UTC, Dennis Ritchie wrote: On Saturday, 2 May 2015 at 19:38:01 UTC, Fyodor Ustinov wrote: I see it by the lack of "42". :) But why is this "receive" breaks down? import std.stdio; import std.concurrency; struct Answer { int number = 10; ~this() { writeln(number); } } void threadRoutine() { receive( (int value){ } //handle question ); ownerTid.send( Answer() ); //answer } void main() { Tid childId = spawn(&threadRoutine); childId.send(100); //question receive((Answer t) {}); //answer } //DMD64 D Compiler v2.067.1 /* 10 10 10 10 10 10 10 10 10 10 10 7080544 10 10 10 */
Re: What wrong?
On Monday, 4 May 2015 at 01:03:43 UTC, Fyodor Ustinov wrote: I'm not sure that it's not my fault. So I hope that will come by knowledgeable people and say "Hey, buddy, your mistake is..." :) OK. But if one does not come within three days :), duplicate topic in this section: http://forum.dlang.org/group/digitalmars.D
Re: What wrong?
On Saturday, 2 May 2015 at 20:46:32 UTC, Dennis Ritchie wrote: On Saturday, 2 May 2015 at 19:38:01 UTC, Fyodor Ustinov wrote: I see it by the lack of "42". :) But why is this "receive" breaks down? Report, please, about it (D)evepopers :) https://issues.dlang.org/ I'm not sure that it's not my fault. So I hope that will come by knowledgeable people and say "Hey, buddy, your mistake is..." :)
Re: What wrong?
On Saturday, 2 May 2015 at 19:38:01 UTC, Fyodor Ustinov wrote: I see it by the lack of "42". :) But why is this "receive" breaks down? Report, please, about it (D)evepopers :) https://issues.dlang.org/
Re: What wrong?
On Saturday, 2 May 2015 at 19:13:45 UTC, Dennis Ritchie wrote: On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) based on DMD v2.066.1 and LLVM 3.5.0. $ ./z TUQLUE 42 11 Compiled by DMD v2.067.1 the program crashes: $ ./aa TUQLUE Segmentation fault What I'm doing wrong? I think the problem is in these lines: - receive( (supervisorAnswer a) => r = a.ret ); Partially it works :) I see it by the lack of "42". :) But why is this "receive" breaks down?
Re: What wrong?
On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) based on DMD v2.066.1 and LLVM 3.5.0. $ ./z TUQLUE 42 11 Compiled by DMD v2.067.1 the program crashes: $ ./aa TUQLUE Segmentation fault What I'm doing wrong? I think the problem is in these lines: - receive( (supervisorAnswer a) => r = a.ret ); Partially it works :) - import std.variant; private struct Exit{}; private struct supervisorAnswer { Variant ret; } private __gshared Tid supervisorTid; private void supervisor() { static Variant[string] zval; bool done = false; void _store(T)(string k, T v) { assert(k.length > 0); zval[k] = v; } void _get(Tid id, string k) { id.send(supervisorAnswer(zval.get(k, Variant("NOTFOUND"; } while (!done) { supervisorAnswer answer; receive( (Exit s) { done = true; }, &_store!long, &_store!ulong, &_store!int, &_store!uint, &_store!float, &_store!double, &_store!string, &_store!Variant, &_get, (Variant e) { writeln(e); }, ); } } Variant Get(const string s) { Variant r; supervisorTid.send(thisTid, s); writeln("TUQLUE"); /*receive( (supervisorAnswer a) => r = a.ret );*/ writeln("42"); return r; } void Set(T)(const string s, T v) { supervisorTid.send(s, v); } shared static this() { supervisorTid = spawn(&supervisor); } shared static ~this() { send(supervisorTid, Exit()); } void main() { Set("1", 11); writeln(Get("1")); send(supervisorTid, Exit()); thread_joinAll(); }
What wrong?
Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) based on DMD v2.066.1 and LLVM 3.5.0. $ ./z TUQLUE 42 11 Compiled by DMD v2.067.1 the program crashes: $ ./aa TUQLUE Segmentation fault What I'm doing wrong?
Re: What wrong did i do? (key in hashtable is always null)
bearophile wrote: This was my version, maybe it solves some of your problems: http://shootout.alioth.debian.org/debian/benchmark.php?test=knucleotide&lang=gdc&id=2 I haven't used my dlibs here, so for example that sort in the middle is long and ugly (and not fully correct, that opCmp doesn't compare accordingly both key and value, as the problem specs state: "sorted by descending frequency and then ascending k-nucleotide key"), in Python it becomes: l = sorted(frequences.items(), reverse=True, key=lambda (seq,freq): (freq,seq)) With my dlibs it's similar. You can probably do something similar with Phobos2. By the way, the formatting of your code needs improvements, reduce indentation length and format code in a more readable way. Bye, bearophile Thanks for pointing out code format style. :) Shootout site stop benching D lang => why wasting time in formating code for someone else. I just curious in D's AA perf compared to C++ pb_ds::cc_hash_table. The newest C++ knucleotide using uint64 as key, not char[] anymore. In my small test case, D's built-in AA has the same perf as C glib. That's 4-5 times slower that pb_ds::cc_hash_table. Moreover, i think that it has bug -.-
Re: What wrong did i do? (key in hashtable is always null)
grauzone wrote: Is your opCmp/toHash really called? Maybe the function signature is off, and dmd doesn't "find" the function. Just a guess, I don't really know how this D2 stuff works. toHash + opCmp are called. The awkward is that, most of those functions are copied & pasted from C. They work perfectly. I suspect that it is a bug. I would like to know if someone else meet the same problem.
Re: What wrong did i do? (key in hashtable is always null)
The Anh Tran wrote: This is just a small D exercise. I port c++ knucleotide from shootout.alioth.debian.org Issue 1: If i manually listing hashtable contents, the key does exist in that ht. But (key in hash_table) always yield null. Worse, if i use: "auto val = ht[key]", an exception is thrown. Problem code is from line 163 to 177. Issue 2: If I pass an AA (uint[ulong]) to a template function. DMD complains that uint[ulong] is void. How can i get the type of AA? DMD 2.037. Linux Ubuntu. Source code: ftp://ftp.4utours.com/dualamd/Dlang/knu5.d Is your opCmp/toHash really called? Maybe the function signature is off, and dmd doesn't "find" the function. Just a guess, I don't really know how this D2 stuff works. Sample data: ftp://ftp.4utours.com/dualamd/Dlang/fa50k.txt Thanks.
Re: What wrong did i do? (key in hashtable is always null)
The Anh Tran: > This is just a small D exercise. I port c++ knucleotide from > shootout.alioth.debian.org This was my version, maybe it solves some of your problems: http://shootout.alioth.debian.org/debian/benchmark.php?test=knucleotide&lang=gdc&id=2 I haven't used my dlibs here, so for example that sort in the middle is long and ugly (and not fully correct, that opCmp doesn't compare accordingly both key and value, as the problem specs state: "sorted by descending frequency and then ascending k-nucleotide key"), in Python it becomes: l = sorted(frequences.items(), reverse=True, key=lambda (seq,freq): (freq,seq)) With my dlibs it's similar. You can probably do something similar with Phobos2. By the way, the formatting of your code needs improvements, reduce indentation length and format code in a more readable way. Bye, bearophile
What wrong did i do? (key in hashtable is always null)
This is just a small D exercise. I port c++ knucleotide from shootout.alioth.debian.org Issue 1: If i manually listing hashtable contents, the key does exist in that ht. But (key in hash_table) always yield null. Worse, if i use: "auto val = ht[key]", an exception is thrown. Problem code is from line 163 to 177. Issue 2: If I pass an AA (uint[ulong]) to a template function. DMD complains that uint[ulong] is void. How can i get the type of AA? DMD 2.037. Linux Ubuntu. Source code: ftp://ftp.4utours.com/dualamd/Dlang/knu5.d Sample data: ftp://ftp.4utours.com/dualamd/Dlang/fa50k.txt Thanks.