<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Samet Kilictas&#039;s Blog &#187; intersect</title>
	<atom:link href="http://samet.kilictas.com/tag/intersect/feed/" rel="self" type="application/rss+xml" />
	<link>http://samet.kilictas.com</link>
	<description>J2E, PHP, Linux, PL/SQL and other random rants</description>
	<lastBuildDate>Sun, 06 Nov 2011 04:36:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Example Code #4 &#8211; Intersect and Write in Prolog</title>
		<link>http://samet.kilictas.com/example-code-4-intersect-and-write-in-prolog/</link>
		<comments>http://samet.kilictas.com/example-code-4-intersect-and-write-in-prolog/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 12:13:38 +0000</pubDate>
		<dc:creator>Samet Kilictas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Prolog]]></category>
		<category><![CDATA[append]]></category>
		<category><![CDATA[intersect]]></category>
		<category><![CDATA[member]]></category>

		<guid isPermaLink="false">http://samet.kilictas.com/?p=221</guid>
		<description><![CDATA[1- &#8220;!&#8221; character stops the query when it is false and &#8220;;&#8221; runs as &#8220;or&#8221; so it skips the false part then moves next part smaller(X,Y):- X X&#62;Y,write(Y),write(' is bigger then '),write(X),!; write('They are equal'). Query -&#62; ?smaller(3,5) : 3 is smaller then 5 Query -&#62; ?smaller(8,5) : 8 is bigger then 5 Query -&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>1- &#8220;!&#8221; character stops the query when it is false and &#8220;;&#8221; runs as &#8220;or&#8221; so it skips the false part then moves next part</strong></p>
<p><code>smaller(X,Y):- X<br />
X&gt;Y,write(Y),write(' is bigger then '),write(X),!;<br />
write('They are equal').</code></p>
<p>Query -&gt; <code>?smaller(3,5)  : 3 is smaller then 5</code><br />
Query -&gt; <code>?smaller(8,5)  : 8 is bigger then 5</code><br />
Query -&gt; <code>?smaller(5,5)  : They are equal</code></p>
<p><strong>2- Intersect relation</strong></p>
<p>Intersect function uses an external function inside. Member function checks whether the first parameter is member of the given list or not.</p>
<p>Query -&gt; <code>member(3,[3,4,5]).</code></p>
<p><code>member(HM,[HM|TM]).<br />
member(XM,[HM|TM]):- member(XM,TM).</code></p>
<p>and the intersect function gives you the result on LI variable. Try it.</p>
<p>intersect([ ],LI,[ ]).<br />
intersect([HI|TI],LI,LI2):- member(HI,LI),intersect(TI,LI,LI3),LI2=[HI|LI3],!;intersect(TI,LI,LI2).</p>
<p>Query -&gt; <code>intersect([3,4],LI,[4,5]) : [4]</code></p>
<a href='http://twitter.com/share?url=http%3A%2F%2Fsamet.kilictas.com%2F%3Fp%3D221&count=vertical&related=&text=Example%20Code%20%234%20-%20Intersect%20and%20Write%20in%20Prolog' class='twitter-share-button' data-text='Example Code #4 - Intersect and Write in Prolog' data-url='http://samet.kilictas.com/?p=221' data-counturl='http://samet.kilictas.com/example-code-4-intersect-and-write-in-prolog/' data-count='vertical' data-via='sametkilictas'>Tweet</a>]]></content:encoded>
			<wfw:commentRss>http://samet.kilictas.com/example-code-4-intersect-and-write-in-prolog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

