<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.3" -->
<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/"
	>

<channel>
	<title>Anodyne</title>
	<link>http://www.anodyne.ca</link>
	<description></description>
	<pubDate>Wed, 24 Dec 2008 00:38:14 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>
	<language>en</language>
			<item>
		<title>Erlang Notes - Records</title>
		<link>http://www.anodyne.ca/2008/12/23/erlang-notes-records/</link>
		<comments>http://www.anodyne.ca/2008/12/23/erlang-notes-records/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 00:38:14 +0000</pubDate>
		<dc:creator>grant.mcinnes</dc:creator>
		
		<category><![CDATA[erlang]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.anodyne.ca/2008/12/23/erlang-notes-records/</guid>
		<description><![CDATA[Here is the eighth of some notes about erlang.
Obviously this is a very cursory glance at things. It’s really just notes to help me remember things. If you’re looking for something in more detail you can take a look at the erlang reference manual.
Records
Records are a way of providing a names for elements of tuples.
Record [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the eighth of some notes about erlang.<br />
Obviously this is a very cursory glance at things. It’s really just notes to help me remember things. If you’re looking for something in more detail you can take a look at the <a href ="http://www.erlang.org/doc/reference_manual/part_frame.html">erlang reference manual.</a></p>
<h2>Records</h2>
<p>Records are a way of providing a names for elements of tuples.</p>
<p>Record declarations are created in .hrl files with a syntax like:</p>
<p><code><br />
-record(events, {day=monday,name=hangover}).<br />
</code></p>
<p>This gives us the ability to create a new event record with attributes of day and name.  Like this:</p>
<p><code><br />
X1 = #event{day=monday,name=hangover}).<br />
</code></p>
<p>Remember, its really just a tuple, but because we make it a record, it gets to have names for its variables. We can pattern match to get the variables out of the record.  To get the values out of X1 above for example:</p>
<p><code><br />
#event{day=D,name=N} = X1.<br />
D.<br />
monday<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anodyne.ca/2008/12/23/erlang-notes-records/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Erlang Notes - Gaurds and gaurd sequences</title>
		<link>http://www.anodyne.ca/2008/12/22/erlang-notes-gaurds-and-gaurd-sequences/</link>
		<comments>http://www.anodyne.ca/2008/12/22/erlang-notes-gaurds-and-gaurd-sequences/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 01:06:14 +0000</pubDate>
		<dc:creator>grant.mcinnes</dc:creator>
		
		<category><![CDATA[erlang]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.anodyne.ca/2008/12/22/erlang-notes-gaurds-and-gaurd-sequences/</guid>
		<description><![CDATA[Here is the seventh of some notes about erlang.
Obviously this is a very cursory glance at things. It’s really just notes to help me remember things. If you’re looking for something in more detail you can take a look at the erlang reference manual.
Guards
As far as I understand, guards provide an enhancement to pattern matching, [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the seventh of some notes about erlang.<br />
Obviously this is a very cursory glance at things. It’s really just notes to help me remember things. If you’re looking for something in more detail you can take a look at the <a href ="http://www.erlang.org/doc/reference_manual/part_frame.html">erlang reference manual.</a></p>
<h2>Guards</h2>
<p>As far as I understand, guards provide an enhancement to pattern matching, allowing us to enhance our pattern matching abilities by testing the values of variables.  I&#8217;m not quite sure exactly where guards can be used: No limitations on where are mentioned yet, so I&#8217;m going to assume that you can use them anywhere you are using pattern matching, although it seems a bit odd to use them on the RHS of an expression.</p>
<p>The simplest example of a guard is probably something like:</p>
<p><code><br />
  sqrt(X) when X < 0  -> exit(dumbValue).<br />
</code> </p>
<p>In this case when we call sqrt with a value less than 0 we&#8217;ll exit.  Pretty straight forward.</p>
<h3>Guard sequences</h3>
<p>We can also combine guard clauses to give us more complex checks:</p>
<p><code><br />
  sqrt(X) when X < 0,  X < 20 -> exit(notInValue).<br />
</code></p>
<p>Guard sequences are simply separate guard clauses conjoined in some way.  They typical way they are conjoined is simply by a comma as above, in which case the comma represents an &#8216;and&#8217; statement.  They can also be combined by  short-circuit boolean operators <strong>andalso</strong> or <strong>orelse</strong>, or by the normal boolean operators <strong>or</strong> or <strong>and</strong>.</p>
<p>These cases function much as you would expect, with short-circuit boolean expressions functioning as in other languages.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anodyne.ca/2008/12/22/erlang-notes-gaurds-and-gaurd-sequences/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Erlang Notes - List comprehensions</title>
		<link>http://www.anodyne.ca/2008/12/13/erlang-notes-list-comprehensions/</link>
		<comments>http://www.anodyne.ca/2008/12/13/erlang-notes-list-comprehensions/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 02:09:41 +0000</pubDate>
		<dc:creator>grant.mcinnes</dc:creator>
		
		<category><![CDATA[erlang]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.anodyne.ca/2008/12/13/erlang-notes-list-comprehensions/</guid>
		<description><![CDATA[Here is the sixth of some notes about erlang.
Obviously this is a very cursory glance at things. It’s really just notes to help me remember things. If you’re looking for something in more detail you can take a look at the erlang reference manual.
List comprehensions
I first encountered List Comprehensions in Python, and they were one [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the sixth of some notes about erlang.<br />
Obviously this is a very cursory glance at things. It’s really just notes to help me remember things. If you’re looking for something in more detail you can take a look at the <a href ="http://www.erlang.org/doc/reference_manual/part_frame.html">erlang reference manual.</a></p>
<h2>List comprehensions</h2>
<p>I first encountered List Comprehensions in Python, and they were one of the things I loved, and missed as I started working in Ruby more.  In principle, they are a simple way to define a mapping from one list to another.  Here&#8217;s the notation in Erlang:</p>
<p><code></p>
<p>[2*X || X <- L].</p>
<p></code></p>
<p>This concise piece of code says something like: take each of the elements from the list L, and map them as element X into a new list defined by the function 2 times X.</p>
<p>Of course, the function you apply to the elements of the list could be a good deal more complex, and probably would be in real life.</p>
<p>There are some quite interesting isolated examples of list comprehension in Joe Armstrong&#8217;s book, including a terse quicksort implementation, but I don&#8217;t think there&#8217;s much more to say about them here, out of the context of a real application</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anodyne.ca/2008/12/13/erlang-notes-list-comprehensions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Have you watched Giles Bowkett yet?</title>
		<link>http://www.anodyne.ca/2008/10/02/have-you-watched-giles-bowkett-yet/</link>
		<comments>http://www.anodyne.ca/2008/10/02/have-you-watched-giles-bowkett-yet/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 16:50:14 +0000</pubDate>
		<dc:creator>grant.mcinnes</dc:creator>
		
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.anodyne.ca/2008/10/02/have-you-watched-giles-bowkett-yet/</guid>
		<description><![CDATA[Have you seen Giles Bowkett yet?
This is hands down the best talk I have ever seen at a conference.  
I don&#8217;t know if the feeling comes across on the video, but I have never seen the kind of reaction to a talk that Giles got to this talk at RubyFringe.  The room was [...]]]></description>
			<content:encoded><![CDATA[<p>Have you seen <a href="http://www.infoq.com/presentations/archaeopteryx-bowkett">Giles Bowkett</a> yet?</p>
<p>This is hands down the best talk I have ever seen at a conference.  </p>
<p>I don&#8217;t know if the feeling comes across on the video, but I have never seen the kind of reaction to a talk that Giles got to this talk at RubyFringe.  The room was totally electric and he had a minute long standing ovation at the end of the talk.  The hair was standing up on the back of my neck.</p>
<p>People left the room for lunch afterwards with stunned looks on their faces.  Even Giles seemed to be amazed by the response he got, judging by the look on his face.</p>
<p>Absolutely recommended.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.anodyne.ca/2008/10/02/have-you-watched-giles-bowkett-yet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Erlang Notes - Higher order functions</title>
		<link>http://www.anodyne.ca/2008/09/27/erlang-notes-higher-order-functions/</link>
		<comments>http://www.anodyne.ca/2008/09/27/erlang-notes-higher-order-functions/#comments</comments>
		<pubDate>Sat, 27 Sep 2008 16:50:38 +0000</pubDate>
		<dc:creator>grant.mcinnes</dc:creator>
		
		<category><![CDATA[erlang]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.anodyne.ca/2008/09/27/erlang-notes-higher-order-functions/</guid>
		<description><![CDATA[Here is the fifth of some notes about erlang.
Obviously this is a very cursory glance at things. It’s really just notes to help me remember things. If you’re looking for something in more detail you can take a look at the erlang reference manual.
Higher order functions
A higher order function is any function which does one [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the fifth of some notes about erlang.<br />
Obviously this is a very cursory glance at things. It’s really just notes to help me remember things. If you’re looking for something in more detail you can take a look at the <a href ="http://www.erlang.org/doc/reference_manual/part_frame.html">erlang reference manual.</a></p>
<h2>Higher order functions</h2>
<p>A higher order function is any function which does one or more of the following:</p>
<ul>
<li>
    Takes one or more functions as its input
  </li>
<li>
     Returns a function as its output
  </li>
</ul>
<h3>Functions that take functions as an argument</h3>
<p>
We already saw some examples of this in the last section.  Remember this code:<br />
<code><br />
1> List = [2,4,6,8,10].<br />
[2,4,6,8,10]<br />
2> Triple = fun(X) -> 3 * X end.<br />
#Fun<erl_eval.6.13229925><br />
3> lists:map(Triple, List).<br />
[6,12,18,24,30]<br />
</code></p>
<p>In this code, lists:map takes a function as an argument and applies the function to each member of the passed in list.  A map function is a very common example of this pattern.  I would expect that its fairly fundamental to any language that allows functions to be passed around as first class entities.
</p>
<h3>Functions that return functions</h3>
<p>Functions that return functions are somewhat less common, but they can be useful to help us write generic code that can be parameterized at runtime to do different things.  Here&#8217;s some imaginary, untested, code to help get the point across:<br />
<code><br />
1> % Imagine some readings of various types exist&#8230;<br />
1>MakeReadingFinder = fun(Type) -> (fun(DateRange) -> readings:find(Type, Date) end end.<br />
#Fun<erl_eval.6.56006484><br />
2>BeforeBreakfastReadingFinder = MakeReadingFinder(before_breakfast).<br />
#Fun<erl_eval.6.5600484><br />
3>BeforeBreakfastReadingFinder(now()).<br />
% Readings are magically returned!</p>
<p></code></p>
<p>Although the example isn&#8217;t perfectly clear (there&#8217;s a better one on pg. 45 of <em>Programming Erlang</em>) you can see that what we&#8217;re doing is using the ability to return a function as a way to fill in some of the returned functions parameters before we use it.</p>
<p>This allows us to parameterize the function, and is probably going to be ideal for implementing Factory patterns etc. very simply.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anodyne.ca/2008/09/27/erlang-notes-higher-order-functions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Erlang Notes - Anonymous functions</title>
		<link>http://www.anodyne.ca/2008/09/24/erlang-notes-anonymous-functions/</link>
		<comments>http://www.anodyne.ca/2008/09/24/erlang-notes-anonymous-functions/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 01:47:04 +0000</pubDate>
		<dc:creator>grant.mcinnes</dc:creator>
		
		<category><![CDATA[erlang]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.anodyne.ca/2008/09/24/erlang-notes-anonymous-functions/</guid>
		<description><![CDATA[Here is the fourth of some notes about erlang.
Obviously this is a very cursory glance at things. It’s really just notes to help me remember things. If you’re looking for something in more detail you can take a look at the erlang reference manual.
Anonymous functions
Anonymous functions in erlang are known as funs.
Funs work mostly like [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the fourth of some notes about erlang.<br />
Obviously this is a very cursory glance at things. It’s really just notes to help me remember things. If you’re looking for something in more detail you can take a look at the <a href ="http://www.erlang.org/doc/reference_manual/part_frame.html">erlang reference manual.</a></p>
<h3>Anonymous functions</h3>
<p>Anonymous functions in erlang are known as <em>funs</em>.</p>
<p>Funs work mostly like regular functions - they can take any number of arguments, the arguments can be of any type, and the function can have multiple clauses.  The thing that makes anonymous functions useful is that they can be bound to a variable.  For example:<br />
<code><br />
1> Half = fun(X) -> X / 2 end.<br />
#Fun<erl_eval.6.13229925><br />
2> Half(3).<br />
1.5<br />
</code><br />
Or, with multiple clauses:<br />
<code><br />
1> DistanceConvert = fun({miles, M}) -> {kilometers, 1.609344 * M};<br />
1>                               ({kilometers, K}) -> {miles, 0.6213   * K}<br />
1>                           end.<br />
#Fun<erl_eval.6.13229925><br />
2> DistanceConvert({miles, 10}).<br />
{kilometers,16.09344}<br />
3> DistanceConvert({kilometers, 15}).<br />
{miles,9.3195}<br />
</code><br />
Many other languages allow anonymous functions bound to variables.  Think of Ruby or Python&#8217;s lambdas or, as an even closer analogy, of Javascript&#8217;s assignment of methods to variables.</p>
<h3>Anonymous functions as arguments</h3>
<p>Much like Javascript or Ruby, you can use these anonymous functions as arguments to other functions.  This enables us to perform list wide operations using internal iterators, and to perform operations such as map and filter.  For example:<br />
<code><br />
1> List = [2,4,6,8,10].<br />
[2,4,6,8,10]<br />
2> Triple = fun(X) -> 3 * X end.<br />
#Fun<erl_eval.6.13229925><br />
3> lists:map(Triple, List).<br />
[6,12,18,24,30]<br />
</code>
</p>
<p>
As you can imagine, this opens up a lot of power.  As far as I can tell the syntax for passing in funs allows you to pass them in as any parameter, and to call them inside a function clause body just by using the () call syntax.
</p>
<p>
It would also be interesting to know if funs are full closures.  That is, do they keep their bindings with them when they&#8217;re passed around?  As far as I know, I think they lose it, so they&#8217;re not.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anodyne.ca/2008/09/24/erlang-notes-anonymous-functions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Erlang Notes - Functions</title>
		<link>http://www.anodyne.ca/2008/09/23/erlang-notes-functions/</link>
		<comments>http://www.anodyne.ca/2008/09/23/erlang-notes-functions/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 00:23:46 +0000</pubDate>
		<dc:creator>grant.mcinnes</dc:creator>
		
		<category><![CDATA[erlang]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.anodyne.ca/2008/09/23/erlang-notes-functions/</guid>
		<description><![CDATA[Here is the third of some notes about erlang.  
Obviously this is a very cursory glance at things.  It&#8217;s really just notes to help me remember things.  If you&#8217;re looking for something in more detail you can take a look at the erlang reference manual.
Functions
Functions in erlang are consist of multiple clauses. [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the third of some notes about erlang.  </p>
<p>Obviously this is a very cursory glance at things.  It&#8217;s really just notes to help me remember things.  If you&#8217;re looking for something in more detail you can take a look at the <a href="http://www.erlang.org/doc/reference_manual/part_frame.html">erlang reference manual.</a></p>
<h2>Functions</h2>
<p>Functions in erlang are consist of multiple clauses.  Each clause is separated by a semicolon and the final clause is terminated by a dot-whitespace.  For example:<br />
  <code><br />
    utter(dog)  -> &#8220;woof&#8221;;<br />
    utter(cat)   -> &#8220;meow&#8221;;<br />
    utter(cow)  -> &#8220;moo&#8221;.<br />
  </code><br />
In the case above we have a function <strong>utter</strong> with three <em>clauses</em>.  Each of the clauses has a <em>head</em> and a <em>body</em>.
</p>
<h3>The head</h3>
<ul>
<li>
       The head is a function name then a <em>pattern</em><br />
in parens, such as:<br />
      <code><br />
         utter(cow)</p>
<p>      </code>
     </li>
<li>
       The pattern in the head is pattern matched based on the parameters passed when the function is called.  So to execute the clause with the head defined above we would write:<br />
       <code><br />
           utter(cow).</p>
<p>        </code>
      </li>
<li>
       If there are multiple clauses with heads that match the call, then the first one that matches will be used.
     </li>
</ul>
<h3>The body</h3>
<ul>
<li>
         The body consists of a series of <em>expressions</em>.
       </li>
<li>
          An expression is anything that can be evaluated to produce a value
      </li>
<li>
          You can have a series of expressions, separated by commas to produce an <em>expression sequence</em>.  The value of the expression sequence is the value of the last expression that was evaluated.
       </li>
</ul>
<h3>Putting it all together</h3>
<p>So we have:<br />
    <code><br />
      utter(dog)  -> &#8220;woof&#8221;;<br />
      utter(cat)   -> &#8220;meow&#8221;;<br />
      utter(cow)  -> &#8220;moo&#8221;.</p>
<p>   </code></p>
<p>   Tweaking an example from the great <em>Programming Erlang</em>, we can do:<br />
   <code><br />
       -module(perimiter).<br />
       -compile(export_all).</p>
<p>       perimiter({square, Distance})   ->   Distance * 4;<br />
       perimiter({rectangle, With, Height})   -> Width * Height * 2.</p>
<p>   </code><br />
Where you can see that having multiple clauses for a function, combined with tuples allows us to implement a sort of polymorphism.</p>
<p>
Another thing to note about functions is that functions with the same name and a different arity are completely different functions.  </p>
<p>That is, area(Radius) is a totally different function from area(Length * Width)  as far as the runtime system is concerned.  </p>
<p>Joe Armstrong says that erlang programmers often use this feature to provide helper functions for a main function, but that makes me throw up in my mouth a little.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anodyne.ca/2008/09/23/erlang-notes-functions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Erlang Notes - Variables and assignment</title>
		<link>http://www.anodyne.ca/2008/09/22/erlang-notes-variables-and-assignment/</link>
		<comments>http://www.anodyne.ca/2008/09/22/erlang-notes-variables-and-assignment/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 00:01:06 +0000</pubDate>
		<dc:creator>grant.mcinnes</dc:creator>
		
		<category><![CDATA[erlang]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.anodyne.ca/2008/09/22/erlang-notes-variables-and-assignment/</guid>
		<description><![CDATA[Here is the second of some notes about erlang.  
Obviously this is a very cursory glance at things.  It&#8217;s really just notes to help me remember things.  If you&#8217;re looking for something in more detail you can take a look at the erlang reference manual.
Variables


       Literals [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the second of some notes about erlang.  </p>
<p>Obviously this is a very cursory glance at things.  It&#8217;s really just notes to help me remember things.  If you&#8217;re looking for something in more detail you can take a look at the <a href="http://www.erlang.org/doc/reference_manual/part_frame.html">erlang reference manual.</a></p>
<h2>Variables</h2>
<ul>
<li>
       Literals starting with an upper case character, such as <strong>Pizza</strong> are variables
    </li>
<li>
      Variables  are single assignment only, meaning that once they are bound to a value, that value cannot be changed.  That&#8217;s different from a lot of languages, obviously, where we can change the values of variables during the run of the program.  For example:<br />
    <code><br />
      1> % Lets assign X to be 6<br />
      1> X = 6.<br />
      6<br />
      2> X = 7.<br />
      ** exception error: no match of right hand side value 7<br />
    </code></p>
<p>     When trying to re-assign a new value to a variable, we get an error message.   The error message complains about bad matching, which leads us into the next issue.
    </li>
</ul>
<h2>Assignment</h2>
<p>      Assignment is slightly different from traditional languages.  It is done by pattern matching the RHS against the LHS of an expression, rather than the more traditional manner of simply plugging the value of the RHS into the LHS.</p>
<h3>Numbers</h3>
<p>
      Pattern matching a number is simple.  If the number or expression on the RHS evaluates to the same number as on the LHS, then there is a match.  For example:<br />
    <code><br />
      1> X = 6.<br />
      6<br />
      2> Y = 2.<br />
      2<br />
      3> X = 7.<br />
      ** exception error: no match of right hand side value 7<br />
      4> X = Y.<br />
      ** exception error: no match of right hand side value 2<br />
      5> X = Y + 4.<br />
      6<br />
    </code>
    </p>
<h3>Tuples</h3>
<p>Matching tuples is a little more complicated.  Of course, you can have a direct match between two tuples, but more commonly, you can extract values from tuples by pattern matching.  Lets say we have a tuple structure that represents an employee and we want to extract the employee name<br />
      <code><br />
         2> % First we&#8217;ll define a tuple<br />
         2> Employee = {employee, {name, grant}}.<br />
         {employee,{name,grant}}<br />
         3> % Now we&#8217;ll pattern match on the tuple to extract the<br />
         3> % particular element we want from the tuple<br />
         3> {employee, {name, EmployeeName}} = Employee.<br />
         {employee,{name,grant}}<br />
         4> % So we expect that the EmployeeName variable<br />
         4> % will have the value grant now.<br />
         4> EmployeeName.<br />
         grant<br />
      </code>
     </p>
<p>Interestingly, this seems to reverse the common pattern of accessing elements deeply nested in structures in more conventional languages.  In ruby, for instance, we might have an example like this:<br />
    <code><br />
      person = {:employee => {:name => &#8216;grant&#8217;}}<br />
      employee_name = person[:employee][:name]<br />
   </code><br />
   In this case we have a naked variable name on the LHS and do some silly walking on the structure on the RHS to get at the value we want.  Erlang reverses this so that we have a naked structure (meaning no function calls or other manipulation) on the RHS and we pattern match our way to the value that we want on the LHS of the expression.
  </p>
<h3>Lists</h3>
<p>Pattern matching Lists seems to be a little more simple.  In general, a list can be pattern matched by the form [A, B, C&#8230; | T]  where A, B and C are variables substituted by the first, second and third elements of the list respectively, and T is substituted by the remaining elements of the list.  For example:<br />
   <code><br />
     1> L = [1,2,3,4,5].<br />
[1,2,3,4,5]<br />
2> [A,B,C | T] = L.<br />
[1,2,3,4,5]<br />
3> A.<br />
1<br />
4> B.<br />
2<br />
5> C.<br />
3<br />
6> T.<br />
[4,5]<br />
7> [A, B, C, D, E, F, G] = L.<br />
** exception error: no match of right hand side value [1,2,3,4,5]<br />
</code><br />
Note that if we run out of elements on the RHS of the expression we&#8217;ll get a bad match type message.  Also, the most common operation with this type of matching is more than likely to remove the head of the list into a variable so that we can work with it, and store the tail of the list for future work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anodyne.ca/2008/09/22/erlang-notes-variables-and-assignment/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Erlang Notes - Simple data types</title>
		<link>http://www.anodyne.ca/2008/09/20/erlang-notes-simple-data-types/</link>
		<comments>http://www.anodyne.ca/2008/09/20/erlang-notes-simple-data-types/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 03:42:05 +0000</pubDate>
		<dc:creator>grant.mcinnes</dc:creator>
		
		<category><![CDATA[erlang]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.anodyne.ca/2008/09/20/erlang-notes-simple-data-types/</guid>
		<description><![CDATA[Here is the first of some notes about erlang.  
Obviously this is a very cursory glance at things.  It&#8217;s really just notes to help me remember things.  If you&#8217;re looking for something in more detail you can take a look at the erlang reference manual.
Basic Data Types
Integers


     Integer [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the first of some notes about erlang.  </p>
<p>Obviously this is a very cursory glance at things.  It&#8217;s really just notes to help me remember things.  If you&#8217;re looking for something in more detail you can take a look at the <a href="http://www.erlang.org/doc/reference_manual/part_frame.html">erlang reference manual.</a></p>
<h2>Basic Data Types</h2>
<h3>Integers</h3>
<ul>
<li>
     Integer arithmetic is arbitrary sized.  Yay for no overflows
  </li>
<li>
    Base 16 and 32 can be represented by 16#1a and 32#1a respectively.  In fact, that<br />
works for arbitrary bases up to 36, I think.  Base 2 is 2#1101
  </li>
</ul>
<h3>Floating-Point Numbers</h3>
<ul>
<li>
    Floating point numbers must have a decimal point followed by at least one decimal digit
  </li>
<li>
    As far as I can tell floats are also aribrarily sized.
  </li>
<li>
    Not sure yet how to specify precision, or if you can.
  </li>
<li>
    Cooercion from integer to float seems to be automatic, if one of the terms is a float
  </li>
</ul>
<h3>Atoms</h3>
<ul>
<li>
    Atoms usually start with lowercase letters.  They can start with uppercase letters or non-alphanumerics if they are enclosed in<br />
   quotes though.
  </li>
<li>
   <strong>foo</strong>, <strong>&#8216;Foo&#8217;</strong>, <strong>&#8216;@Foo&#8217;</strong>, <strong>dave@smith</strong> are all valid atoms
  </li>
<li>
    Atoms are used to represent symbolic constants, similar to Symbols in Ruby, or the #define FOO 1 construct in C
  </li>
</ul>
<h3>Tuples</h3>
<ul>
<li>
    A group of things enclosed in curly braces, <strong>{Foo, bar, 1, &#8220;22&#8243;}</strong> is a tuple
  </li>
<li>
     Tuples group a fixed number of things together.  It performs the same function as a Struct in C or some other type of Record type of data structure
  </li>
<li>
    Tuples seem to be commonly used as a way of differentiating between functions that need to have different behaviours, but keep their arity the same.  One example from Joe Armstrong&#8217;s book: </p>
<p><code><br />
area({rectangle, W, H}) -> W*H;<br />
area({circle, R})           -> 3.14 * R * R.<br />
</code></p>
<p>   By passing a tuple we are able to keep the arity  the same, but cheat on the type of behaviour the function is implementing
  </li>
</ul>
<h3>Lists</h3>
<ul>
<li>
     A group of things enclosed in square brackets, <strong>[foo, X, 23, &#8220;toad&#8221;]</strong> is a list
  </li>
<li>
     Lists are useful for storing variable length numbers of things.
  </li>
<li>
     The first element of a list is called the <em>head</em> and the remainder is called the <em>tail</em>  We can talk about these two elements using the general form <strong>[Head|Tail]</strong>.  This is a common operation, especially when using recursive implementations of algorithms.
  </li>
</ul>
<h3>Strings</h3>
<ul>
<li>
    Strings are enclosed in double quotation marks.  <strong>&#8220;My big ass&#8221;</strong> is a string.
  </li>
<li>
    Remember that things enclosed in single quotation marks are atoms - don&#8217;t confuse the two
  </li>
<li>
    Strings in erlang are really just lists of integers.
  </li>
<li>
    The shell will print a list of integers as a string if all the integers in the list represent printable characters under iso 8809 encoding
  </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.anodyne.ca/2008/09/20/erlang-notes-simple-data-types/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ciaweb home phone service</title>
		<link>http://www.anodyne.ca/2007/09/29/ciaweb-home-phone-service/</link>
		<comments>http://www.anodyne.ca/2007/09/29/ciaweb-home-phone-service/#comments</comments>
		<pubDate>Sun, 30 Sep 2007 03:51:37 +0000</pubDate>
		<dc:creator>grant.mcinnes</dc:creator>
		
		<category><![CDATA[snippits]]></category>

		<guid isPermaLink="false">http://www.anodyne.ca/2007/09/29/ciaweb-home-phone-service/</guid>
		<description><![CDATA[I recently switched over to cia.com for intartubes provision, and it&#8217;s been fine.  With the service give you a voip line for more or less free (it works out to about $7 /mos. or something).  So far that&#8217;s been nothing but a pile of shit - the Linksys ATA they send constantly loses [...]]]></description>
			<content:encoded><![CDATA[<p>I recently switched over to cia.com for intartubes provision, and it&#8217;s been fine.  With the service give you a voip line for more or less free (it works out to about $7 /mos. or something).  So far that&#8217;s been nothing but a pile of shit - the Linksys ATA they send constantly loses registration with their servers for some reason.</p>
<p>Given that their customer service is notoriously bad, I haven&#8217;t even tried phoning in to see what condition their condition is in.  But, if you reboot the cable modem, router and ATA in that order it re-registers, so I&#8217;m guessing the ATA only gets a window to register after their dhcp server has assigned a lease, and if the ATA drops the registration it&#8217;s not able to re-register until something asks for a new lease.  (Btw, I&#8221;m using a linksys WRT 54G with DD-WRT firmware on the router, and the ATA is behind the router, so that I can do QOS routing on the SIP packets).</p>
<p>Anyhow&#8230;.</p>
<p>I&#8217;m just writing this as a quick note to anyone else who might want to hack this setup.  The ATA can be reset following Cyberweb&#8217;s instructions by dialing 1111 then RESET then # then 1  into your phone.  This puts it in a factory default state where you can log into its admin web page and futz around - it&#8217;s at http://192.168.0.1 and the username is admin, password is also admin.</p>
<p>Then Cyberweb then instructs you to download a file from them through the modem to provision it.  Once you download this file, the admin interface of the modem becomes locked, so it&#8217;s no longer possible to edit its setup parameters.  Fortunately <a href='http://www.anodyne.ca/wp-content/uploads/2007/09/provision.xml' title='Cyberweb linksys ATA provisioning file'>the file they ask you to download</a> contains the admin password in clear text, so it&#8217;s trivial to get back in to the ATA.</p>
<p>Having said this though, I&#8217;ve no reason to believe that getting into it is useful.  Unless you know what parameters their sip server is using at the other end, I doubt that changing anything will get you a better service.  More than likely it&#8217;ll still suck.  But its nice to know it&#8217;s doable even for the hack value.  It&#8217;s also probably handy if you want to bring your own ATA or set up an asterisk box at home.</p>
<p>If anyone finds some params to frob that will make the whole thing more reliable though, let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anodyne.ca/2007/09/29/ciaweb-home-phone-service/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
