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