Re: Passing around a list of differently typed functions

2014-06-22 Thread FreeSlave via Digitalmars-d-learn
On Monday, 23 June 2014 at 01:16:49 UTC, Evan Davis wrote: As the subject says, I would like to pass around an array of functions. The trick is, that the functions have different type signatures. Is there a way to put the two functions int foo(int a, int b); bool bar(bool a, bool b); into one

Re: Passing around a list of differently typed functions

2014-06-22 Thread Tobias Pankrath via Digitalmars-d-learn
On Monday, 23 June 2014 at 01:16:49 UTC, Evan Davis wrote: As the subject says, I would like to pass around an array of functions. The trick is, that the functions have different type signatures. Is there a way to put the two functions int foo(int a, int b); bool bar(bool a, bool b); into one

Passing around a list of differently typed functions

2014-06-22 Thread Evan Davis via Digitalmars-d-learn
As the subject says, I would like to pass around an array of functions. The trick is, that the functions have different type signatures. Is there a way to put the two functions int foo(int a, int b); bool bar(bool a, bool b); into one array, that I can pass around and cast as necessary? Thank

Re: very short pipeShell program

2014-06-22 Thread Ali Çehreli via Digitalmars-d-learn
On 06/22/2014 05:01 PM, WhatMeWorry wrote: After hours of reading (obviously not comprehending) std.process and looking at code samples, I still can't even do something this simple. Open a Windows command line and run miscellaneous commands. Only the first command, dir" is shown in the final out

very short pipeShell program

2014-06-22 Thread WhatMeWorry via Digitalmars-d-learn
After hours of reading (obviously not comprehending) std.process and looking at code samples, I still can't even do something this simple. Open a Windows command line and run miscellaneous commands. Only the first command, dir" is shown in the final output. auto pipe = pipeShell("dir", Redi

Re: What is the correct way to forward method calls to the struct field?

2014-06-22 Thread monnoroch via Digitalmars-d-learn
Cool! Only this does not show me where the error was. __FILE__ and __LINE__ is not any help here, because it's a template. Any other way to find out where the actual error was?

Re: What is the correct way to forward method calls to the struct field?

2014-06-22 Thread monnoroch via Digitalmars-d-learn
Nah, this gives me lots of compiler crap, like .empty and others, when compiler tries to compile them.

Re: What is the correct way to forward method calls to the struct field?

2014-06-22 Thread Philippe Sigaud via Digitalmars-d-learn
On Sun, Jun 22, 2014 at 5:02 PM, monnoroch via Digitalmars-d-learn wrote: > Thanks a lot! > There is a problem though: when i pass incorrect parameters to > such a method, it says, that S has no such field, which is a > misleading error message. You can test the mixin with static if, like this:

Re: What is the correct way to forward method calls to the struct field?

2014-06-22 Thread Philippe Sigaud via Digitalmars-d-learn
On Sun, Jun 22, 2014 at 5:04 PM, monnoroch via Digitalmars-d-learn wrote: > There is also a problem: when i declare opDispatch to be private, > i still have access to this forwarding from another package. Is > it a bug or what? I don't know. I never used private in conjunction with a template. Le

Re: What is the correct way to forward method calls to the struct field?

2014-06-22 Thread monnoroch via Digitalmars-d-learn
Thanks a lot! There is a problem though: when i pass incorrect parameters to such a method, it says, that S has no such field, which is a misleading error message.

Re: What is the correct way to forward method calls to the struct field?

2014-06-22 Thread monnoroch via Digitalmars-d-learn
There is also a problem: when i declare opDispatch to be private, i still have access to this forwarding from another package. Is it a bug or what?

Re: package reflection

