<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Searching the abstract form in erlang</title>
	<atom:link href="http://nickelcode.com/2009/04/22/searching-the-abstract-form-in-erlang/feed/" rel="self" type="application/rss+xml" />
	<link>http://nickelcode.com/2009/04/22/searching-the-abstract-form-in-erlang/</link>
	<description>penny for your thoughts, nickel for your code</description>
	<lastBuildDate>Wed, 12 May 2010 20:15:34 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: John Bender</title>
		<link>http://nickelcode.com/2009/04/22/searching-the-abstract-form-in-erlang/comment-page-1/#comment-2083</link>
		<dc:creator>John Bender</dc:creator>
		<pubDate>Fri, 24 Apr 2009 20:54:31 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=274#comment-2083</guid>
		<description>@Hynek

I agree they are hard to debug (for example the Name in checking for a function), but without my desired 
&lt;pre&gt; {something, _, _} == OtherThing &lt;/pre&gt;

 its the quickest solution for providing a &quot;Matcher&quot; of sorts.</description>
		<content:encoded><![CDATA[<p>@Hynek</p>
<p>I agree they are hard to debug (for example the Name in checking for a function), but without my desired </p>
<pre> {something, _, _} == OtherThing </pre>
<p> its the quickest solution for providing a &#8220;Matcher&#8221; of sorts.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hynek (Pichi) Vychodil</title>
		<link>http://nickelcode.com/2009/04/22/searching-the-abstract-form-in-erlang/comment-page-1/#comment-2082</link>
		<dc:creator>Hynek (Pichi) Vychodil</dc:creator>
		<pubDate>Fri, 24 Apr 2009 19:29:07 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=274#comment-2082</guid>
		<description>And one more suggestion, avoid using macros on all places where functions or  high order functions can be used. It is necessary only for pattern matching. If you are afraid about performance use &lt;code&gt;-code(inline).&lt;/code&gt; or explicit &lt;code&gt;-compile({inline, [{turn_cw, 1}, {turn_ccw, 1}]}).&lt;/code&gt; You can use it even in &lt;code&gt;.hrl&lt;/code&gt; files. To suppress unused function warnings you should use &lt;code&gt;-compile({nowarn_unused_function, [{turn_cw, 1}, {turn_ccw, 1}]}).&lt;/code&gt; for your checks you can introduce
&lt;pre&gt;
-export([call_check/1, function_check/1]).

call_check(Name) -&gt;
  fun(Form) -&gt;
    case Form of
      {call,_,{atom,_,Name},_} -&gt; true;
      _ -&gt; false
    end
  end.

function_check(Name) -&gt;
  fun(Form) -&gt;
    case Form of
      {function,_,Name,_,_} -&gt; true;
      _ -&gt; false
    end
  end.
&lt;/pre&gt;and usage:
&lt;pre&gt;
foo(Form, Name) -&gt;
    find(Form, util:call_check(Name)).
&lt;/pre&gt;
or even in &lt;code&gt;.hrl&lt;/code&gt;:
&lt;pre&gt;
%if there are performance reasons
%-compile({inline, [{call_check, 1}, {function_check, 1}]}).

%avoid warning
-compile({nowarn_unused_function, [{call_check, 1}, {function_check, 1}]}).

call_check(Name) -&gt;
  fun(Form) -&gt;
    case Form of
      {call,_,{atom,_,Name},_} -&gt; true;
      _ -&gt; false
    end
  end.

function_check(Name) -&gt;
  fun(Form) -&gt;
    case Form of
      {function,_,Name,_,_} -&gt; true;
      _ -&gt; false
    end
  end.
&lt;/pre&gt;
uasge:
&lt;pre&gt;
-include(&quot;util.hrl&quot;).

foo(Form, Name) -&gt;
    find(Form, call_check(Name)).
&lt;/pre&gt;Macros are hard to debug and maintenance.</description>
		<content:encoded><![CDATA[<p>And one more suggestion, avoid using macros on all places where functions or  high order functions can be used. It is necessary only for pattern matching. If you are afraid about performance use <code>-code(inline).</code> or explicit <code>-compile({inline, [{turn_cw, 1}, {turn_ccw, 1}]}).</code> You can use it even in <code>.hrl</code> files. To suppress unused function warnings you should use <code>-compile({nowarn_unused_function, [{turn_cw, 1}, {turn_ccw, 1}]}).</code> for your checks you can introduce</p>
<pre>
-export([call_check/1, function_check/1]).

call_check(Name) -&gt;
  fun(Form) -&gt;
    case Form of
      {call,_,{atom,_,Name},_} -&gt; true;
      _ -&gt; false
    end
  end.

function_check(Name) -&gt;
  fun(Form) -&gt;
    case Form of
      {function,_,Name,_,_} -&gt; true;
      _ -&gt; false
    end
  end.
</pre>
<p>and usage:</p>
<pre>
foo(Form, Name) -&gt;
    find(Form, util:call_check(Name)).
</pre>
<p>or even in <code>.hrl</code>:</p>
<pre>
%if there are performance reasons
%-compile({inline, [{call_check, 1}, {function_check, 1}]}).

%avoid warning
-compile({nowarn_unused_function, [{call_check, 1}, {function_check, 1}]}).

call_check(Name) -&gt;
  fun(Form) -&gt;
    case Form of
      {call,_,{atom,_,Name},_} -&gt; true;
      _ -&gt; false
    end
  end.

function_check(Name) -&gt;
  fun(Form) -&gt;
    case Form of
      {function,_,Name,_,_} -&gt; true;
      _ -&gt; false
    end
  end.
</pre>
<p>uasge:</p>
<pre>
-include("util.hrl").

foo(Form, Name) -&gt;
    find(Form, call_check(Name)).
</pre>
<p>Macros are hard to debug and maintenance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Bender</title>
		<link>http://nickelcode.com/2009/04/22/searching-the-abstract-form-in-erlang/comment-page-1/#comment-2080</link>
		<dc:creator>John Bender</dc:creator>
		<pubDate>Fri, 24 Apr 2009 18:44:59 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=274#comment-2080</guid>
		<description>@Hynek

The head matching in a fun is awesome, I hadn&#039;t even considered doing that as I&#039;ve never seen it before. That is super clean.</description>
		<content:encoded><![CDATA[<p>@Hynek</p>
<p>The head matching in a fun is awesome, I hadn&#8217;t even considered doing that as I&#8217;ve never seen it before. That is super clean.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hynek (Pichi) Vychodil</title>
		<link>http://nickelcode.com/2009/04/22/searching-the-abstract-form-in-erlang/comment-page-1/#comment-2079</link>
		<dc:creator>Hynek (Pichi) Vychodil</dc:creator>
		<pubDate>Fri, 24 Apr 2009 18:37:37 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=274#comment-2079</guid>
		<description>Another suggestion:

&lt;pre&gt;
-define(call_check, fun({call,_,{atom,_,Name},_}) -&gt; true;
                       (_) -&gt; false
                    end).

-define(function_check, fun({_, _, Name, _, _}) -&gt; true;
                           (_) -&gt; false
                        end).
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Another suggestion:</p>
<pre>
-define(call_check, fun({call,_,{atom,_,Name},_}) -&gt; true;
                       (_) -&gt; false
                    end).

-define(function_check, fun({_, _, Name, _, _}) -&gt; true;
                           (_) -&gt; false
                        end).
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Bender</title>
		<link>http://nickelcode.com/2009/04/22/searching-the-abstract-form-in-erlang/comment-page-1/#comment-2030</link>
		<dc:creator>John Bender</dc:creator>
		<pubDate>Thu, 23 Apr 2009 16:35:38 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=274#comment-2030</guid>
		<description>@Hynek

That erl_syntax_lib was probably what I was looking for when I was on #erlang the other night. Didn&#039;t get a response, but thanks for the insight!</description>
		<content:encoded><![CDATA[<p>@Hynek</p>
<p>That erl_syntax_lib was probably what I was looking for when I was on #erlang the other night. Didn&#8217;t get a response, but thanks for the insight!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hynek (Pichi) Vychodil</title>
		<link>http://nickelcode.com/2009/04/22/searching-the-abstract-form-in-erlang/comment-page-1/#comment-2027</link>
		<dc:creator>Hynek (Pichi) Vychodil</dc:creator>
		<pubDate>Thu, 23 Apr 2009 15:24:39 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=274#comment-2027</guid>
		<description>find(Form, CompareFun) when is_list(Form) -&gt;
[ Y &#124;&#124; X &lt;- Form, Y &lt;- find(X, CompareFun) ].
find(Form, CompareFun) -&gt;
lists:reverse(
erl_syntax_lib:fold(
fun(N, R) -&gt;
case CompareFun(N) of
true -&gt; [N&#124;R];
_ -&gt; R
end
end, [], X
)
).</description>
		<content:encoded><![CDATA[<p>find(Form, CompareFun) when is_list(Form) -&gt;<br />
[ Y || X &lt;- Form, Y &lt;- find(X, CompareFun) ].<br />
find(Form, CompareFun) -&gt;<br />
lists:reverse(<br />
erl_syntax_lib:fold(<br />
fun(N, R) -&gt;<br />
case CompareFun(N) of<br />
true -&gt; [N|R];<br />
_ -&gt; R<br />
end<br />
end, [], X<br />
)<br />
).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
