<?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>greynode &#187; functional</title>
	<atom:link href="http://greynode.org/tag/functional/feed/" rel="self" type="application/rss+xml" />
	<link>http://greynode.org</link>
	<description>ingénierie de tous les aspects de vie</description>
	<lastBuildDate>Wed, 11 Aug 2010 04:10:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Functional Programming with the Unix Command Line</title>
		<link>http://greynode.org/2009/06/25/functional-programming-with-the-unix-command-line/</link>
		<comments>http://greynode.org/2009/06/25/functional-programming-with-the-unix-command-line/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 06:29:30 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[one liners]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripting languages]]></category>

		<guid isPermaLink="false">http://greynode.org/?p=66</guid>
		<description><![CDATA[I was pondering the unix command line the other day while reading sed &#38; awk, and I came to the following revelation: variables aside, the unix command line is a lot like functional programming. Using the command line, you can build a functional program by redirecting I/O between various programs, or functions. Many of the [...]]]></description>
			<content:encoded><![CDATA[<p>I was pondering the unix command line the other day while reading <em>sed &amp; awk</em>, and I came to the following revelation: variables aside, the unix command line is a lot like functional programming. Using the command line, you can build a functional program by redirecting I/O between various programs, or <em>functions</em>. Many of the programs one uses to build one-liners are essentially <a href="http://en.wikipedia.org/wiki/Pure_function"><strong>pure functions</strong></a>. An example of a pure function on the unix command line might be the programs <em>uniq</em> or <em>sort</em>. Various other functions such as <em>ps</em> and <em>wget</em> are not so pure, as their output relies on I/O with the operating sytem or server.</p>
<p>All theory aside, here are a few good one-liners.</p>
<h2>Uploading Files</h2>
<blockquote>
<pre>tar cjvf - yourDirectory | ssh uname@host "cat &gt; yourDirectory.tar.bz2"</pre>
</blockquote>
<p>This command will create an archive of &#8220;yourDirectory&#8221; and upload it to your server via SSH, all in one chained command. Quite handy for uploading local content for sharing or backup.</p>
<p><strong>Edit:</strong> Apparently this command transfers large files extremely slow. Oops.</p>
<h2>Checking FreeBSD UPDATING File Automatically</h2>
<blockquote>
<pre>portversion | awk '/&lt;/ {print $1}' |
xargs -I '{}' awk '/AFFECTS:.*{}/ {print}' /usr/ports/UPDATING &gt; updates.txt</pre>
</blockquote>
<p>Ok. So this command pertains to the FreeBSD ports system. It is not recommended that you upgrade all your ports at once. There is often information contained in the file /usr/ports/UPDATING about special instructions you may have to follow while upgrading a package. Often times you may have to recompile other packages, or add a line to a configuration file, etc. The string above will check all of the ports tht are out of date, and compare them to the UPDATING file to see if the package is contained. If it is, it writes the name of that port to updates.txt. You can then use this file to know which ports have special instructions. You should probably write an alias for this one.</p>
<h2>Converting Line Endings</h2>
<p>The following two commands should help with reformatting files. Often times I find myself getting web designs from someone who uses windows. Most editors on windows will save files with DOS line endings. When you open one of these files in unix (in certain editors), the line endings won&#8217;t appear properly. The following commands will circumvent this problem, in either situation.</p>
<h3>Convert from unix (\n) to DOS (\r\n)</h3>
<blockquote>
<pre>awk '{sub(/$/, "\r")};1' unix_endings.txt &gt; dos_endings.txt</pre>
</blockquote>
<h3>Convert from DOS (\r\n) to unix (\n)</h3>
<blockquote>
<pre>awk '{sub(/\r$/, "")};1' dos_endings.txt &gt; unix_endings.txt</pre>
</blockquote>
<p>And yes, I realize that I use too many commas when I write: I&#8217;m working on it.</p>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/06/25/functional-programming-with-the-unix-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Haskell</title>
		<link>http://greynode.org/2009/05/17/9/</link>
		<comments>http://greynode.org/2009/05/17/9/#comments</comments>
		<pubDate>Mon, 18 May 2009 06:56:20 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.greynode.org/?p=9</guid>
		<description><![CDATA[I have recently been continuing my journey with Haskell, the purely functional programming language. I had dabbled with it a little bit over the winter, but haven&#8217;t had much practice since then. It is my hope that over the summer I will be able to get a fair amount of practice with the language. I [...]]]></description>
			<content:encoded><![CDATA[<p>I have recently been continuing my journey with <a href="http://www.haskell.org">Haskell</a>, the <a href="http://www.haskell.org/haskellwiki/Functional_programming" target="_blank">purely functional programming language</a>. I had dabbled with it a little bit over the winter, but haven&#8217;t had much practice since then. It is my hope that over the summer I will be able to get a fair amount of practice with the language.</p>
<p>I have settled on using the book <a href="http://www.realworldhaskell.org/" target="_blank">Real World Haskell</a> as my first stepping stone. It has gotten good reviews, and was recommended to me by one of my professors. There is a <a href="http://book.realworldhaskell.org/read/">free version of it online</a>, if you wish to check it out. It uses quite a bit of comparison with imperative languages, at least in the early chapters, so I don&#8217;t recommend it to someone who has never programmed before.</p>
<p>For those of you who are not familiar with functional programming, I am going to present to you a few problems and the elegant solutions provided by Haskell. The first I will show you is an implementation of quicksort.</p>
<pre>qsort (x:xs) = qsort (filter (&lt; x) xs) ++ [x] ++ qsort (filter (&gt;= x) xs)</pre>
<p>This implementation of quicksort is so clean it makes me sick. It is essentially the definition of the quicksort algorithm. Because of the facilities provided by Haskell, it translates quite nicely.</p>
<p>Another problem I&#8217;d like to show you involves counting. Say you had a string of words, and you would like to count the number of words that start with an upper-case letter. In an imperative language, this might involve several loops and/or the use of regular expressions. With Haskell, its a simple matter of function composition. Have a look:</p>
<pre>capCount = length . filter (isUpper . head) . words</pre>
<p>This might look odd if you are not familiar with functional programming or function composition, but it is a really simple function. The &#8216;.&#8217; operator simply takes the output from the function on the right, and feeds it into the function on the left. The &#8216;words&#8217; function breaks a string up into a list of words wherever there is a space. The &#8216;head&#8217; function returns the first element of the list, &#8216;isUpper&#8217; will return a boolean value saying whether or not a Character is upper-case, &#8216;filter&#8217; applies a function over a list and removes items that evaluate to False, and &#8216;length&#8217; returns the length of the list. As you can see, it&#8217;s much easier to describe with code than with words.</p>
<p>Anyway, I will be posting anything I find interesting on here. Hopefully someone other than myself will benefit from it.</p>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/05/17/9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->