Re: D2 map trouble
On Wed, Jul 28, 2010 at 01:06, Nick Sabalausky a...@a.a wrote: Nick Sabalausky a...@a.a wrote in message news:i2no7g$eu...@digitalmars.com... Trying to convert some D1 code to D2: On 2.047, I'm trying to do this: import std.string; void foo(string str) { str = std.algorithm.map!( (char a) { return inPattern(a, [digits, letters])? a : '_'; } )(str); } And I'm getting: delegate std.algorithm.__dgliteral1 cannot access frame of function __dgliteral1 What's going on? How do I do it right? I figure I probably have some sort of problem with strings being immutable(char)[] instead of char[], but it doesn't look like that's the issue it's complaining about. Also, in this particular case, I'm not concerned about multi-unit UTF-8 characters. In my particular case, I've just switched to regex: import std.regex; str = replace(str, regex([^a-zA-Z0-9]), _); But I am still curious to hear what exactly was going on with map. It's an error I get on a weekly basis :-( Either returning a map with an anonymous function or using it as you do. I gather the Map template in std.algo is unable to have access to your closure literal, as it is inside foo. A possible workaround is having the anonymous function as a standard, named, free function and use this inside foo. But in that case, why have anonymous functions in D? Another is to use 'string functions', I think. I can test right now, but something like might work: void foo(string str) { str = std.algorithm.map!q{ inPattern(a, [digits, letters])? a : '_'; } (str); } But then I guess inPattern must be visible from std.algorithm. So my current conclusion it that it's more a limitation of anonymous closures than a limitation in map. Philippe
Re: D2 map trouble
On 07/28/2010 12:57 AM, Nick Sabalausky wrote: Trying to convert some D1 code to D2: On 2.047, I'm trying to do this: import std.string; void foo(string str) { str = std.algorithm.map!( (char a) { return inPattern(a, [digits, letters])? a : '_'; } )(str); } And I'm getting: delegate std.algorithm.__dgliteral1 cannot access frame of function __dgliteral1 What's going on? How do I do it right? I figure I probably have some sort of problem with strings being immutable(char)[] instead of char[], but it doesn't look like that's the issue it's complaining about. Also, in this particular case, I'm not concerned about multi-unit UTF-8 characters. This is a compiler bug. Easy workaround: auto fn = (char a) { ... }; str = map!fn(str);
Re: D2 map trouble
On Wed, Jul 28, 2010 at 16:51, Pelle pelle.mans...@gmail.com wrote: This is a compiler bug. Easy workaround: auto fn = (char a) { ... }; str = map!fn(str); Is it on bugzilla? Philippe
Re: D2 map trouble
Philippe Sigaud: Is it on bugzilla? If not present you can add it here: http://d.puremagic.com/issues/show_bug.cgi?id=4264 Bye, bearophile
D2 map trouble
Trying to convert some D1 code to D2: On 2.047, I'm trying to do this: import std.string; void foo(string str) { str = std.algorithm.map!( (char a) { return inPattern(a, [digits, letters])? a : '_'; } )(str); } And I'm getting: delegate std.algorithm.__dgliteral1 cannot access frame of function __dgliteral1 What's going on? How do I do it right? I figure I probably have some sort of problem with strings being immutable(char)[] instead of char[], but it doesn't look like that's the issue it's complaining about. Also, in this particular case, I'm not concerned about multi-unit UTF-8 characters.
Re: D2 map trouble
Nick Sabalausky a...@a.a wrote in message news:i2no7g$eu...@digitalmars.com... Trying to convert some D1 code to D2: On 2.047, I'm trying to do this: import std.string; void foo(string str) { str = std.algorithm.map!( (char a) { return inPattern(a, [digits, letters])? a : '_'; } )(str); } And I'm getting: delegate std.algorithm.__dgliteral1 cannot access frame of function __dgliteral1 What's going on? How do I do it right? I figure I probably have some sort of problem with strings being immutable(char)[] instead of char[], but it doesn't look like that's the issue it's complaining about. Also, in this particular case, I'm not concerned about multi-unit UTF-8 characters. In my particular case, I've just switched to regex: import std.regex; str = replace(str, regex([^a-zA-Z0-9]), _); But I am still curious to hear what exactly was going on with map.
Re: D2 map trouble
On 28.07.2010 3:06, Nick Sabalausky wrote: Nick Sabalauskya...@a.a wrote in message news:i2no7g$eu...@digitalmars.com... Trying to convert some D1 code to D2: On 2.047, I'm trying to do this: import std.string; void foo(string str) { str = std.algorithm.map!( (char a) { return inPattern(a, [digits, letters])? a : '_'; } )(str); } And I'm getting: delegate std.algorithm.__dgliteral1 cannot access frame of function __dgliteral1 What's going on? How do I do it right? I figure I probably have some sort of problem with strings being immutable(char)[] instead of char[], but it doesn't look like that's the issue it's complaining about. Also, in this particular case, I'm not concerned about multi-unit UTF-8 characters. In my particular case, I've just switched to regex: import std.regex; str = replace(str, regex([^a-zA-Z0-9]), _); But I am still curious to hear what exactly was going on with map. AFAIK weird compiler bug. See also thread about std.find which involves the problem with map http://www.digitalmars.com/d/archives/digitalmars/D/Improving_std.algorithm.find_113545.html#N113558 -- Dmitry Olshansky