<div class="gmail_quote">On Wed, Jul 28, 2010 at 01:06, Nick Sabalausky <span dir="ltr"><a@a.a></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
"Nick Sabalausky" <a@a.a> wrote in message<br>
news:i2no7g$euv$1@digitalmars.com...<br>
<div><div></div><div class="h5">> Trying to convert some D1 code to D2:<br>
><br>
> On 2.047, I'm trying to do this:<br>
><br>
> import std.string;<br>
> void foo(string str)<br>
> {<br>
> str =<br>
> std.algorithm.map!(<br>
> (char a) { return inPattern(a, [digits, letters])? a : '_'; }<br>
> )(str);<br>
> }<br>
><br>
> And I'm getting:<br>
><br>
> delegate std.algorithm.__dgliteral1 cannot access frame of function<br>
> __dgliteral1<br>
><br>
> What's going on? How do I do it right? I figure I probably have some sort<br>
> of problem with strings being immutable(char)[] instead of char[], but it<br>
> doesn't look like that's the issue it's complaining about. Also, in this<br>
> particular case, I'm not concerned about multi-unit UTF-8 characters.<br>
><br>
><br>
<br>
</div></div>In my particular case, I've just switched to regex:<br>
<br>
import std.regex;<br>
str = replace(str, regex("[^a-zA-Z0-9]"), "_");<br>
<br>
But I am still curious to hear what exactly was going on with map.<br>
<br>
<br></blockquote><div> </div></div>It's an error I get on a weekly basis :-(<div>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.<br>
<div><br><div>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?</div><div>Another is to use 'string functions', I think. I can test right now, but something like might work:</div>
<div><br></div><div>void foo(string str)<br>{<br> str =<br> std.algorithm.map!q{<br> inPattern(a, [digits, letters])? a : '_'; </div><div>}<br> (str);<br>}</div></div></div><div><br></div><div>But then I guess inPattern must be visible from std.algorithm.</div>
<div><br></div><div>So my current conclusion it that it's more a limitation of anonymous closures than a limitation in map.</div><div><br></div><div>Philippe</div><div><br></div>