<?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>The Dark Energy Blog</title>
	<atom:link href="http://blog.spacesocket.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.spacesocket.com</link>
	<description>The Universe of Design, Development and Everything Else</description>
	<lastBuildDate>Sat, 05 Jan 2013 09:12:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Ada: Type Conversions</title>
		<link>http://blog.spacesocket.com/2012/09/22/ada-type-conversions/</link>
		<comments>http://blog.spacesocket.com/2012/09/22/ada-type-conversions/#comments</comments>
		<pubDate>Sun, 23 Sep 2012 04:02:17 +0000</pubDate>
		<dc:creator>North</dc:creator>
				<category><![CDATA[Ada]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[integer]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[type]]></category>

		<guid isPermaLink="false">http://blog.spacesocket.com/?p=516</guid>
		<description><![CDATA[This is part of a series on programming in the Ada language, a mission critical programming language that I am attempting to learn and become proficient in. Being a mission-critical language, Ada is very strongly typed. There are no implicit conversions as there are in other languages like C. So a statement that is perfectly [...]]]></description>
				<content:encoded><![CDATA[<p><em>This is part of a series on <a href="http://blog.spacesocket.com/2012/07/23/learning-ada/">programming in the Ada language</a>, a mission critical programming language that I am attempting to learn and become proficient in.</em></p>
<p>Being a mission-critical language, Ada is <em>very</em> strongly typed. There are no implicit conversions as there are in other languages like C. So a statement that is perfectly legal in C like <em>double num = 1;</em> is illegal in Ada because 1 is an integer &#8212; it must be specified as 1.0 because Ada doesn&#8217;t auto-convert. This gets a bit tedious at times when there are a lot of numbers, but it&#8217;s also quite useful in helping avoid (though doesn&#8217;t eliminate the possibility of) assigning a value to the wrong variable.</p>
<p><em>(Actually, there are implicit conversions in Ada &#8212; for example, 1 is not an Integer; it is a universal integer value that can be implicitly converted to an Integer &#8212; but that doesn&#8217;t even count as a conversion in most other languages so&#8230;)</em></p>
<p>There are a LOT of aspects of type conversions in Ada. I&#8217;ll just cover the few I think will be needed to do basic operations in the language without going into a ton of detail on the more complex operations that can be done.</p>
<p>To get started, the standard form of type conversion is the explicit conversion. To convert from one type to another, use:</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">New_Type<span style="color: #66cc66;">&#40;</span>Value_of_Old_Type<span style="color: #66cc66;">&#41;</span></div></div>
<p>This can be legally done between any two numeric values. For example, to convert an Integer value to Float:</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Float_Val : Float := Float<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">12</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>This is equivalent to:</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Float_Val : Float := <span style="color: #ff0000;">12.0</span>;</div></div>
<p>Of course, the latter version is more concise and is generally recommended when it&#8217;s possible. However, if the original value is a variable or constant, the explicit conversion in the former version is needed.</p>
<p>Note that when precision is lost (ie. converting from Float to Integer), the result is rounded.</p>
<p>Explicit conversions can also be done on any two types or subtypes derived from the same parent type. For example:</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">type</span> Hostname <span style="color: #00007f;">is</span> <span style="color: #46aa03; font-weight:bold;">new</span> String <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">1</span> .. <span style="color: #ff0000;">63</span><span style="color: #66cc66;">&#41;</span>;<br />
Host_Str : String := <span style="color: #7f007f;">&quot;google&quot;</span>;<br />
Host_Val : Hostname := Hostname <span style="color: #66cc66;">&#40;</span>Host_Str<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>And that&#8217;s about all the type conversions I&#8217;ll probably be using in the near future. Unchecked type conversions is also possible, but it&#8217;s unlikely I&#8217;ll use it anytime soon and it seems that there&#8217;s generally an alternative so I won&#8217;t attempt to understand/use it at this point.</p>
<p>Related to type conversions, and generally considered to be a type conversion in most other languages, is the conversion between string and numeric data. This is done through the use of the <em>Value</em> and <em>Image</em> attributes.</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Numeric_String &nbsp; : String := <span style="color: #7f007f;">&quot;121&quot;</span>;<br />
Integer_Value &nbsp; &nbsp;: Integer := Integer'Value <span style="color: #66cc66;">&#40;</span>Numeric_String<span style="color: #66cc66;">&#41;</span>;<br />
New_String_Value : String := Integer'Image <span style="color: #66cc66;">&#40;</span>Integer_Value<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Note that <em>Numeric_String /= New_String_Value</em>. When <em>Integer_Value</em> is converted to a string with <em>Integer&#8217;Image</em>, it adds a space in front of non-negative integers. As a result, <em>New_String_Value</em> is actually set to &#8221; 121&#8243;. This is used for formatting purposes when both negative and non-negative numbers are outputted into a list. This problem can easily be resolved through using the <em>Ada.Strings.Fixed.Trim</em> function on the result.</p>
<p>First, the library needs to withed and used by the package.</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">with</span> Ada.<span style="color: #202020;">Strings</span>.<span style="color: #202020;">Fixed</span>; <span style="color: #46aa03; font-weight:bold;">use</span> Ada.<span style="color: #202020;">Strings</span>.<span style="color: #202020;">Fixed</span>;</div></div>
<p>Then,</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Trimed_String : String := Trim <span style="color: #66cc66;">&#40;</span>New_String_Value, Ada.<span style="color: #202020;">Strings</span>.<span style="color: #202020;">Left</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>The <em>Ada.Strings.Left</em> parameter tells the function to remove the extra space on the left, if there is one. This leaves strings with negative values, which do not have an extra space on the left, unaffected.</p>
<p>If the number is guaranteed to be positive, then string slicing can be used which may be slightly faster.</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Sliced_String : String := New_String_Value <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">2</span> .. <span style="color: #202020;">New_String_Value</span>'Last<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>This, however, cuts off the negative sign in the case of negative values. In some cases, I can see this being done intentionally as a quick way to go from a number to a string containing the absolute value of that number.</p>
<p>There is a LOT more on type conversions I skipped right over &#8212; perhaps because I just plainly overlooked them; or those features may not be used frequently and I likely would not find a use for them with my relatively simple project; or maybe because they are advanced topics that I should probably save for later when I gain a bit more experience with using the language. Otherwise, I would risk trying to explain something I don&#8217;t actually understand which could lead to undue confusion (and I think I may have caused enough of that already).</p>
<p>So this marks the end of the sub-series on types, but only for now. Other useful topics (ie. access types and the like) will be covered as I start with the code for the project (which is a library of astronomical calculations for those who skipped over the overview post). The next post in the Ada series will cover the start of this project and its foundational code. Unfortunately, this happens to be a relatively busy time of year for me so that post may not arrive for quite some time &#8212; perhaps a couple of months. Then, the real fun begins.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spacesocket.com/2012/09/22/ada-type-conversions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ada: Records (Type System)</title>
		<link>http://blog.spacesocket.com/2012/08/01/ada-records/</link>
		<comments>http://blog.spacesocket.com/2012/08/01/ada-records/#comments</comments>
		<pubDate>Wed, 01 Aug 2012 19:22:02 +0000</pubDate>
		<dc:creator>North</dc:creator>
				<category><![CDATA[Ada]]></category>
		<category><![CDATA[case statement]]></category>
		<category><![CDATA[naming]]></category>
		<category><![CDATA[record]]></category>
		<category><![CDATA[type]]></category>
		<category><![CDATA[variant record]]></category>

		<guid isPermaLink="false">http://blog.spacesocket.com/?p=491</guid>
		<description><![CDATA[This is part of a series on programming in the Ada language, a mission critical programming language that I am attempting to learn and become proficient in. This is part 2 of the sub-series on types in Ada. A second variety of types in Ada (the first being the enumeration) is the record. When I [...]]]></description>
				<content:encoded><![CDATA[<p><em>This is part of a series on <a href="http://blog.spacesocket.com/2012/07/23/learning-ada/">programming in the Ada language</a>, a mission critical programming language that I am attempting to learn and become proficient in.</em></p>
<p>This is part 2 of the sub-series on types in Ada. A second variety of types in Ada (the first being the enumeration) is the record. When I first learned C a few years back, records (called structures in that language) were what I always associated with user-defined types. They are effectively sets of other types which can be grouped together and incorporated into a single variable (ie. coordinates).</p>
<p>A simple record type is written like this:</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">type</span> Coord <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">record</span><br />
&nbsp; &nbsp; &nbsp; Longitude : Float <span style="color: #46aa03; font-weight:bold;">range</span> -<span style="color: #ff0000;">180.0</span> .. <span style="color: #ff0000;">180.0</span>;<br />
&nbsp; &nbsp; &nbsp; Latitude &nbsp;: Float <span style="color: #46aa03; font-weight:bold;">range</span> -<span style="color: #ff0000;">90.0</span> .. <span style="color: #ff0000;">90.0</span>;<br />
&nbsp; &nbsp;<span style="color: #00007f;">end</span> <span style="color: #46aa03; font-weight:bold;">record</span>;</div></div>
<p>(Note the use of boundaries &#8212; Float is effectively an enumeration so it can be bounded)</p>
<p>Sometimes, it may also be helpful to have default values for each field.</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">type</span> Coord <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">record</span><br />
&nbsp; &nbsp; &nbsp; Longitude : Float <span style="color: #46aa03; font-weight:bold;">range</span> -<span style="color: #ff0000;">180.0</span> .. <span style="color: #ff0000;">180.0</span> := -<span style="color: #ff0000;">22.5</span>;<br />
&nbsp; &nbsp; &nbsp; Latitude &nbsp;: Float <span style="color: #46aa03; font-weight:bold;">range</span> -<span style="color: #ff0000;">90.0</span> .. <span style="color: #ff0000;">90.0</span> &nbsp; := <span style="color: #ff0000;">89.5</span>;<br />
&nbsp; &nbsp;<span style="color: #00007f;">end</span> <span style="color: #46aa03; font-weight:bold;">record</span>;</div></div>
<p>In Ada, records can be extended into other types with additional fields if they are declared as &#8220;tagged&#8221;. For example, if the longitude and latitude data isn&#8217;t enough and a new type that includes elevation is needed, it&#8217;s as simple as:</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">type</span> Coord <span style="color: #00007f;">is</span> <span style="color: #46aa03; font-weight:bold;">tagged</span> <span style="color: #adadad; font-style: italic;">-- Coord has been changed to a tagged type</span><br />
&nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">record</span><br />
&nbsp; &nbsp; &nbsp; Longitude : Float <span style="color: #46aa03; font-weight:bold;">range</span> -<span style="color: #ff0000;">180.0</span> .. <span style="color: #ff0000;">180.0</span>;<br />
&nbsp; &nbsp; &nbsp; Latitude &nbsp;: Float <span style="color: #46aa03; font-weight:bold;">range</span> -<span style="color: #ff0000;">90.0</span> .. <span style="color: #ff0000;">90.0</span>;<br />
&nbsp; &nbsp;<span style="color: #00007f;">end</span> <span style="color: #46aa03; font-weight:bold;">record</span>;<br />
<br />
<span style="color: #46aa03; font-weight:bold;">type</span> Position <span style="color: #00007f;">is</span> <span style="color: #46aa03; font-weight:bold;">new</span> Coord <span style="color: #46aa03; font-weight:bold;">with</span><br />
&nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">record</span><br />
&nbsp; &nbsp; &nbsp; Elevation : Float;<br />
&nbsp; &nbsp;<span style="color: #00007f;">end</span> <span style="color: #46aa03; font-weight:bold;">record</span>;</div></div>
<p>The above declaration of &#8220;Position&#8221; is equivalent to:</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">type</span> Position <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">record</span><br />
&nbsp; &nbsp; &nbsp; Longitude : Float <span style="color: #46aa03; font-weight:bold;">range</span> -<span style="color: #ff0000;">180.0</span> .. <span style="color: #ff0000;">180.0</span>;<br />
&nbsp; &nbsp; &nbsp; Latitude &nbsp;: Float <span style="color: #46aa03; font-weight:bold;">range</span> -<span style="color: #ff0000;">90.0</span> .. <span style="color: #ff0000;">90.0</span>;<br />
&nbsp; &nbsp; &nbsp; Elevation : Float;<br />
&nbsp; &nbsp;<span style="color: #00007f;">end</span> <span style="color: #46aa03; font-weight:bold;">record</span>;</div></div>
<p>There is no such thing as a &#8220;class&#8221; in Ada like there is in Java and C++. Instead, tagged records can be used to do the equivalent with its ability to be added on much as classes can be extended in Java and C++.</p>
<p>There are also discriminated records &#8212; records which work a lot like generics in other languages (as well as in Ada itself).</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">type</span> Disc_Coord <span style="color: #66cc66;">&#40;</span>Min_Lon, Max_Lon, Min_Lat, Max_Lat : Float<span style="color: #66cc66;">&#41;</span> <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">record</span><br />
&nbsp; &nbsp; &nbsp; Longitude : Float <span style="color: #46aa03; font-weight:bold;">range</span> Min_Lon .. <span style="color: #202020;">Max_Lon</span>;<br />
&nbsp; &nbsp; &nbsp; Latitude &nbsp;: Float <span style="color: #46aa03; font-weight:bold;">range</span> Min_Lat .. <span style="color: #202020;">Max_Lat</span>;<br />
&nbsp; &nbsp;<span style="color: #00007f;">end</span> <span style="color: #46aa03; font-weight:bold;">record</span>;</div></div>
<p>To use such records, the discriminants of the type must be specified when creating an object of the type.</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">My_Coord : Disc_Coord <span style="color: #66cc66;">&#40;</span>Min_Lon =&gt; -<span style="color: #ff0000;">180.0</span>, Max_Lon =&gt; <span style="color: #ff0000;">180.0</span>, Min_Lat =&gt; -<span style="color: #ff0000;">90.0</span>, Max_Lat =&gt; <span style="color: #ff0000;">90.0</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Note that I&#8217;ve named the discriminants (Min_Lon, Max_Lon, &#8230;). This isn&#8217;t necessary &#8212; it&#8217;s possible to do just:</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">My_Coord : Disc_Coord <span style="color: #66cc66;">&#40;</span>-<span style="color: #ff0000;">180.0</span>, <span style="color: #ff0000;">180.0</span>, -<span style="color: #ff0000;">90.0</span>, <span style="color: #ff0000;">90.0</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>However, that is a lot less readable to someone looking over the code. It&#8217;s also far more prone to errors &#8212; if you screw up the order and you&#8217;ve named the discriminants, you&#8217;re okay, but if you screw up the order and you don&#8217;t name the discriminants, you&#8217;re just plain screwed. Naming is also supported with procedure/function calls where you name the parameters.</p>
<blockquote><p><b>A Quick Note on Naming</b><br />
I have used parameters in the wrong order on more than one occasion with function calls in other languages that don&#8217;t support naming. Each occasion cost me a good hour&#8217;s worth of debugging and trying to figure out where my problem is. As a result, I find naming to be a very welcome feature.</p>
<p>Naming can and should also be when assigning values to objects that are record types: (note that this uses the none-discriminated records)</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">My_Coord_1 : Coord := <span style="color: #66cc66;">&#40;</span>Longitude =&gt; -<span style="color: #ff0000;">22.5</span>, Latitude =&gt; <span style="color: #ff0000;">89.5</span><span style="color: #66cc66;">&#41;</span>;<br />
My_Coord_2 : Coord := <span style="color: #66cc66;">&#40;</span>-<span style="color: #ff0000;">22.5</span>, <span style="color: #ff0000;">89.5</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #adadad; font-style: italic;">-- equivalent to above</span></div></div>
<p>Note how unreadable the latter version is. You would have to pull up the specification of Coord to see what each number means. Is -22.5 the longitude or the latitude? A look at the specification says longitude. However, a look at the first version immediately says which is which &#8212; without having to look up the specification.</p></blockquote>
<p>Getting back to discriminate types, it&#8217;s also possible to have one type be completely different types depending on the discriminate. Confused? The code should explain better than I can. These, by the way, are called variant records:</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">type</span> Disc_Type <span style="color: #66cc66;">&#40;</span>Version : Natural<span style="color: #66cc66;">&#41;</span> <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">record</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">case</span> Version <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">when</span> <span style="color: #ff0000;">1</span> =&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Field_1 : Float;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">when</span> <span style="color: #ff0000;">2</span>, <span style="color: #ff0000;">3</span> =&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Field_2 : Float;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">when</span> <span style="color: #46aa03; font-weight:bold;">others</span> =&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Field_1 : Float := <span style="color: #ff0000;">10</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">end</span> <span style="color: #00007f;">case</span>;<br />
&nbsp; &nbsp;<span style="color: #00007f;">end</span> <span style="color: #46aa03; font-weight:bold;">record</span>;</div></div>
<p>The case statement uses the same format as case statements in procedure and function bodies (and does the same thing). It checks the discriminant and sends it to the correct when statement depending on its value.</p>
<p>Unlike many other languages, the case statement (or switch/case) does not require a break statement at the bottom. The break statement (inside switch statements) is one of my most common errors I make with languages that require it. Even after working with perhaps hundreds of switch/case statements in C, I <em>still</em> frequently forget to add the break at the end. The result is that execution simply continues to the next option <em>without</em> giving me an error. It&#8217;s usually months later, long after the code has been released when the problem is discovered. My guess is that this is the reason why switch statements are considered &#8220;evil&#8221; in such languages.</p>
<p>So far, of these, I plan to make use of standard, tagged and variant records in my astronomical calculations library. I don&#8217;t see anything that plain discriminated records could be used for&#8230; yet.</p>
<p>Coming next should be type conversions. Ada seems to be particular strict on these as it&#8217;s part of what makes it mission-critical.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spacesocket.com/2012/08/01/ada-records/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Ada: Enumeration Types</title>
		<link>http://blog.spacesocket.com/2012/07/31/ada-enumeration-types/</link>
		<comments>http://blog.spacesocket.com/2012/07/31/ada-enumeration-types/#comments</comments>
		<pubDate>Tue, 31 Jul 2012 22:35:49 +0000</pubDate>
		<dc:creator>North</dc:creator>
				<category><![CDATA[Ada]]></category>
		<category><![CDATA[enum]]></category>
		<category><![CDATA[enumeration]]></category>
		<category><![CDATA[type]]></category>

		<guid isPermaLink="false">http://blog.spacesocket.com/?p=484</guid>
		<description><![CDATA[This is part of a series on programming in the Ada language, a mission critical programming language that I am attempting to learn and become proficient in. When I first looked at the Ada language, one thing I found to be very attractive was the type system &#8212; unlike some other languages, it just &#8220;made [...]]]></description>
				<content:encoded><![CDATA[<p><em>This is part of a series on <a href="http://blog.spacesocket.com/2012/07/23/learning-ada/">programming in the Ada language</a>, a mission critical programming language that I am attempting to learn and become proficient in.</em></p>
<p>When I first looked at the Ada language, one thing I found to be very attractive was the type system &#8212; unlike some other languages, it just &#8220;made sense&#8221; to me.</p>
<p>There are actually a lot of different kinds of types in Ada. The generic one that first caught my attention is the enumeration. Enums exist in C/C++ as well (and perhaps many other language), but an enum declaration in C hardly tells you what it means. In C, an enum would be declared like this:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">enum</span> Day_of_Week <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Sunday<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; Monday<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; Tuesday<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; Wednesday<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; Thursday<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; Friday<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; Saturday<br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<p>I have never understood enums in C particularly well despite several years of experience in the language. As a result, the most I have done with them is to use them as an equivalent of a series of constants like:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define Sunday 0</span><br />
<span style="color: #339933;">#define Monday 1</span><br />
<span style="color: #808080; font-style: italic;">/* ... */</span><br />
<span style="color: #339933;">#define Saturday 6</span></div></div>
<p>I&#8217;m sure that C is more powerful than that, but the more advanced features, based on a quick Google search, require memorizing a lot of extra syntax. One reason I chose C back in 2009 is its simple syntax &#8212; at least for the simple tasks I needed to do. C++ had ugly &lt;brackets&gt; and Fortran was&#8230;well, to say the least, unreadable. This was, naturally, several years before I even heard of Ada so it was not an option &#8212; which meant C was the most understandable language of its type I knew of. And that is how I became a C programmer. Then in came the features like enums and&#8230;</p>
<p>Well, enough of that &#8212; it&#8217;s time to return to the language that solves all (or at least a few) problems. Enumerations in Ada are <em>MUCH</em> more understandable. Compare the above to:</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">type</span> Day_of_Week <span style="color: #00007f;">is</span> <span style="color: #66cc66;">&#40;</span><br />
&nbsp; &nbsp;Sunday,<br />
&nbsp; &nbsp;Monday,<br />
&nbsp; &nbsp;Tuesday,<br />
&nbsp; &nbsp;Wednesday,<br />
&nbsp; &nbsp;Thursday,<br />
&nbsp; &nbsp;Friday,<br />
&nbsp; &nbsp;Saturday<br />
<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Now <em>THAT</em> just makes sense, regardless of whether you know any Ada or not! Sunday, Monday, &#8230;, Saturday are all of the type &#8220;Day_of_Week&#8221; &#8212; no confusing &#8220;enum&#8221; keyword or resemblance to a function call. With this, a procedure or function can accept an argument of type &#8220;Day_of_Week&#8221; and be passed a Sunday, &#8230;, Saturday.</p>
<p>Perhaps more interesting is the ability to have subtypes which include just a portion of the main enumerated type. For example,</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">subtype</span> Workday <span style="color: #00007f;">is</span> Day_of_Week <span style="color: #46aa03; font-weight:bold;">range</span> Monday .. <span style="color: #202020;">Saturday</span>;</div></div>
<p>Now there&#8217;s something that should be very useful &#8212; especially with catching errors. I am a big fan of organization in code &#8212; mainly because if the code isn&#8217;t organized in a standardized and strict manner, I quickly lose track of which code does what. And when that happens, it&#8217;s quite easy to screw up. Organizing it this way also lets the compiler double check your work to make sure you organized correctly &#8212; because if you organized wrong, you probably made a mistake somewhere that wouldn&#8217;t be caught in a language like C.</p>
<p>I was originally planning on writing about the entire type system in this post. Those of you who are Ada programmers probably laughed just now at that statement. A quick look at the features of the type system show that one can probably write a whole book on it and this post would have ended up being upwards of 20 pages long. So, to keep things short and understandable, I&#8217;ll break it up into 20 posts instead.</p>
<p>So, next up in this sub-series on Ada types are records &#8212; the equivalent of structures in C.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spacesocket.com/2012/07/31/ada-enumeration-types/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ada: Child Packages</title>
		<link>http://blog.spacesocket.com/2012/07/31/ada-child-packages/</link>
		<comments>http://blog.spacesocket.com/2012/07/31/ada-child-packages/#comments</comments>
		<pubDate>Tue, 31 Jul 2012 21:33:31 +0000</pubDate>
		<dc:creator>North</dc:creator>
				<category><![CDATA[Ada]]></category>
		<category><![CDATA[child packages]]></category>
		<category><![CDATA[package]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.spacesocket.com/?p=476</guid>
		<description><![CDATA[This is part of a series on programming in the Ada language, a mission critical programming language that I am attempting to learn and become proficient in. It&#8217;s been another couple of days. To be honest, I haven&#8217;t done much with Ada in these recent days but here are some more findings as a result [...]]]></description>
				<content:encoded><![CDATA[<p><em>This is part of a series on <a href="http://blog.spacesocket.com/2012/07/23/learning-ada/">programming in the Ada language</a>, a mission critical programming language that I am attempting to learn and become proficient in.</em></p>
<p>It&#8217;s been another couple of days. To be honest, I haven&#8217;t done much with Ada in these recent days but here are some more findings as a result of my experimentation and research.</p>
<p>Last time, we had packages. Now, it&#8217;s time to deal with some child packages which are exactly what they sound like &#8212; a sub-package of a parent package. All of the standard packages are child packages of the &#8220;Ada&#8221; package. GNAT also provides some child packages under the &#8220;GNAT&#8221; package.</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">package</span> Parent <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">-- enter some stuff here...</span><br />
<span style="color: #00007f;">end</span> Parent;<br />
<br />
<span style="color: #46aa03; font-weight:bold;">package</span> Parent.<span style="color: #202020;">Child</span> <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">-- enter some more stuff here...</span><br />
<span style="color: #00007f;">end</span> Parent.<span style="color: #202020;">Child</span>;</div></div>
<p>Besides the obvious benefit of organization, child packages also provide some inheritance benefits. For example, every child package automatically has access to everything in the parent package. Normally, that requires a &#8220;with&#8221; statement at the top. Therefore, the following is redundant:</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">with</span> Parent;<br />
<span style="color: #46aa03; font-weight:bold;">package</span> Parent.<span style="color: #202020;">Child</span> <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">-- some code that uses functions in &quot;Parent&quot;</span><br />
<span style="color: #00007f;">end</span> Parent.<span style="color: #202020;">Child</span>;</div></div>
<p>An even bigger benefit is the ability for child packages to access the private declarations of the parent package. For example, if a parent is declared as:</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">package</span> Parent <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">-- public declarations</span><br />
&nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">procedure</span> Public_Foo;<br />
<span style="color: #46aa03; font-weight:bold;">private</span><br />
&nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">-- private declarations</span><br />
&nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">procedure</span> Private_Foo;<br />
<span style="color: #00007f;">end</span> Parent;</div></div>
<p>then any other package can call Public_Foo (after using a with statement as shown above). However, only the package itself and all child packages can use Private_Foo.</p>
<p>Sometimes, it&#8217;s useful to have private child packages.</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">private</span> <span style="color: #46aa03; font-weight:bold;">package</span> Parent.<span style="color: #202020;">Private_Child</span> <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #adadad; font-style: italic;">-- declarations</span><br />
<span style="color: #00007f;">end</span> Parent.<span style="color: #202020;">Private_Child</span>;</div></div>
<p>The declarations in such private packages are only accessible to other private units such in the bodies of sibling packages (ie. other child packages of the same parent).</p>
<p>Next time, it&#8217;s time to take a look at Ada&#8217;s highly sophisticated type system &#8212; effectively, the system that makes the language what it is.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spacesocket.com/2012/07/31/ada-child-packages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First findings of Lua</title>
		<link>http://blog.spacesocket.com/2012/07/31/first-findings-of-lua/</link>
		<comments>http://blog.spacesocket.com/2012/07/31/first-findings-of-lua/#comments</comments>
		<pubDate>Tue, 31 Jul 2012 21:20:59 +0000</pubDate>
		<dc:creator>proms74</dc:creator>
				<category><![CDATA[Lua]]></category>
		<category><![CDATA[reading]]></category>

		<guid isPermaLink="false">http://blog.spacesocket.com/?p=474</guid>
		<description><![CDATA[Now that I have everything installed, I can now begin playing with the tricks of Lua. Our ultimate goal is to learn how to assemble a program together. Assembling a program is very difficult for beginners, so practice is necessary. This is just like learning physics. Physics is a difficult subject for beginners, but with [...]]]></description>
				<content:encoded><![CDATA[<p>Now that I have everything installed, I can now begin playing with the tricks of Lua.</p>
<p>Our ultimate goal is to learn how to assemble a program together. Assembling a program is very difficult for beginners, so practice is necessary. This is just like learning physics. Physics is a difficult subject for beginners, but with practice, it becomes easier over time.</p>
<p>On the command line, I notice a MS-DOS like screen where I begin to write code on the command line.</p>
<p>So where do I start? Click <a href="http://www.lua.org/pil/2.html">here</a>.</p>
<p>For example, I type in: print (&#8220;Hello world&#8221;), and I get Hello world as the output value. Another example is to type: print (6868^2), and I get 47169424 as the output value. This is just another branch of mathematics, applied to the real world.</p>
<p>But this is just the first step. Some vocabulary terms must be mentioned here, to get oriented with the Lua. That is what you do when you learn a new language.</p>
<p>However, in order to thoroughly learn Lua, the first step is to visit the <a href="http://www.lua.org/pil/2.html">Lua online handbook </a>to find out the terminology. That is where I will begin my studies using the Lua language.</p>
<p>As I am learning Lua, I will also be coming across different resources.</p>
<p>At this time, I have just come across a video demonstration on Youtube, explaining how to program in Lua. <a href="http://www.youtube.com/watch?v=JKfKCL3UB4s">Here</a> you can learn how to use the Lua program to successfully create your first program. I will be using this resource often in order to learn how to make programs using the Lua language. It is easier rather than reading the online handbook because it actually demonstrates how to compile a program. I think it is very useful for programmers who have virtually no programming experience (like me).</p>
<p>But, let&#8217;s get back to the &#8220;Hello world&#8221; example.</p>
<div class="codecolorer-container lua default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="lua codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>code<span style="color: #66cc66;">&gt;</span>&amp;gt<span style="color: #66cc66;">;</span><span style="color: #0000aa;">print</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff6666;">&quot;Hello world&quot;</span><span style="color: #66cc66;">&#41;</span><br />
Hello world<br />
&amp;gt<span style="color: #66cc66;">;</span><span style="color: #0000aa;">io.write</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff6666;">&quot;Hello world&quot;</span><span style="color: #66cc66;">&#41;</span><br />
Hello world&amp;gt<span style="color: #66cc66;">;</span><br />
&amp;gt<span style="color: #66cc66;">;</span><span style="color: #0000aa;">print</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff6666;">&quot;Hello world<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span><br />
Hello world<br />
&amp;gt<span style="color: #66cc66;">;</span><span style="color: #0000aa;">print</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff6666;">&quot;My name is Fred...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span><br />
My name is Fred<span style="color: #66cc66;">...&lt;/</span>code<span style="color: #66cc66;">&gt;</span><br />
<br />
&amp;gt<span style="color: #66cc66;">;</span><span style="color: #0000aa;">io.write</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff6666;">&quot;I have a cat called Borris&quot;</span><span style="color: #66cc66;">&#41;</span><br />
I have a cat called Borris&amp;gt<span style="color: #66cc66;">;</span><br />
&amp;gt<span style="color: #66cc66;">;</span><span style="color: #0000aa;">io.write</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff6666;">&quot;I have a cat called Borris<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span><br />
I have a cat called Borris</div></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spacesocket.com/2012/07/31/first-findings-of-lua/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Beginning of a Lua Program</title>
		<link>http://blog.spacesocket.com/2012/07/29/the-beginning-of-a-lua-program/</link>
		<comments>http://blog.spacesocket.com/2012/07/29/the-beginning-of-a-lua-program/#comments</comments>
		<pubDate>Mon, 30 Jul 2012 03:00:40 +0000</pubDate>
		<dc:creator>proms74</dc:creator>
				<category><![CDATA[Lua]]></category>
		<category><![CDATA[Google Code]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[ZERO]]></category>

		<guid isPermaLink="false">http://blog.spacesocket.com/?p=470</guid>
		<description><![CDATA[After a few days hiatus, it is now time to begin the installation process. Installation &#8211; The Overall Process Disclaimer: If you are operating your Lua software on a non-Windows operating system, please visit the Lua website for further information on how to install your Lua software. Also, use Youtube as a resource to guide [...]]]></description>
				<content:encoded><![CDATA[<p>After a few days hiatus, it is now time to begin the installation process.</p>
<p><strong>Installation &#8211; The Overall Process</strong></p>
<p><strong></strong>Disclaimer: If you are operating your Lua software on a non-Windows operating system, please visit the Lua website for further information on how to install your Lua software. Also, use Youtube as a resource to guide you in the installation process.</p>
<p>This post applies to all Windows operating systems (particularly Windows XP and 7, as these operating systems are popularly used).</p>
<p>First, search &#8220;Lua for Windows&#8221; on Google, and then you will see a link to the Lua for Windows page. Then, you will be asked to download your Lua for Windows software from Google Code, which can be accessed <a href="http://code.google.com/p/luaforwindows/downloads/detail?name=LuaForWindows_v5.1.4-46.exe&amp;can=2&amp;q=">here</a>.</p>
<p>When downloading, you will want to save the file under the Downloads folder (if using Windows 7). For XP users, please find a folder that you feel comfortable using to save your files.</p>
<div id="attachment_505" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.spacesocket.com/wp-content/uploads/2012/07/Luainstall12.png"><img class="size-medium wp-image-505" src="http://blog.spacesocket.com/wp-content/uploads/2012/07/Luainstall12-300x225.png" alt="" width="300" height="225" /></a><p class="wp-caption-text">Downloading your Lua for Windows.</p></div>
<p>When prompted to download, click on Save. Here is what will happen&#8230;</p>
<p><a href="http://blog.spacesocket.com/wp-content/uploads/2012/07/luainstall2.png"><img class="alignnone size-medium wp-image-506" src="http://blog.spacesocket.com/wp-content/uploads/2012/07/luainstall2-300x225.png" alt="Downloading Lua." width="300" height="225" /></a></p>
<p>Sometimes, anti-virus providers will cause the program to &#8221;not be verified&#8221;. In that case, you just click &#8220;Run&#8221;.</p>
<div id="attachment_507" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.spacesocket.com/wp-content/uploads/2012/07/Luainstall3.png"><img class="size-medium wp-image-507" src="http://blog.spacesocket.com/wp-content/uploads/2012/07/Luainstall3-300x225.png" alt="" width="300" height="225" /></a><p class="wp-caption-text">Installing Lua</p></div>
<p>Installation now begins. You click &#8220;Next.&#8221;</p>
<p>Then&#8230;</p>
<div id="attachment_508" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.spacesocket.com/wp-content/uploads/2012/07/luainstall4.png"><img class="size-medium wp-image-508" src="http://blog.spacesocket.com/wp-content/uploads/2012/07/luainstall4-300x225.png" alt="" width="300" height="225" /></a><p class="wp-caption-text">Installing Lua 2</p></div>
<p>You now choose where to save your installed files. In this case, I use my Downloads folder (Windows 7). Then click &#8220;Next&#8221;.</p>
<p><a href="http://blog.spacesocket.com/wp-content/uploads/2012/07/luainstall5.png"><img class="alignnone size-medium wp-image-509" src="http://blog.spacesocket.com/wp-content/uploads/2012/07/luainstall5-300x225.png" alt="" width="300" height="225" /></a></p>
<p>Now you choose what to install. I recommend full installation. When you are finished, click &#8220;Next&#8221; for further instructions.</p>
<p>Make sure to follow all the prompts to install your Lua for Windows software.</p>
<p>After installing, you should see an &#8220;Installation Complete&#8221; page like the screenshot below.<a href="http://blog.spacesocket.com/wp-content/uploads/2012/07/luainstall6.png"><img class="alignnone size-medium wp-image-510" src="http://blog.spacesocket.com/wp-content/uploads/2012/07/luainstall6-300x225.png" alt="" width="300" height="225" /></a><br />
You check the box next to &#8220;Run a simple introduction to Lua&#8221; if you need to learn how to use it. Otherwise, click &#8220;Finish&#8221; and begin enjoying your time learning Lua!</p>
<p>Learning Lua is tricky at first, but once you master the basics of Lua, everything else is simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spacesocket.com/2012/07/29/the-beginning-of-a-lua-program/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basics of Ada</title>
		<link>http://blog.spacesocket.com/2012/07/26/basics-of-ada/</link>
		<comments>http://blog.spacesocket.com/2012/07/26/basics-of-ada/#comments</comments>
		<pubDate>Thu, 26 Jul 2012 18:06:12 +0000</pubDate>
		<dc:creator>North</dc:creator>
				<category><![CDATA[Ada]]></category>

		<guid isPermaLink="false">http://blog.spacesocket.com/?p=460</guid>
		<description><![CDATA[This is part of a series on programming in the Ada language, a mission critical programming language that I am attempting to learn and become proficient in. Well, it&#8217;s been a few days and it&#8217;s now time to report back with some findings. Note that this isn&#8217;t the first time I&#8217;ve seen Ada code so [...]]]></description>
				<content:encoded><![CDATA[<p><em>This is part of a series on <a href="http://blog.spacesocket.com/2012/07/23/learning-ada/">programming in the Ada language</a>, a mission critical programming language that I am attempting to learn and become proficient in.</em></p>
<p>Well, it&#8217;s been a few days and it&#8217;s now time to report back with some findings. Note that this isn&#8217;t the first time I&#8217;ve seen Ada code so I may appear to be going a bit faster than someone completely new to the language would.</p>
<p><strong>Comments</strong></p>
<p>There is only one type of comment in Ada &#8212; those prefixed by &#8220;&#8211;&#8221;.</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #adadad; font-style: italic;">-- This is a comment</span></div></div>
<p><strong>Semicolons</strong></p>
<p>Yes, there are semi-colons after just about every complete statement. That&#8217;s quite standard among all the major compiled languages. The fact that it shows up in a language known for helping programmers avoid mistakes and improving readability &#8212; which semi-colons do help with, as annoying as they are to type.</p>
<p><strong>Assignment vs Equality Check</strong></p>
<p>Many newcomers to programming get confused by the statement &#8220;i = i + 1&#8243; which is a common way to increment a variable in some languages. That&#8217;s because we have long learned that &#8220;=&#8221; means the two sides are the same when obviously i cannot equal i + 1. That&#8217;s because the &#8220;=&#8221; in that statement means assignment and changes the value of i to i + 1 rather than specifies that they are equal. That leads to the next big mistake many newcomers make: using the &#8220;=&#8221; instead of &#8220;==&#8221;. Nowhere in math is &#8220;==&#8221; ever used despite its appearance as a mathematical operator. It means, in many languages, the equivalent of what &#8220;=&#8221; means in math and the rest of the world.</p>
<p>Ada resolves this issue with a simple change: by making the assignment operator &#8220;:=&#8221; rather than just &#8220;=&#8221; which it uses in place of &#8220;==&#8221;. Yes, it&#8217;s one extra character to type, but at least it now makes sense to the rest of the world.</p>
<p>I should also point out that the errors generated when you forget that assignment is &#8220;:=&#8221; and equality is &#8220;=&#8221; are very helpful and concise in located what you did wrong. Unlike the error system in most C compilers which would say something like &#8220;Expected &#8216;:=&#8217; near &#8216;=&#8217;&#8221;, or, even worse, &#8220;Unexpected character near &#8216;=&#8217;&#8221;, the Ada compiler actually says &#8220;&#8216;=&#8217; should be &#8216;:=&#8217;&#8221;.</p>
<p><strong>Functions &amp; Procedures</strong></p>
<p>Ada is one of those languages that distinguish between functions and procedures. A function returns a value and cannot modify any arguments passed to it. A procedure does not return a value but can modify arguments.</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">procedure</span> Modify_Args <span style="color: #66cc66;">&#40;</span>Arg1 : <span style="color: #46aa03; font-weight:bold;">in</span> <span style="color: #46aa03; font-weight:bold;">out</span> Integer<span style="color: #66cc66;">&#41;</span> <span style="color: #00007f;">is</span><br />
<span style="color: #00007f;">begin</span><br />
&nbsp; &nbsp;Arg1 := <span style="color: #ff0000;">12</span>; <span style="color: #adadad; font-style: italic;">-- changes the value passed to 12</span><br />
<span style="color: #00007f;">end</span> Modify_Args;<br />
<br />
<span style="color: #46aa03; font-weight:bold;">function</span> Set_Var <span style="color: #00007f;">return</span> Integer <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;Var : Integer := <span style="color: #ff0000;">10</span>; <span style="color: #adadad; font-style: italic;">-- sets var to 10</span><br />
<span style="color: #00007f;">begin</span><br />
&nbsp; &nbsp;Modify_Args<span style="color: #66cc66;">&#40;</span>Var<span style="color: #66cc66;">&#41;</span>; <span style="color: #adadad; font-style: italic;">-- passes it to the procedure which changes it to 12</span><br />
&nbsp; &nbsp;<span style="color: #00007f;">return</span> Var;<br />
<span style="color: #00007f;">end</span> Set_Var;</div></div>
<p><strong>Packages</strong></p>
<p>All Ada programs are written as packages. Packages are like classes in object-oriented languages where everything inside is static &#8212; so no initializing objects from them.</p>
<p>Packages are typically broken into a spec file and a body file. These resemble the header and code files in C/C++ with one distinct difference &#8212; they absolutely must match up. A package body cannot have any public functions or procedures that do not appear in the package spec. This makes sense &#8212; a public function/procedure is expected to be used by functions/procedures in other packages which requires inclusion in the spec file.</p>
<p>Package spec:</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">package</span> Example <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">function</span> foo <span style="color: #00007f;">return</span> Float; <span style="color: #adadad; font-style: italic;">-- must be implemented in package body or error will result</span><br />
<span style="color: #00007f;">end</span> Example;</div></div>
<p>Package body</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">package</span> <span style="color: #46aa03; font-weight:bold;">body</span> Example <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">function</span> foo <span style="color: #00007f;">return</span> Float <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #00007f;">begin</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">return</span> <span style="color: #ff0000;">10.0</span>;<br />
&nbsp; &nbsp;<span style="color: #00007f;">end</span> foo;<br />
<span style="color: #00007f;">end</span> Example;</div></div>
<p>Even the entry point (&#8220;main&#8221; program) is included in a package. The entry point has the same name as the package it is included in. Naturally, not every package NEEDS an entry point just as there aren&#8217;t multiple &#8220;main&#8221; functions in C.</p>
<p>The package containing main is specified in the build file. The following program does&#8230;well, nothing.</p>
<div class="codecolorer-container ada default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ada codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #46aa03; font-weight:bold;">package</span> Test <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #46aa03; font-weight:bold;">procedure</span> Test <span style="color: #00007f;">is</span><br />
&nbsp; &nbsp;<span style="color: #00007f;">begin</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #46aa03; font-weight:bold;">null</span>;<br />
&nbsp; &nbsp;<span style="color: #00007f;">end</span> Test;<br />
<span style="color: #00007f;">end</span> Test;</div></div>
<p>&#8211;</p>
<p>Well, that&#8217;s it for now. I&#8217;ll be back to update with some more interesting features of Ada.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spacesocket.com/2012/07/26/basics-of-ada/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lua: Why learn programming language?</title>
		<link>http://blog.spacesocket.com/2012/07/25/lua-why-learn-programming-language/</link>
		<comments>http://blog.spacesocket.com/2012/07/25/lua-why-learn-programming-language/#comments</comments>
		<pubDate>Thu, 26 Jul 2012 05:27:52 +0000</pubDate>
		<dc:creator>proms74</dc:creator>
				<category><![CDATA[Lua]]></category>
		<category><![CDATA[future]]></category>
		<category><![CDATA[US]]></category>

		<guid isPermaLink="false">http://blog.spacesocket.com/?p=456</guid>
		<description><![CDATA[Technology has been advancing rapidly, especially in the computer industry. From Steve Jobs&#8217; first release of the Apple computer in 1984, along with release of Windows 1.0 from Microsoft in 1985, the technology has rapidly advanced in the last 28 years. There is an eventual possibility that computers will be a thing of the past, [...]]]></description>
				<content:encoded><![CDATA[<p>Technology has been advancing rapidly, especially in the computer industry. From Steve Jobs&#8217; first release of the Apple computer in 1984, along with release of Windows 1.0 from Microsoft in 1985, the technology has rapidly advanced in the last 28 years. There is an eventual possibility that computers will be a thing of the past, and that tablet PCs will take over traditional desktop computers in the future.</p>
<p>But with the rapid advancement of technology comes huge challenges. One challenge that our younger generation will have to face is learning a programming language. As North mentions, &#8220;some colleges require students to take computer literacy classes in order to graduate.&#8221; But why is that? Is that designed to distract students from their focus of study?</p>
<p>Not at all. In fact, just like a good working knowledge of economics and accounting is crucial to successful survival in a capitalist society, a good working knowledge of computer programming is just as crucial as having a good working knowledge of economics and accounting, since our future life will revolve around computers. Computers in the future will be ubiquitous, so having a sufficient command of programming language is equally advantageous to understanding economics and accounting, for survival purposes.</p>
<p>So, what is Lua? Lua is a <a href="http://www.lua.org/about.html">powerful, fast, embeddable, and lightweight scripting language</a>. It combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.</p>
<p>Lua has advantages. It is a proven, robust language, and it is fast, portable, embeddable, powerful (but simple), small and of course, FREE!</p>
<p>It is used in many industrial applications, with emphasis on embedded systems and games. It is currently a leading scripting language in games. It has a deserved reputation for its fast performance, and it is distributed in a small package. In addition, it is compatible with all operating systems.</p>
<p>For more information about Lua&#8217;s syntax, please click <a href="http://www.lua.org/manual/5.1/manual.html/">here</a>.</p>
<p>More information can be found on the Internet.</p>
<p>In the past years of my life, I have zero programming experience. My websites are pre-made, using Drupal CMS. But, that will all change when I begin learning Lua, an important programming language. The Internet is a great resource for Lua, and it also will provide great resources for me as I learn the language. And of course, whenever you have something you don&#8217;t understand, try to help yourself, and then ASK! This is the key to learning anything, from being able to pass a test, to of course, learning a language like Lua.</p>
<p>HAVE FUN! And of course, come back here for links to more posts.</p>
<p><a href="http://blog.spacesocket.com/2012/07/29/the-beginning-of-a-lua-program/">The Beginning of a Lua Program</a></p>
<p><a href="http://blog.spacesocket.com/2012/07/31/first-findings-of-lua">First Findings of Lua</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spacesocket.com/2012/07/25/lua-why-learn-programming-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Space Socket Challenge: Learn Programming</title>
		<link>http://blog.spacesocket.com/2012/07/23/space-socket-challenge-learn-programming/</link>
		<comments>http://blog.spacesocket.com/2012/07/23/space-socket-challenge-learn-programming/#comments</comments>
		<pubDate>Tue, 24 Jul 2012 00:26:44 +0000</pubDate>
		<dc:creator>North</dc:creator>
				<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[future]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[Space Socket Dev]]></category>

		<guid isPermaLink="false">http://blog.spacesocket.com/?p=451</guid>
		<description><![CDATA[Many of you reading have probably never even touched a line of code let alone write a program. With so much software available these, it&#8217;s getting increasingly convenient to just go download a copy of WordPress to setup a blog or to look online for a calculator to solve your integral problems. Yet, with computers [...]]]></description>
				<content:encoded><![CDATA[<p>Many of you reading have probably never even touched a line of code let alone write a program. With so much software available these, it&#8217;s getting increasingly convenient to just go download a copy of WordPress to setup a blog or to look online for a calculator to solve your integral problems.</p>
<p>Yet, with computers dominating much of the future, it may become a necessity in the future to be able to write good, working code much as it&#8217;s a necessity today to be able to speak a language. Despite the vast number of software available already, it hardly covers everything. It&#8217;s not because these tasks are hard, but rather, because there are endless possibilities that it&#8217;s impossible to implement them all.  Many of the tasks existing software can&#8217;t do yet can be accomplished with just a couple lines of code any novice programmer can write.</p>
<p>Just as those with the ability to understand texting linguo (ie. lol, rofl, lmao, etc..) have left the older generations behind, there&#8217;s a real possibility that those who write code and think programmatically will leave those of the present behind. Many universities in the US are already requiring students of all majors to take an introductory computer science course to graduate.</p>
<p>So here&#8217;s the challenge for you: If haven&#8217;t already, learn to write code. There are countless practical applications for writing code from extending your website in a way no one else has to solving a repetitive and boring problem your professor or boss assigned. You&#8217;ll save yourself a lot of work and might even get yourself a promotion!</p>
<p>Space Socket Dev blogger proms74 will be tackling this challenge head-on by learning to script in <a href="http://www.lua.org">Lua</a> over the next month or so. Like many of you, he has had no prior experience working with any programming language. Along the way, he will be offering helpful hints and advice to save you some time when trying it for yourself.</p>
<p>Meanwhile, many others will already have significant programming experience whether it&#8217;s Fortran, C or PHP. To those readers, your challenge is this: learn a new programming language. While it&#8217;s true that one should always aim to be good at one language than decent in many, picking up new languages is a good way to think differently when you write code. Often, coding styles and methods in one language are equally applicable in another yet they never surface in that second language simply because of the way it was designed. For example, Python is a language that strictly conforms to a standard of coding with certain &#8220;rules&#8221; that come naturally with its design. But such &#8220;rules&#8221; may be equally applicable in, say, Lua. I am <a href="http://blog.spacesocket.com/2012/07/23/learning-ada/">taking up this second challenge by learning Ada</a>, a mission-critical language frequently used in airplanes, rockets and spacecraft.</p>
<p>Time for me to get started (or rather, continue where I left off)! Are you up to the challenge? If so, ready, get set, GO!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spacesocket.com/2012/07/23/space-socket-challenge-learn-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Ada: Installing GNAT</title>
		<link>http://blog.spacesocket.com/2012/07/23/installing-gnat/</link>
		<comments>http://blog.spacesocket.com/2012/07/23/installing-gnat/#comments</comments>
		<pubDate>Mon, 23 Jul 2012 23:21:24 +0000</pubDate>
		<dc:creator>North</dc:creator>
				<category><![CDATA[Ada]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[GNAT]]></category>

		<guid isPermaLink="false">http://blog.spacesocket.com/?p=443</guid>
		<description><![CDATA[This is part of a series on programming in the Ada language, a mission critical programming language that I am attempting to learn and become proficient in. The standard compiler for the Ada language today is the GNAT compiler which is part of GCC. There are actually 3 different versions of GNAT: GNAT-GPL, GNAT Pro [...]]]></description>
				<content:encoded><![CDATA[<p><em>This is part of a series on <a href="http://blog.spacesocket.com/2012/07/23/learning-ada/">programming in the Ada language</a>, a mission critical programming language that I am attempting to learn and become proficient in.</em></p>
<p>The standard compiler for the Ada language today is the <a href="http://www.gnu.org/software/gnat/">GNAT compiler</a> which is part of GCC. There are actually 3 different versions of GNAT: GNAT-GPL, GNAT Pro and GNAT-GCC. GNAT-GPL and GNAT-Pro are released by <a href="http://www.adacore.com" target="_blank">AdaCore</a>, the company that develops Ada-related products. GNAT-GCC includes a runtime library licensed under the GPL requiring all binaries compiled by it to be released under the GPL. GNAT Pro and GNAT-GCC (included in the GCC distribution) includes a runtime under the GMGPL (GNAT Modified GPL), a license equivalent to the LGPL.</p>
<p>I decided to start off with <a href="http://libre.adacore.com/tools/gnat-gpl-edition/" target="_blank">GNAT-GPL</a>, which includes an IDE (GNAT Programming Studio) then later switch the compiler to GNAT-GCC as needed. So I downloaded a copy of GNAT-GPL 2012 for x86 Windows from the <a href="http://libre.adacore.com" target="_blank">Libre website of AdaCore</a> and installed it. Note that although it shows a field for email before you download, you do <em>not</em> need to fill it in for the downloads to show.</p>
<p>At 108 MB, it was a pretty big download and took several minutes to download. The per-user installation went smoothly as I had expected and within a few more minutes, GNAT was successfully installed. Or so I had thought. The first logical step was to load up GNAT Programming Studio and take a look around the environment. The splash screen loaded and, for a few seconds, the program appeared to be loading, but when the splash screen closed, the program did not load. A peek at task manager shows that the gps.exe process quits after the splash screen exits so something must not have been right with the installation or my machine.</p>
<div id="attachment_445" class="wp-caption alignleft" style="width: 310px"><a href="http://blog.spacesocket.com/2012/07/23/installing-gnat/gps1/" rel="attachment wp-att-445"><img class="size-medium wp-image-445" title="GPS Splash Screen" src="http://blog.spacesocket.com/wp-content/uploads/2012/07/gps1-300x225.gif" alt="GPS Splash Screen" width="300" height="225" /></a><p class="wp-caption-text">The splash screen loaded&#8230;a good sign. But when it closed, GNAT Programming Studio didn&#8217;t start.</p></div>
<p>I was not in the mood to debug the problem and just moved on to the second option: GNATbench. <a href="http://libre.adacore.com/tools/gnatbench/" target="_blank">GNATbench</a> is a plugin for Eclipse that turns it into a complete Ada development environment. This was another 57 MB to download. Naturally, I also needed <a href="http://www.eclipse.org" target="_blank">Eclipse</a> so I went and downloaded that as well &#8212; another 192 MB.</p>
<p>I followed the instructions in the readme for GNATbench and installed it through Help-&gt;Install New Software&#8230;except it wouldn&#8217;t install. It was missing a dependency. Rereading the readme said that I needed the C/C++ Development Tools so I installed that through the dialog &#8212; it didn&#8217;t say how many MB it was but I assume it was about 5 MB based on how long it took to install. I restarted Eclipse and tried installing GNATbench again &#8212; still with no luck. I went into the dialog again and installed everything having to do with C/C++ &#8212; probably another 10 MB of downloads. Once more, GNATbench failed to install.</p>
<p>Reading  the deceptively simple readme even more closely, it said that GNATbench needed Eclipse 3.6 or 3.7&#8230;hmm, what version do I have? Eclipse 4.2???!!!??? Apparently, Eclipse 4.2 Juno was only recently released this June and GNATbench had not been updated to support it. Eclipse 3.7 was the previous version as they skipped 3.8, 4.0 and 4.1 so at least I would only be 1 version behind so I went and downloaded <a href="http://www.eclipse.org/indigo/" target="_blank">Eclipse 3.7 Indigo</a> &#8212; this time, the C/C++ version so I wouldn&#8217;t have to go through the trouble of installing them afterwards. It was another 114 MB to download but at long last, GNATbench was up and running.</p>
<p>So long story short, it took me 486 MB of downloads to get it working, but at least it works! Now if only this code will work&#8230;but that&#8217;s for next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spacesocket.com/2012/07/23/installing-gnat/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
