digitalmars.D - filter!(not!(predicate))(someInputRange) does not compile
- Jens Mueller (21/21) Jan 19 2011 Hi,
- Andrei Alexandrescu (4/25) Jan 19 2011 Place the call to not!alwaysTrue in a local function inside main:
- Jens Mueller (4/38) Jan 19 2011 Thanks. Can you elaborate a bit please? I wonder why the alias won't
- Andrei Alexandrescu (16/53) Jan 19 2011 I thought of it for a bit. It's a limitation of the compiler that's
- Jens Mueller (8/33) Jan 20 2011 Yeah. That makes sense.
- Andrei Alexandrescu (4/37) Jan 20 2011 Yes please. Make it an enhancement as it would remove a limitation of an...
- Jens K. Mueller (2/43) Jan 20 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5469
- spir (8/10) Jan 20 2011 Because in your original version the alias line does not define a func,
Hi, I cannot make the following compile. import std.functional; import std.array; import std.algorithm; import std.stdio; void main() { auto numbers = [0, 1, 2, 3, 4, 5]; bool alwaysTrue(uint a) { return true; } alias not!(alwaysTrue) alwaysFalse; numbers = array(filter!(alwaysTrue)(numbers)); writeln(numbers); numbers = array(filter!(alwaysFalse)(numbers)); // does not compile writeln(numbers); } The line with alwaysFalse fails with: /path/to/../src/phobos/std/algorithm.d(854): Error: constructor std.algorithm.Filter!(not,int[]).Filter.this cannot get frame pointer to not Any ideas what I'm doing wrong or workarounds? Jens
Jan 19 2011
On 1/19/11 5:53 PM, Jens Mueller wrote:Hi, I cannot make the following compile. import std.functional; import std.array; import std.algorithm; import std.stdio; void main() { auto numbers = [0, 1, 2, 3, 4, 5]; bool alwaysTrue(uint a) { return true; } alias not!(alwaysTrue) alwaysFalse; numbers = array(filter!(alwaysTrue)(numbers)); writeln(numbers); numbers = array(filter!(alwaysFalse)(numbers)); // does not compile writeln(numbers); } The line with alwaysFalse fails with: /path/to/../src/phobos/std/algorithm.d(854): Error: constructor std.algorithm.Filter!(not,int[]).Filter.this cannot get frame pointer to not Any ideas what I'm doing wrong or workarounds? JensPlace the call to not!alwaysTrue in a local function inside main: bool alwaysFalse(uint a) { return not!alwaysTrue(a); } Andrei
Jan 19 2011
Andrei Alexandrescu wrote:On 1/19/11 5:53 PM, Jens Mueller wrote:Thanks. Can you elaborate a bit please? I wonder why the alias won't work. JensHi, I cannot make the following compile. import std.functional; import std.array; import std.algorithm; import std.stdio; void main() { auto numbers = [0, 1, 2, 3, 4, 5]; bool alwaysTrue(uint a) { return true; } alias not!(alwaysTrue) alwaysFalse; numbers = array(filter!(alwaysTrue)(numbers)); writeln(numbers); numbers = array(filter!(alwaysFalse)(numbers)); // does not compile writeln(numbers); } The line with alwaysFalse fails with: /path/to/../src/phobos/std/algorithm.d(854): Error: constructor std.algorithm.Filter!(not,int[]).Filter.this cannot get frame pointer to not Any ideas what I'm doing wrong or workarounds? JensPlace the call to not!alwaysTrue in a local function inside main: bool alwaysFalse(uint a) { return not!alwaysTrue(a); }
Jan 19 2011
On 1/19/11 7:19 PM, Jens Mueller wrote:Andrei Alexandrescu wrote:I thought of it for a bit. It's a limitation of the compiler that's worth a bug report. The explanation is a bit involved. Let me start by remarking that if you prepend "static" to alwaysTrue, the alias works as expected: static bool alwaysTrue(uint a) { return true; } alias not!(alwaysTrue) alwaysFalse; Without "static", alwaysTrue has access to a hidden pointer to the stack frame of the function is in. In theory a template should be unable to manipulate alwaysTrue because of that frame pointer. But Walter has had this great idea of instantiating templates in the context of the function they're in, so they gain access to the frame pointer too. However, that instantiation mechanism still has a few limitations. I think the code above runs into one of them. AndreiOn 1/19/11 5:53 PM, Jens Mueller wrote:Thanks. Can you elaborate a bit please? I wonder why the alias won't work.Hi, I cannot make the following compile. import std.functional; import std.array; import std.algorithm; import std.stdio; void main() { auto numbers = [0, 1, 2, 3, 4, 5]; bool alwaysTrue(uint a) { return true; } alias not!(alwaysTrue) alwaysFalse; numbers = array(filter!(alwaysTrue)(numbers)); writeln(numbers); numbers = array(filter!(alwaysFalse)(numbers)); // does not compile writeln(numbers); } The line with alwaysFalse fails with: /path/to/../src/phobos/std/algorithm.d(854): Error: constructor std.algorithm.Filter!(not,int[]).Filter.this cannot get frame pointer to not Any ideas what I'm doing wrong or workarounds? JensPlace the call to not!alwaysTrue in a local function inside main: bool alwaysFalse(uint a) { return not!alwaysTrue(a); }
Jan 19 2011
Andrei Alexandrescu wrote:On 1/19/11 7:19 PM, Jens Mueller wrote:Yeah. That makes sense. It has this hidden pointer to access variables from the function it is defined in.Andrei Alexandrescu wrote:I thought of it for a bit. It's a limitation of the compiler that's worth a bug report. The explanation is a bit involved. Let me start by remarking that if you prepend "static" to alwaysTrue, the alias works as expected: static bool alwaysTrue(uint a) { return true; } alias not!(alwaysTrue) alwaysFalse; Without "static", alwaysTrue has access to a hidden pointer to the stack frame of the function is in.Place the call to not!alwaysTrue in a local function inside main: bool alwaysFalse(uint a) { return not!alwaysTrue(a); }Thanks. Can you elaborate a bit please? I wonder why the alias won't work.In theory a template should be unable to manipulate alwaysTrue because of that frame pointer. But Walter has had this great idea of instantiating templates in the context of the function they're in, so they gain access to the frame pointer too. However, that instantiation mechanism still has a few limitations. I think the code above runs into one of them.I see. I can file a bug report if it is considered important and should not be forgotten. Jens
Jan 20 2011
On 1/20/11 12:47 PM, Jens Mueller wrote:Andrei Alexandrescu wrote:Yes please. Make it an enhancement as it would remove a limitation of an otherwise little explored feature. Thanks! AndreiOn 1/19/11 7:19 PM, Jens Mueller wrote:Yeah. That makes sense. It has this hidden pointer to access variables from the function it is defined in.Andrei Alexandrescu wrote:I thought of it for a bit. It's a limitation of the compiler that's worth a bug report. The explanation is a bit involved. Let me start by remarking that if you prepend "static" to alwaysTrue, the alias works as expected: static bool alwaysTrue(uint a) { return true; } alias not!(alwaysTrue) alwaysFalse; Without "static", alwaysTrue has access to a hidden pointer to the stack frame of the function is in.Place the call to not!alwaysTrue in a local function inside main: bool alwaysFalse(uint a) { return not!alwaysTrue(a); }Thanks. Can you elaborate a bit please? I wonder why the alias won't work.In theory a template should be unable to manipulate alwaysTrue because of that frame pointer. But Walter has had this great idea of instantiating templates in the context of the function they're in, so they gain access to the frame pointer too. However, that instantiation mechanism still has a few limitations. I think the code above runs into one of them.I see. I can file a bug report if it is considered important and should not be forgotten. Jens
Jan 20 2011
Andrei Alexandrescu wrote:On 1/20/11 12:47 PM, Jens Mueller wrote:http://d.puremagic.com/issues/show_bug.cgi?id=5469Andrei Alexandrescu wrote:Yes please. Make it an enhancement as it would remove a limitation of an otherwise little explored feature. Thanks!On 1/19/11 7:19 PM, Jens Mueller wrote:Yeah. That makes sense. It has this hidden pointer to access variables from the function it is defined in.Andrei Alexandrescu wrote:I thought of it for a bit. It's a limitation of the compiler that's worth a bug report. The explanation is a bit involved. Let me start by remarking that if you prepend "static" to alwaysTrue, the alias works as expected: static bool alwaysTrue(uint a) { return true; } alias not!(alwaysTrue) alwaysFalse; Without "static", alwaysTrue has access to a hidden pointer to the stack frame of the function is in.Place the call to not!alwaysTrue in a local function inside main: bool alwaysFalse(uint a) { return not!alwaysTrue(a); }Thanks. Can you elaborate a bit please? I wonder why the alias won't work.In theory a template should be unable to manipulate alwaysTrue because of that frame pointer. But Walter has had this great idea of instantiating templates in the context of the function they're in, so they gain access to the frame pointer too. However, that instantiation mechanism still has a few limitations. I think the code above runs into one of them.I see. I can file a bug report if it is considered important and should not be forgotten. Jens
Jan 20 2011
On 01/20/2011 02:19 AM, Jens Mueller wrote:Thanks. Can you elaborate a bit please? I wonder why the alias won't work.Because in your original version the alias line does not define a func, but a kind of constant symbol. A higher order func like filter expects a func as first arg, not a constant. (my 2 c) denis _________________ vita es estrany spir.wikidot.com
Jan 20 2011