2014-06-22 Thread Shammah Chancellor via Digitalmars-d-learn
On 2014-06-22 14:11:58 +, sigod said: In the video "Case Studies In Simplifying Code With Compile-Time Reflection" [was pointed out][0] that it is possible to reflect on imported packages. So, I tried: reflection.d: ``` import std.stdio; import test.module1; import test.module2; void m

package reflection

2014-06-22 Thread sigod via Digitalmars-d-learn
In the video "Case Studies In Simplifying Code With Compile-Time Reflection" [was pointed out][0] that it is possible to reflect on imported packages. So, I tried: reflection.d: ``` import std.stdio; import test.module1; import test.module2; void main() { foreach (m; __traits(allMemb

Re: mixin(__MODULE__) fails if module name is "module"

2014-06-22 Thread sigod via Digitalmars-d-learn
This question seems more fit for the main D newsgroup. Should I create new thread in the main newsgroup? Look in Bugzilla if there is a enhancement request. Yeah. I found one: https://issues.dlang.org/show_bug.cgi?id=456

Re: mixin(__MODULE__) fails if module name is "module"

2014-06-22 Thread sigod via Digitalmars-d-learn
On Sunday, 22 June 2014 at 12:52:11 UTC, sigod wrote: module.d: (or just `module module;` in source file) I was wrong about `module module;` declaration.

Re: mixin(__MODULE__) fails if module name is "module"

2014-06-22 Thread bearophile via Digitalmars-d-learn
sigod: Shouldn't keywords be disallowed for module names? I agree. (Walter seems not too keen on strictness). This question seems more fit for the main D newsgroup. Look in Bugzilla if there is a enhancement request. Bye, bearophile

mixin(__MODULE__) fails if module name is "module"

2014-06-22 Thread sigod via Digitalmars-d-learn
E.g.: module.d: (or just `module module;` in source file) ``` import std.stdio; void main() { foreach (m; __traits(allMembers, mixin(__MODULE__))) { // module.d-mixin-4(4): Error: expression expected, not 'module' writeln(m); } } ``` Documentation says: Package names cannot be

Re: Question about iteger literals

2014-06-22 Thread Uranuz via Digitalmars-d-learn
If these rules are not so clear and have some exceptions (but I don't understand why they are needed) then some documentation needed about this. But I would prefer to have result of uint substraction like uint, and char substraction like char. If we will changing all the types it will be kind o

Re: Question about iteger literals

2014-06-22 Thread bearophile via Digitalmars-d-learn
Uranuz: Why there are so complicated rules in the *new* language. It's hard to understand the logic. Despite D being only 14 years old, one of its rules is to (usually) give the same results if you write code that is valid in C. This means it has to follow many rules of C language. If you t

Re: Question about iteger literals

2014-06-22 Thread Uranuz via Digitalmars-d-learn
On Sunday, 22 June 2014 at 11:57:48 UTC, Uranuz wrote: Another stupid question. Using this logic substraction for two uint values should return int too, because it can produce negative result. Am I right or not? Now this code import std.stdio; void main() { uint a = 50; uint

Re: Question about iteger literals

2014-06-22 Thread bearophile via Digitalmars-d-learn
Uranuz: Another stupid question. Using this logic substraction for two uint values should return int too, because it can produce negative result. Am I right or not? There are no stupid questions, there are only some stupid answers. Generally uint - uint generates a result with a [-4_294_967_

Re: Question about iteger literals

2014-06-22 Thread Uranuz via Digitalmars-d-learn
Another stupid question. Using this logic substraction for two uint values should return int too, because it can produce negative result. Am I right or not?

Re: Question about iteger literals

2014-06-22 Thread Uranuz via Digitalmars-d-learn
In D operations among chars return a int. The same happens in C/C++. If you subtract a char from a char in general you can have a negative result, that can't fit in a char. So what's buggy is your thinking. Ok. Thank you! I never thought about it that way

Re: Question about iteger literals

2014-06-22 Thread bearophile via Digitalmars-d-learn
Uranuz: But what @nogc changes in there so I should use this modifier? @nogc will be present in dmd 2.066, it means that the function (and all the functions it calls) can't perform operations that cause a call to GC functions. Sometimes GC operations are a source of performance loss. Bye,

Re: Question about iteger literals

2014-06-22 Thread bearophile via Digitalmars-d-learn
Uranuz: But I don't understand why in expression where both of arguments have type char: return c - '0'; I have resulting type int. It's very strange for me and looks very buggy) In D operations among chars return a int. The same happens in C/C++. If you subtract a char from a cha

Re: Some kind of RPC exists for D?

2014-06-22 Thread Bienlein via Digitalmars-d-learn
On Saturday, 21 June 2014 at 18:22:54 UTC, Paul wrote: I wrote some (JSONRPC and TXTRPC) and used them with vibe. I can send you via email Hi Paul, alternatively you could upload your code to GitHub or some similar place and place the link here. Then you also have a means to "proof" that the

Re: Question about iteger literals

2014-06-22 Thread Uranuz via Digitalmars-d-learn
In expression return c - 'a' + 10; I could think that 10 has type int and resulting value promoted to the largest type. But I don't understand why in expression where both of arguments have type char: return c - '0'; I have resulting type int. It's very strange for me and looks ve

Re: Question about iteger literals

2014-06-22 Thread Uranuz via Digitalmars-d-learn
ushort hexValue(in char c) pure nothrow @safe @nogc else return ushort.max; I understand what pure, nothrow and @safe mean there. But what @nogc changes in there so I should use this modifier? Is it logical specifier that this function can be used without garbage

Re: DMD Fails with fPIC error

2014-06-22 Thread Reuben via Digitalmars-d-learn
Thanks, that did the trick. Here's a summary post for anyone else with the same problem: Problem: DMD uses GCC to perform linking. On Hardened Gentoo (and derivatives like Sabayon), GCC implies -fPIE, which causes linking to fail if phobos and druntime were not compiled with -fPIC. You can ch

Re: Question about iteger literals

2014-06-22 Thread bearophile via Digitalmars-d-learn
Uranuz: bool isDigit(char c) nothrow This function is already in Phobos, it's std.ascii.isDigit. ushort hexValue(char c) nothrow Better to use this signature (assuming you want a ushort result, despite a ubyte suffices and a uint is faster): ushort hexValue(in char c) pure nothrow @saf

Question about iteger literals

2014-06-22 Thread Uranuz via Digitalmars-d-learn
I have the following programme import std.stdio; bool isDigit(char c) nothrow { return c >= '0' && c <= '9'; } ushort hexValue(char c) nothrow { if( isDigit(c) ) return c - '0'; else if (c >= 'a' && c <= 'f') return c - 'a' + 10; e

Re: opAssign() calls members' postblits?

2014-06-22 Thread via Digitalmars-d-learn
On Saturday, 21 June 2014 at 20:03:26 UTC, Ali Çehreli wrote: > Now, http://dlang.org/struct.html#AssignOverload says: > > ref S opAssign(S s) > { Note that opAssign takes by-value. The post-blits that you see are due that copy. i.e. b in main is copied to the argument that opAssign