<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-694679611587040520</id><updated>2026-10-18T15:26:56.217-07:00</updated><category term="CLR"/><category term="JVM"/><category term="Python"/><category term="Java"/><category term="VB.NET"/><category term="Zonnon"/><category term="Boo"/><category term="C#"/><category term="C++"/><category term="Ceylon"/><category term="Cobra"/><category term="F#"/><category term="Fantom"/><category term="Gosu"/><category term="Groovy"/><category term="IronPython"/><category term="IronRuby"/><category term="JRuby"/><category term="JScript.NET"/><category term="Jython"/><category term="Keywords"/><category term="Kotlin"/><category term="Nemerle"/><category term="Oxygene"/><category term="PHP"/><category term="Phalanger"/><category term="PowerShell"/><category term="Scala"/><category term="Series"/><category term="Xtend"/><category term="DelphiPrism"/><category term="Golo"/><category term="POC"/><category term="Silver"/><category term="Swift"/><title type='text'>Carlos Quintanilla&amp;#39;s blog</title><subtitle type='html'>On (CLR, JVM) Programming Languagues</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>118</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-972945066794760435</id><published>2016-09-08T04:30:00.001-07:00</published><updated>2017-04-21T03:21:34.148-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="PowerShell"/><title type='text'>Arrays and Indexers in PowerShell</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in PowerShell. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in&amp;nbsp;PowerShell, in this case, compared to all other ~22 languages on future posts, which&amp;nbsp;essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my most recent post, &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in C# and C++ just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
NOTE:&lt;br /&gt;
PowerShell provides two different types of arrays,&amp;nbsp;PowerShell [array] objects and typed arrays [type[]]. In&amp;nbsp;PowerShell&amp;nbsp;array&amp;nbsp;objects, a script can dynamically add and remove elements, and&amp;nbsp;elements can be of any data type. In typed arrays, which are dense, the size is fixed, and elements must be the same type as the base type of the array, the least are coming from .NET types, specially multi-dimensional arrays.&lt;br /&gt;
&lt;br /&gt;
I chose to use the Typed Arrays (and all other variables as well) to keep it closer to the previous posts. I used [array] for jagged arrays [array[]], and for function/method parameter even though [object[]] should also work also.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: powershell&quot;&gt;
function ReverseChar($arr) {
    [char[]] $reversed = @(1..$arr.length)
    #[array]::Reverse($reversed)  &amp;lt;-- better to use this but for demo purposes I did it with a for 2 indexes
  
    for ($i, $j = 0, ($arr.length - 1); $j -ge 0; $i++, $j--) {
        $reversed[$i] = $arr[$j] 
    }
    return $reversed
}

function BubbleSort([array]$arr) {  
    $swap = 0  
    for ($i = ($arr.Length - 1); $i -gt 0; $i--) {  
        for ($j = 0; $j -lt $i; $j++) {  
            if ($arr[$j] -gt $arr[$j + 1]) {     
                $swap = $arr[$j]
                $arr[$j] = $arr[$j + 1]                
                $arr[$j + 1] = $swap                  
            }  
        }  
    }  
    return $arr  
}  

function TransposeMatrix([int[,]]$m) {  
    &amp;lt;# Transposing a Matrix 2,3  
        *  
        * A =  [6  4 24]T [ 6  1]  
        *      [1 -9  8]  [ 4 -9] 
        *                 [24  8] 
    #&amp;gt;
    [int[,]]$transposed = [int[,]]::new(
        $m.GetUpperBound(1) + 1,
        $m.GetUpperBound(0) + 1)
    
    for ($i = 0; $i -le $m.GetUpperBound(0); $i++) {  
        for ($j = 0; $j -le $m.GetUpperBound(1); $j++) {                          
            $transposed[$j,$i] = $m[$i,$j]
        }  
    } 
    return ,$transposed  # use comma operator to avoid unroll
}  

function UpperCaseRandomArray([array[]]$arr)  
{  
    #$r = new-object [System.Random]
    #$i = $r.Next(0, ($arr.Length - 1))
    $i = get-random -minimum -0 -maximum ($arr.Length - 1)
    for ($j = 0; $j -lt $arr[$i].Count; $j++) {
        $arr[$i][$j] = $arr[$i][$j].ToUpper()
    }
    return $arr
}  

function PrintArray([array]$arr) {
    if(!$arr) { $arr=@() }
    Write-Host(&amp;quot;`nPrint Array Content $($arr.GetType().Name) [$($arr.Length)]&amp;quot;)

    for ($i=0; $i -lt $arr.Length; $i++) {    
        Write-Host(&amp;quot; array [$($i.ToString().PadLeft(2))] = $($arr[$i].ToString().PadLeft(2))&amp;quot;)
    }
}

function PrintMatrix([int[,]]$m) {  
    Write-Host (&amp;quot;`nPrint Matrix Content {0}[{0},{0}]&amp;quot; -f 
        $m.GetType().Name.Replace(&amp;quot;[,]&amp;quot;, &amp;quot;&amp;quot;),
        ($m.GetUpperBound(0) + 1), 
        ($m.GetUpperBound(1) + 1))
            
    for ($i = 0; $i -le $m.GetUpperBound(0); $i++) {
        for ($j = 0; $j -le $m.GetUpperBound(1); $j++) {
            Write-Host (&amp;quot; array [{0,2},{1,2}] = {2,2} &amp;quot; -f $i, $j, $m[$i,$j]) 
        }
    }
}  

function GraphJaggedArray([Array[]]$arr) {  
    &amp;lt;# When using Arrays, we can use foreach operator instead of for:  
        *  
        * for ($i = 0; $i -lt $arr.Length; $i++) 
        *   for ($j = 0; $j -lt $arr.Length; $j++)
        *  
        #&amp;gt; 
    Write-Host (&amp;quot;Print Text Content $($arr.GetType().Name)`n&amp;quot;)  
    $lineCount = 1 
    foreach ($s in $arr) {  
        Write-Host -NoNewline (&amp;quot;Line{0,2}|&amp;quot; -f $lineCount)  
        foreach ($_ in $s) {  
            Write-Host -NoNewline (&amp;quot;{0,3}&amp;quot; -f &#39;*&#39;)  
        }  
        Write-Host (&amp;quot; ($($s.Length))&amp;quot;)
        $lineCount++ 
    }  
}

function PrintJaggedArray([array[]]$arr) {          
    Write-Host (&amp;quot;`nPrint Jagged Array Content $($arr.GetType().Name)&amp;quot;)  
    for ($i = 0; $i -lt $arr.Count; $i++) {  
        $line = [System.Text.StringBuilder]::new()
        for ($j = 0; $j -lt $arr[$i].Count; $j++) {
            [void]$line.Append(&amp;quot; &amp;quot;)
            [void]$line.Append($arr[$i][$j].ToString())
        }
        if (($line.ToString()) -ceq ($line.ToString().ToUpper())) {
            [void]$line.Append(&amp;quot; &amp;lt;-- [UPPERCASED]&amp;quot;)
        }
        Write-Host $line
    }  
}    


function PrintCommonArrayExceptions($arr) {      
    try {  

        if ($arr -eq $null) {             
            $arr[100] = &amp;quot;hola&amp;quot; 
        }
        elseif ($arr[0] -eq $null) {            
            $arr[100] = &amp;quot;hola&amp;quot;
        } 
        elseif ($arr[100] -eq $null) {            
            $arr[100][100] = &amp;quot;hola&amp;quot;
        }                   

        #throw [System.NullReferenceException]::new(&amp;quot;&amp;quot;)
        #throw [System.Exception]::new(&amp;quot;&amp;quot;)        
                            
    } 
    catch [System.Management.Automation.RuntimeException]{
        Write-Host (&amp;quot;`nException: `n$($_.Exception.GetType().FullName)`n$($_.Exception.Message)&amp;quot;)          
    }
    catch [System.NullReferenceException],[System.IndexOutOfRangeException] {
        Write-Host (&amp;quot;`nException: `n$($_.Exception.GetType().FullName)`n$($_.Exception.Message)&amp;quot;)  
    }               
    catch [Exception] {
        # pass
    }
    catch {
        # pass
    }
    finally {
        # pass
    }
}  

function PrintTitle([String]$message) {
    Write-Host 
    Write-Host (&amp;quot;=&amp;quot; * 55)
    Write-Host ($message)
    Write-Host (&amp;quot;=&amp;quot; * 55)
}

class Alphabet {
    # Array Field  
    hidden [char[]]$letters = @()     

    # No indexer support. 
    # Getter/Setter Method instead. 
    [char] GetItem([int]$index) {    
        return $this.letters[$index]
    } 

    [void] SetItem([int]$index, [char]$value) {
        $this.letters[$index] = [char]::ToUpper($value)
    }

    # &amp;quot;Read-Only Property&amp;quot;
    [int] Length() {    
        return $this.letters.Length
    } 

    # Constructors  
    Alphabet([int]$size) {
        $this.letters = @(,&#39; &#39; * $size)
    }

    Alphabet([string]$list) {
        $this.letters = $list.ToUpper().ToCharArray()
    }

    Alphabet([char[]]$list) {
        $this.letters = $list
    }

    # Overridden Method  
    [string] ToString() {       
        return [String]::Join(&amp;quot;,&amp;quot;, $this.letters)
    }

    # Method 
    [char[]] Slice([int]$start, [int]$length) {
        [char[]]$result = @(,&#39; &#39; * $length)
        for ($i, $j = 0, $start 
             $i -lt $length
             $i++, $j++) {  
            $result[$i] = $this.letters[$j]
        }  
        return $result
    }
}

# Single-dimensional Array(s)
printTitle(&amp;quot;Reverse Array Elements&amp;quot;)

# Declare and Initialize Array of Chars
[char[]] $letters = @(1..5)
$letters[0] = &#39;A&#39;  
$letters[1] = &#39;E&#39;  
$letters[2] = &#39;I&#39;
$letters[3] = &#39;O&#39;
$letters[4] = &#39;U&#39;

# untyped arrays or an array of type [array] are all System.Object[]  
# typed arrays need an explicit type [int[]], [string[]], or even [Object[]]

PrintArray($letters)
$inverse_letters = ReverseChar($letters)
PrintArray($inverse_letters)

PrintTitle(&amp;quot;Sort Integer Array Elements&amp;quot;)

# Declare and Initialize Array of Integers
[int[]]$numbers = @(10, 8, 3, 1, 5)
PrintArray($numbers)
[int[]]$ordered_numbers = [int[]](BubbleSort($numbers))
PrintArray($ordered_numbers)

PrintTitle(&amp;quot;Sort String Array Elements&amp;quot;)

# Declare and Initialize and Array of Strings
[string[]]$names = @(
    &amp;quot;Damian&amp;quot;,
    &amp;quot;Rogelio&amp;quot;,
    &amp;quot;Carlos&amp;quot;,
    &amp;quot;Luis&amp;quot;,
    &amp;quot;Daniel&amp;quot;
)
PrintArray($names)
[string[]]$ordered_names = BubbleSort($names)
PrintArray($ordered_names) 


# Multi-dimensional Array (Matrix row,column)  
# To declare a multi-dimensional array in PowerShell 
            
PrintTitle(&amp;quot;Transpose Matrix&amp;quot;);  
            
&amp;lt;# Matrix row=2,col=3 
    * A =  [6  4 24] 
    *      [1 -9  8] 
    * #&amp;gt;
# $matrix = New-Object &#39;int[,]&#39; 2,3
$matrix = [int[,]]::new(2,3)
$matrix[0,0], $matrix[0,1], $matrix[0,2] = 6, 4,24
$matrix[1,0], $matrix[1,1], $matrix[1,2] = 1,-9, 8 

PrintMatrix($matrix)  
[int[,]]$transposed_matrix = TransposeMatrix($matrix)
PrintMatrix($transposed_matrix)

# Jagged Array (Array-of-Arrays)
            
PrintTitle(&amp;quot;Upper Case Random Array &amp;amp; Graph Number of Elements&amp;quot;)
            
&amp;lt;#              
    * Creating an array of string arrays using the String.Split method 
    * instead of initializing it manually as follows: 
    *  
    * $text = @(  
    *      ,( &amp;quot;word1&amp;quot;, &amp;quot;word2&amp;quot;, &amp;quot;wordN&amp;quot; )
    *      ,( &amp;quot;word1&amp;quot;, &amp;quot;word2&amp;quot;, &amp;quot;wordM&amp;quot; )  
    *      ... 
    *      ) 
    *  
    * Text extract from: &amp;quot;El ingenioso hidalgo don Quijote de la Mancha&amp;quot; 
    *  
 #&amp;gt;  

[array[]]$text = @(   
  ,(&amp;quot;Hoy es el d&amp;iacute;a m&amp;aacute;s hermoso de nuestra vida, querido Sancho;&amp;quot;.Split(&#39; &#39;))  
  ,(&amp;quot;los obst&amp;aacute;culos m&amp;aacute;s grandes, nuestras propias indecisiones;&amp;quot;.Split(&#39; &#39;))  
  ,(&amp;quot;nuestro enemigo m&amp;aacute;s fuerte, miedo al poderoso y nosotros mismos;&amp;quot;.Split(&#39; &#39;))
  ,(&amp;quot;la cosa m&amp;aacute;s f&amp;aacute;cil, equivocarnos;&amp;quot;.Split(&#39; &#39;))
  ,(&amp;quot;la m&amp;aacute;s destructiva, la mentira y el ego&amp;iacute;smo;&amp;quot;.Split(&#39; &#39;))
  ,(&amp;quot;la peor derrota, el desaliento;&amp;quot;.Split(&#39; &#39;))
  ,(&amp;quot;los defectos m&amp;aacute;s peligrosos, la soberbia y el rencor;&amp;quot;.Split(&#39; &#39;))
  ,(&amp;quot;las sensaciones m&amp;aacute;s gratas, la buena conciencia...&amp;quot;.Split(&#39; &#39;))
)          

PrintJaggedArray($text)
UpperCaseRandomArray($text) &amp;gt; $null
PrintJaggedArray($text)
GraphJaggedArray($text)

# Array Exceptions  
            
PrintTitle(&amp;quot;Common Array Exceptions&amp;quot;)
            
PrintCommonArrayExceptions($null)  
PrintCommonArrayExceptions(@())
PrintCommonArrayExceptions($text)  
                  
# Accessing Class Array Elements through &amp;quot;Indexer&amp;quot; Getter/Setter    
PrintTitle(&#39;Alphabets&#39;);  

[Alphabet]$vowels = [Alphabet]::new(5)  
$vowels.setitem(0, &#39;a&#39;)  
$vowels.setitem(1, &#39;e&#39;)  
$vowels.setitem(2, &#39;i&#39;)  
$vowels.setitem(3, &#39;o&#39;)  
$vowels.setitem(4, &#39;u&#39;)  

Write-Host (&amp;quot;`nVowels = {&amp;quot; + [String]::Join(&#39;,&#39;, 
    $vowels.getitem(0), $vowels.getitem(1), $vowels.getitem(2), 
    $vowels.getitem(3), $vowels.getItem(4)) + &amp;quot;}&amp;quot;)

[Alphabet]$en = [Alphabet]::new(&#39;abcdefghijklmnopqrstuvwxyz&#39;)
Write-Host (&#39;English Alphabet = {&#39; + $en.ToString() + &amp;quot;}&amp;quot;)

Write-Host (&#39;Alphabet Extract en[9..19] = {&#39; + 
            ([Alphabet]::new($en.slice(9, 10))).tostring() + &#39;}&#39;)
  

$word1 = [String]::Join(&amp;quot;&amp;quot;, $en.getItem(6), $en.getitem(14), 
                            $en.getitem(14), $en.getitem(3))
$word2 = [String]::Join(&amp;quot;&amp;quot;, $en.getitem(1), $en.getitem(24), 
                            $en.getitem(4), $en.getitem(4))
$word3 = [String]::Join(&amp;quot;&amp;quot;, $en.getitem(4), $en.getitem(21), 
                            $en.getitem(4), $en.getitem(17),
                            $en.getitem(24), $en.getitem(14), 
                            $en.getitem(13), $en.getitem(4))

Write-Host (&amp;quot;`n$word1 $word2, $word3!&amp;quot;)

Read-Host
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI1TkXmk-Rw5XKnRGELaeq82PD5CAhbsXdVsQ9i7a-nXJUOWAhje4OHfslhElO4-KKsIAGAIToz6HeujeN3JyAxgKDk_yyfmxONADVQZhkxaG7pr_MjHVmwCIjcEVADcNFoGf-sqxzhJA/s1600/PSArraysIndexers.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI1TkXmk-Rw5XKnRGELaeq82PD5CAhbsXdVsQ9i7a-nXJUOWAhje4OHfslhElO4-KKsIAGAIToz6HeujeN3JyAxgKDk_yyfmxONADVQZhkxaG7pr_MjHVmwCIjcEVADcNFoGf-sqxzhJA/s1600/PSArraysIndexers.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/972945066794760435/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2016/09/arrays-and-indexers-in-powershell.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/972945066794760435'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/972945066794760435'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2016/09/arrays-and-indexers-in-powershell.html' title='Arrays and Indexers in PowerShell'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI1TkXmk-Rw5XKnRGELaeq82PD5CAhbsXdVsQ9i7a-nXJUOWAhje4OHfslhElO4-KKsIAGAIToz6HeujeN3JyAxgKDk_yyfmxONADVQZhkxaG7pr_MjHVmwCIjcEVADcNFoGf-sqxzhJA/s72-c/PSArraysIndexers.png" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-3758861285470257319</id><published>2016-09-02T09:17:00.000-07:00</published><updated>2017-04-21T03:21:02.148-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="PowerShell"/><title type='text'>Factorial and Fibonacci in PowerShell</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;&lt;script src=&quot;https://platform.twitter.com/widgets.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;
&lt;script src=&quot;//platform.linkedin.com/in.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script data-counter=&quot;right&quot; type=&quot;IN/Share&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in PowerShell that implements 2 classes. There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its methods are not static. And finally the script part that instantiates and executes the script program.&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial&#39;s Series and Fibonacci&#39;s Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little &quot;working&quot; program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some &quot;comments&quot; on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href=&quot;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&quot;&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href=&quot;http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html&quot;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: powershell&quot;&gt;# Factorial and Fibonacci in PowerShell 
Add-Type -Path &quot;C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Numerics.dll&quot;

# Instance Class (No static modifier at class level)
class StaticFiborial {
    # Static Field  
    hidden static [String] $className
    # Static Constructor  
    static StaticFiborial() {  
        [StaticFiborial]::className = &quot;Static Constructor&quot;
        Write-Host ([StaticFiborial]::className)
    }  
    # Static Method - Factorial Recursive  
    static [System.Numerics.BigInteger] FactorialR([Int] $n) {  
        if ($n -eq 1) {
            return 1 #[System.Numerics.BigInteger]::One  
        } else {
            return $n * [StaticFiborial]::FactorialR($n - 1)
        }
    }
    # Static Method - Factorial Imperative   
    static [System.Numerics.BigInteger] FactorialI([Int] $n) {
        $res = [System.Numerics.BigInteger]::One
        for($i = $n
            $i -ge 1
            $i--) {
            #$res = [System.Numerics.BigInteger]::Multiply($res, [System.Numerics.BigInteger]::new($i))
            $res *= $i
        }        
        return $res
    }
    # Static Method - Fibonacci Recursive  
    static [System.Numerics.BigInteger] FibonacciR([Int] $n) {  
        if ($n -lt 2) {
            return 1 #[System.Numerics.BigInteger]::One  
        } else {            
            return [StaticFiborial]::FibonacciR($n - 1) + [StaticFiborial]::FibonacciR($n - 2)
        }
    }
    # Static Method - Fibonacci Imperative  
    static [System.Numerics.BigInteger] FibonacciI([Int] $n) {  
        [long] $pre = 1
        [long] $cur = 1
        [long] $tmp = 0
        for ($i = 2; $i -le $n; $i++) {  
            $tmp = $cur + $pre
            $pre = $cur  
            $cur = $tmp  
        }  
        return $cur 
    }
    # Static Method - Benchmarking Algorithms 
    static [void] BenchmarkAlgorithm([Int] $algorithm, [int[]] $values) {
        $timer = [System.Diagnostics.Stopwatch]::new()
        $i = 0
        $testValue = 0
        $facTimeResult = [System.Numerics.BigInteger]::Zero
        $fibTimeResult = 0

        # &quot;Switch&quot; Flow Constrol Statement          
        switch ($algorithm) {          
            1 {
                Write-Host &quot;`nFactorial Imperative:&quot;
                # &quot;For&quot; Loop Statement
                for($i = 0; $i -lt $values.Length; $i++) {
                    $testValue = $values[$i]
                    # Taking Time   
                    $timer.Start()
                    $facTimeResult = [StaticFiborial]::FactorialI($testValue)
                    $timer.Stop()
                    # Getting Time    
                    Write-Host (&quot; ({0}) = {1}&quot; -f $testValue, $timer.Elapsed)
                }                
            }
            2 {
                Write-Host &quot;`nFactorial Recursive:&quot;      
                # &quot;While&quot; Loop Statement          
                while ($i -lt $values.Length) { 
                    $testValue = $values[$i]
                    # Taking Time   
                    $timer.Start()
                    $facTimeResult = [StaticFiborial]::FactorialR($testValue)
                    $timer.Stop()
                    # Getting Time    
                    Write-Host (&quot; ({0}) = {1}&quot; -f $testValue, $timer.Elapsed)
                    $i++                
                }                          
            }
            3 {
                Write-Host &quot;`nFibonacci Imperative:&quot;      
                # &quot;Do-While&quot; Loop Statement           
                do {
                    $testValue = $values[$i]
                    # Taking Time   
                    $timer.Start()
                    $fibTimeResult = [StaticFiborial]::FibonacciI($testValue)
                    $timer.Stop()
                    # Getting Time    
                    Write-Host (&quot; ({0}) = {1}&quot; -f $testValue, $timer.Elapsed)
                    $i++                
                } while ($i -lt $values.Length)                       
            }
            4 {
                Write-Host &quot;`nFibonacci Recursive:&quot;
                # &quot;For&quot; Loop Statement
                foreach ($testValue in $values) {                    
                    # Taking Time   
                    $timer.Start()
                    $fibTimeResult = [StaticFiborial]::FibonacciR($testValue)
                    $timer.Stop()
                    # Getting Time    
                    Write-Host (&quot; ({0}) = {1}&quot; -f $testValue, $timer.Elapsed)
                }                
            }
            default {   
                echo &quot;DONG!`n&quot;                
            }
        }
    }
}


# Instance Class
class InstanceFiborial {
    # Instance Field
    hidden [string] $className
    # Instance Constructor
    InstanceFiborial() {
        $this.className = &quot;Instance Constructor&quot;
        Write-Host $this.className
    }
    # Instance Method - Factorial Recursive
    [System.Numerics.BigInteger] FactorialR([int] $n) {
        # Calling Static Method
        return [StaticFiborial]::FactorialR($n)
    }
    # Instance Method - Factorial Imperative
    [System.Numerics.BigInteger] FactorialI([int] $n) {
        # Calling Static Method
        return [StaticFiborial]::FactorialI($n)
    }
    # Instance Method - Fibonacci Recursive
    [long] FibonacciR([int] $n) {
        # Calling Static Method
        return [StaticFiborial]::FibonacciR($n)
    }
    # Instance Method - Factorial Imperative
    [long] FibonacciI([int] $n) {
        # Calling Static Method
        return [StaticFiborial]::FibonacciI($n)
    }
}


Write-Host &quot;`nInstance Class (with static methods)&quot;
# Calling Static Methods
# Instantiation needed. Calling method directly from the class

Write-Host (&quot;FacImp(5) = {0}&quot; -f [StaticFiborial]::FactorialI(5))
Write-Host (&quot;FacRec(5) = {0}&quot; -f [StaticFiborial]::FactorialR(5))
Write-Host (&quot;FibImp(11)= {0}&quot; -f [StaticFiborial]::FibonacciI(11))
Write-Host (&quot;FibRec(11)= {0}&quot; -f [StaticFiborial]::FibonacciR(11))

Write-Host &quot;`nInstance Class&quot;
# Calling Instance Class and Methods 
# Need to instantiate before using. Calling method from instantiated object

$ff = [InstanceFiborial]::new()
# or
# $ff = New-Object InstanceFiborial

Write-Host (&quot;FacImp(5) = {0}&quot; -f $ff.FactorialI(5))
Write-Host (&quot;FacRec(5) = {0}&quot; -f $ff.FactorialR(5))
Write-Host (&quot;FibImp(11)= {0}&quot; -f $ff.FibonacciI(11))
Write-Host (&quot;FibRec(11)= {0}&quot; -f $ff.FibonacciR(11))


# Create a (generic) list of integer values to test
# From 5 to 50 by 5
$values = @()
for($i = 5; $i -le 50; $i += 5) {
    $values += $i
}

# Benchmarking Fibonacci                     
# 1 = Factorial Imperative            
[StaticFiborial]::BenchmarkAlgorithm(1, $values)
# 2 = Factorial Recursive
[StaticFiborial]::BenchmarkAlgorithm(2, $values) 

# Benchmarking Factorial            
# 3 = Fibonacci Imperative
[StaticFiborial]::BenchmarkAlgorithm(3, $values)
# 4 = Fibonacci Recursive
[StaticFiborial]::BenchmarkAlgorithm(4, $values)

# Stop and Exit
Read-Host 

&lt;/pre&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEgt4064IllrIpklCWe7dTk6yBhFU7YRMPLEhQLGo9lfmW43NSozijkl_AoW8fCDUv16VUpbqpPCeKL9BsXYK_KE20zSu3BCK8lOF6eRSuCWOOIzFNhbGlrVVR4oYxvwV8oTY1K9ke7aY/s1600/PowerShellFiborialOutput.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEgt4064IllrIpklCWe7dTk6yBhFU7YRMPLEhQLGo9lfmW43NSozijkl_AoW8fCDUv16VUpbqpPCeKL9BsXYK_KE20zSu3BCK8lOF6eRSuCWOOIzFNhbGlrVVR4oYxvwV8oTY1K9ke7aY/s1600/PowerShellFiborialOutput.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: powershell&quot;&gt;Add-Type -Path &quot;C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Numerics.dll&quot;

class Fiborial {

    # Using a StringBuilder as a list of string elements
    static [String] GetFactorialSeries([int] $n) {
        # Create the String that will hold the list
        $series = [System.Text.StringBuilder]::new()
        # We begin by concatenating the number you want to calculate
        # in the following format: &quot;!# =&quot;
        [void]$series.Append(&quot;!&quot;)
        [void]$series.Append($n)
        [void]$series.Append(&quot; = &quot;)
        # We iterate backwards through the elements of the series
        for($i = $n; $i -le $n -and $i -gt 0; $i--) {        
            # and append it to the list
            [void]$series.Append($i)
            if ($i -gt 1) {
                [void]$series.Append(&quot; * &quot;)
            }
            else {
                [void]$series.Append(&quot; = &quot;) 
            }
        }
        # Get the result from the Factorial Method
        # and append it to the end of the list
        [void]$series.Append([Fiborial]::Factorial($n))
        # return the list as a string        

        return $series.ToString()
    }

    # Using a StringBuilder as a list of string elements
    static [String] GetFibonnaciSeries([int] $n) {
        # Create the String that will hold the list
        $series = New-Object -TypeName &quot;System.Text.StringBuilder&quot;
        # We begin by concatenating the first 3 values which
        # are always constant
        [void]$series.Append(&quot;0, 1, 1&quot;)
        # Then we calculate the Fibonacci of each element
        # and add append it to the list
        for ($i = 2
             $i -le $n
             $i++) {
            if ($i -lt $n) {
                [void]$series.Append(&quot;, &quot;)
            }
            else {
                [void]$series.Append(&quot; = &quot;)
            }
                
            [void]$series.Append([Fiborial]::Fibonacci($i))
        }
        # return the list as a string
        return $series.ToString()
    }

    static [System.Numerics.BigInteger] Factorial([Int] $n) {  
        if ($n -eq 1) {
            return [System.Numerics.BigInteger]::One  
        } else {
            return $n * [Fiborial]::Factorial($n - 1)
        }
    }

    static [System.Numerics.BigInteger] Fibonacci([Int] $n) {  
        if ($n -lt 2) {
            return [System.Numerics.BigInteger]::One  
        } else {            
            return [Fiborial]::Fibonacci($n - 1) + [Fiborial]::Fibonacci($n - 2)
        }
    }
}


echo (&quot;Printing Factorial Series&quot;)
echo ([Fiborial]::GetFactorialSeries(5))
echo ([Fiborial]::GetFactorialSeries(7))
echo ([Fiborial]::GetFactorialSeries(9))
echo ([Fiborial]::GetFactorialSeries(11))
echo ([Fiborial]::GetFactorialSeries(40))

Write-Host  (&quot;Printing Fibonacci Series&quot;)
Write-Host  ([Fiborial]::GetFibonnaciSeries(5))
Write-Host  ([Fiborial]::GetFibonnaciSeries(7))
Write-Host  ([Fiborial]::GetFibonnaciSeries(9))
Write-Host  ([Fiborial]::GetFibonnaciSeries(11))
Write-Host  ([Fiborial]::GetFibonnaciSeries(40))
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyvV7SoyYCzDkxnNTqQCVJ4kJvf5dgMyqTAFy19cyuL7KEPXwQN6k5kHHy49YQFKGHsF5KMuTDl7jW5pedEpTP9mnHHG-zYIQUcmVUvJKm24KaTt1MJf9WQ5_gNROivkVnzhlTr7pQHX4/s1600/PowerShellFiborialSeries.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyvV7SoyYCzDkxnNTqQCVJ4kJvf5dgMyqTAFy19cyuL7KEPXwQN6k5kHHy49YQFKGHsF5KMuTDl7jW5pedEpTP9mnHHG-zYIQUcmVUvJKm24KaTt1MJf9WQ5_gNROivkVnzhlTr7pQHX4/s1600/PowerShellFiborialSeries.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, constructors, methods, etc. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: powershell&quot;&gt;   
Add-Type -Path &quot;C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Numerics.dll&quot;

# Instance Class  
class Fiborial {

    # Instance Field  
    hidden [int] $instanceCount  
    # Static Field  
    hidden static [int] $staticCount          
    # Instance Read-Only Property/Getter  
    # Within instance members, you can always use    
    # the &quot;this&quot; reference pointer to access your (instance) members.  
    [int] GetInstanceCount() {  
        return $this.instanceCount
    }  
    # Static Read-Only Property/Getter  
    # As with Static Methods, you cannot reference your class members  
    # with the &quot;this&quot; reference pointer since static members are not  
    # instantiated.
    static [int] GetStaticCount() {  
        return [Fiborial]::staticCount
    }  
    # Instance Constructor 
    Fiborial() {    
        $this.instanceCount = 0
        Write-Host (&quot;Instance Constructor $($this.instanceCount)`n&quot;)
    }    
    # Static Constructor  
    static Fiborial() {
        [Fiborial]::staticCount = 0
        Write-Host (&quot;Static Constructor $([Fiborial]::staticCount)`n&quot;)
    }
    # Instance Method  
    [void] Factorial([int] $n)  
    {    
        $this.instanceCount++  
        Write-Host (&quot;Factorial($n)`n&quot;) 
    }  
    # Static Method  
    static [void] Fibonacci([int] $n)   
    {      
        [Fiborial]::staticCount++
        Write-Host (&quot;Fibonacci($n)`n&quot;)  
    }      
}

# Calling Static Constructor/Initializer and Methods  
# No need to instantiate  
[Fiborial]::Fibonacci(5)              
  
# Calling Instance Constructor and Methods  
# Instance required  
$fib = [Fiborial]::new()
$fib.Factorial(5)  

[Fiborial]::Fibonacci(15)              
$fib.Factorial(5)  

# Calling Instance Constructor and Methods  
# for a second object  
$fib2 = [Fiborial]::new()  
$fib2.Factorial(5)

# Calling Static Method  
Write-Host (&quot;Static Count = $([Fiborial]::GetStaticCount())&quot;)  
# Calling Instance Property of object 1 and 2  
Write-Host (&quot;Instance 1 Count = $($fib.GetInstanceCount())&quot;)
Write-Host (&quot;Instance 2 Count = $($fib2.GetInstanceCount())&quot;)  
  
Read-Host 

&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis2LVGrMBpB5dEaY-yoZaElVcPOtx75vdUB6GrHoEVs1VabwJpRIBGmpNI9nfvtahYxElxwVHH1AAMisyjeFtkmbWkY5YGg0mHiz_-Glxpj5Fpwd40Vkc6JVKn7ut1RatZ2JGcJ3gmaVI/s1600/PSFiborialMix.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis2LVGrMBpB5dEaY-yoZaElVcPOtx75vdUB6GrHoEVs1VabwJpRIBGmpNI9nfvtahYxElxwVHH1AAMisyjeFtkmbWkY5YGg0mHiz_-Glxpj5Fpwd40Vkc6JVKn7ut1RatZ2JGcJ3gmaVI/s1600/PSFiborialMix.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64, System.Double, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the &quot;wrong&quot; result &lt;br /&gt;
!40 = -70609262346240000 when using &quot;long&quot; (System.Int64) type, but it was not until I did the Fiborial version in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET, JScript.NET, Boo execution thrown an Overflow Exception when using the &quot;Long/long&quot; (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for &quot;big&quot; numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System.Numerics.BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger  &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just said, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;php&quot; name=&quot;code&quot;&gt;&lt;/pre&gt;
&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics.dll assembly to your project so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnehOsMLbRhjbI3mJ4mkf9entrlPzYVG5ctQrsi3COZEQHfoMeFRGxMqqqBOpowy8SGrF51o4vB3o8yY7WGOwR7qVNyf_I2-1Ul8KIPvo9lZhakJ80wWm2Uh8tf_-ray0jmzx3fYGQnj0/s1600/PSFiborialMix.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnehOsMLbRhjbI3mJ4mkf9entrlPzYVG5ctQrsi3COZEQHfoMeFRGxMqqqBOpowy8SGrF51o4vB3o8yY7WGOwR7qVNyf_I2-1Ul8KIPvo9lZhakJ80wWm2Uh8tf_-ray0jmzx3fYGQnj0/s1600/PSFiborialMix.PNG&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnehOsMLbRhjbI3mJ4mkf9entrlPzYVG5ctQrsi3COZEQHfoMeFRGxMqqqBOpowy8SGrF51o4vB3o8yY7WGOwR7qVNyf_I2-1Ul8KIPvo9lZhakJ80wWm2Uh8tf_-ray0jmzx3fYGQnj0/s1600/PSFiborialMix.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnehOsMLbRhjbI3mJ4mkf9entrlPzYVG5ctQrsi3COZEQHfoMeFRGxMqqqBOpowy8SGrF51o4vB3o8yY7WGOwR7qVNyf_I2-1Ul8KIPvo9lZhakJ80wWm2Uh8tf_-ray0jmzx3fYGQnj0/s1600/PSFiborialMix.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnehOsMLbRhjbI3mJ4mkf9entrlPzYVG5ctQrsi3COZEQHfoMeFRGxMqqqBOpowy8SGrF51o4vB3o8yY7WGOwR7qVNyf_I2-1Ul8KIPvo9lZhakJ80wWm2Uh8tf_-ray0jmzx3fYGQnj0/s1600/PSFiborialMix.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnehOsMLbRhjbI3mJ4mkf9entrlPzYVG5ctQrsi3COZEQHfoMeFRGxMqqqBOpowy8SGrF51o4vB3o8yY7WGOwR7qVNyf_I2-1Ul8KIPvo9lZhakJ80wWm2Uh8tf_-ray0jmzx3fYGQnj0/s1600/PSFiborialMix.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnehOsMLbRhjbI3mJ4mkf9entrlPzYVG5ctQrsi3COZEQHfoMeFRGxMqqqBOpowy8SGrF51o4vB3o8yY7WGOwR7qVNyf_I2-1Ul8KIPvo9lZhakJ80wWm2Uh8tf_-ray0jmzx3fYGQnj0/s1600/PSFiborialMix.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/3758861285470257319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2016/09/factorial-and-fibonacci-in-powershell.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/3758861285470257319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/3758861285470257319'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2016/09/factorial-and-fibonacci-in-powershell.html' title='Factorial and Fibonacci in PowerShell'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEgt4064IllrIpklCWe7dTk6yBhFU7YRMPLEhQLGo9lfmW43NSozijkl_AoW8fCDUv16VUpbqpPCeKL9BsXYK_KE20zSu3BCK8lOF6eRSuCWOOIzFNhbGlrVVR4oYxvwV8oTY1K9ke7aY/s72-c/PowerShellFiborialOutput.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-7435797371132441178</id><published>2015-11-17T09:26:00.000-08:00</published><updated>2017-04-21T03:17:09.891-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="PowerShell"/><title type='text'>PowerShell - Basics by Example</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;&lt;script src=&quot;http://platform.twitter.com/widgets.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;//platform.linkedin.com/in.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script data-counter=&quot;right&quot; type=&quot;IN/Share&quot;&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
To continue with the Basics by Example. today&#39;s version of the post written in &lt;b&gt;PowerShell&lt;/b&gt; Enjoy!
&lt;br /&gt;
&lt;br /&gt;
You can copy and paste the code below in your favorite IDE/Editor, I use PowerShell ISE, and start playing and learning with it. This little &quot;working&quot; program will teach you the basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
Beware that this is using the class keyword introduced on PowerShell version 5.0. If you&#39;re on Windows 10, you must have it already, otherwise you will need to download the &lt;a href=&quot;https://www.microsoft.com/en-us/download/details.aspx?id=48729&quot; target=&quot;_blank&quot;&gt;Windows Management Framework 5.0 Production Preview&lt;/a&gt;&amp;nbsp;. You can check your current version using the following command:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgNEl1NBDC_hXZ3dD6vnZLgvIJuc80onbQarnSIRS-KN5bUlMDotkQ8wabVenLID8uWVpT4Zirx0PuSeUPZKkeLM8g8_jchFk1HY1isaIDJtEG3OtNEiBklvHbw_7FZhoEG9ZkJ-LvusU/s1600/ps+version.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;70&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgNEl1NBDC_hXZ3dD6vnZLgvIJuc80onbQarnSIRS-KN5bUlMDotkQ8wabVenLID8uWVpT4Zirx0PuSeUPZKkeLM8g8_jchFk1HY1isaIDJtEG3OtNEiBklvHbw_7FZhoEG9ZkJ-LvusU/s320/ps+version.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are some &quot;comments&quot; on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href=&quot;http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html&quot;&gt;http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html&lt;/a&gt;&amp;nbsp;&lt;a href=&quot;http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html&quot;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Greetings Program - Verbose&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;pre class=&quot;brush: powershell&quot;&gt;# PowerShell Basics

# Greeting Class  
class Greet {
    # Fields and Auto-Properties (PowerShell doesn&#39;t differentiate between fields &amp;amp; properties)
    [String] $message = &quot;&quot;
    [String] $name = &quot;&quot;
    [Int] $loopMessage = 0
    # Set-Property method 
    [void] setMessage([String] $value) {
        $this.message = $this.Capitalize($value)
    }
    [void] setName([String] $value) {
        $this.name = $this.Capitalize($value)
    }
    # Constructor 
    Greet() {
        $this.message = &quot;&quot;
        $this.name = &quot;&quot;
        $this.loopMessage = 1
    }
    # Overloaded Constructor  
    Greet([String] $message, [String] $name, [String] $loopMessage) {
        $this.message = $message
        $this.name = $name
        $this.loopMessage = $loopMessage
    }
    # Method 1
    [String] Capitalize([String] $val) {
        if ($val.Length -eq 0) {  
            return &quot;&quot;
        } else {
            return (Get-Culture).TextInfo.ToTitleCase($val)            
        }
        #Write-Host (&quot;Hello {0}!`n&quot; -f $this.name)
    }    
    # Method 2    
    [void] Salute() {
        # &quot;for&quot; statement (no need of ; if linebreak used) 
        for ($i = 0; $i -lt $this.loopMessage; $i++) {  
            Write-Host (&quot;{0} {1}!&quot; -f $this.message, $this.name)
        }  
    }  
    # Overloaded Method 2.1  
    [void] Salute([String] $message, [String] $name, [String] $loopMessage) {
        $i = 0
        # &quot;while&quot; statement  
        while ($i -lt $loopMessage) {  
            Write-Host (&quot;{0} {1}!&quot; -f $this.Capitalize($message), $this.Capitalize($name))
            $i++
        }       
    }  
    # Overloaded Method 2.2  
    [void] Salute([String] $name) {
        $dtNow = Get-Date
        switch -regex ($dtNow.Hour) {
            &quot;^(10|11|[6-9])&quot; {$this.message = &quot;good morning,&quot;;break} 
            &quot;^(1[2-7])&quot; {$this.message = &quot;good afternoon,&quot;;break} 
            &quot;^(1[8-9]|2[0-2])&quot; {$this.message = &quot;good evening,&quot;;break}             
            &quot;^(23|[0-5])&quot; { $this.message = &quot;good night,&quot;;break} 
            default {$this.message =&quot;huh?&quot;}
        }
        Write-Host (&quot;{0} {1}!&quot; -f $this.Capitalize($this.message), $this.Capitalize($name))
    }
}

# Console Program  

# Define object of type Greet and Instantiate. Call Constructor  
$g = [Greet]::new()
# Call Set (Methods)Properties and Property (PS is case-insensitive)
$g.setMessage(&quot;hello&quot;)
$g.setName(&quot;world&quot;)
$g.LoopMessage = 5 
# Call Method 2  
$g.Salute()  
# Call Overloaded Method 2.1 and Get Properties  
$g.Salute($g.Message, &quot;powershell&quot;, $g.LoopMessage)
# Call Overloaded Method 2.2  
$g.Salute(&quot;carlos&quot;)
              
# Stop and Exit  
Read-Host &quot;Press any key to exit...&quot;
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Greetings Program - Minimal&lt;/b&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
And the Output is:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgyGTmPsSPnKWPfuW4uemEfZQ63jCHCL33EijTH8zrGRiGKX-AHR0VPM1fBNW3K8rD2fScpGC8l7XZjpOPa8xNailTCV2KDfZMY6LgW7G1ihbmN0rkG8JKrXvIZluRjWH-4-aXlc1reFc/s1600/oobasics+ps1+output.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgyGTmPsSPnKWPfuW4uemEfZQ63jCHCL33EijTH8zrGRiGKX-AHR0VPM1fBNW3K8rD2fScpGC8l7XZjpOPa8xNailTCV2KDfZMY6LgW7G1ihbmN0rkG8JKrXvIZluRjWH-4-aXlc1reFc/s1600/oobasics+ps1+output.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIF_kbDI1-E3ygNvPTWp43TRRH3dNbRwZ4x-k2cG-Hhj5aokuc-C2yzz7ePKoXilDU-QVS9sdWuZs8LgQlG_CMyY_gUdKGvnrq2qlq_FUtvKWHShfEPbbjWydDEX2r1g9kZriDpaeyrk0/s1600/output_java.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt; &lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIF_kbDI1-E3ygNvPTWp43TRRH3dNbRwZ4x-k2cG-Hhj5aokuc-C2yzz7ePKoXilDU-QVS9sdWuZs8LgQlG_CMyY_gUdKGvnrq2qlq_FUtvKWHShfEPbbjWydDEX2r1g9kZriDpaeyrk0/s1600/output_java.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt; &lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIF_kbDI1-E3ygNvPTWp43TRRH3dNbRwZ4x-k2cG-Hhj5aokuc-C2yzz7ePKoXilDU-QVS9sdWuZs8LgQlG_CMyY_gUdKGvnrq2qlq_FUtvKWHShfEPbbjWydDEX2r1g9kZriDpaeyrk0/s1600/output_java.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt; &lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/7435797371132441178/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2015/11/powershell-basics-by-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/7435797371132441178'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/7435797371132441178'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2015/11/powershell-basics-by-example.html' title='PowerShell - Basics by Example'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgNEl1NBDC_hXZ3dD6vnZLgvIJuc80onbQarnSIRS-KN5bUlMDotkQ8wabVenLID8uWVpT4Zirx0PuSeUPZKkeLM8g8_jchFk1HY1isaIDJtEG3OtNEiBklvHbw_7FZhoEG9ZkJ-LvusU/s72-c/ps+version.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-7288355178473858315</id><published>2015-11-12T09:38:00.000-08:00</published><updated>2017-04-21T03:20:08.943-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="PowerShell"/><title type='text'>OO Hello World - PowerShell</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;&lt;script src=&quot;http://platform.twitter.com/widgets.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
The Hello World in PowerShell is finally here!&lt;br /&gt;
&lt;br /&gt;
&quot;Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework.&quot; Its been around for ~8 years (2006), but it is until now, with the release of version 5.0, that they finally introduce classes as a built-in feature of the language. 
&lt;br /&gt;
&lt;br /&gt;
Now that the language have classes, properties, methods, constructors, static members, inheritance and so, we can compare its syntax with all other languages on this blog.
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
By the way, you can see my previous post here: &lt;a href=&quot;http://carlosqt.blogspot.com/2010/06/oo-hello-world.html&quot; target=&quot;_blank&quot;&gt;http://carlosqt.blogspot.com/2010/06/oo-hello-world.html&lt;/a&gt;&amp;nbsp;where I give some details on WHY these &quot;OO Hello World series&quot; samples.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Version 1 (Minimal):&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;The minimum you need to type to get your program compiled and running.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;/div&gt;
&lt;pre class=&quot;brush: powershell&quot;&gt;class Greet {
    [String] $name;
    Greet([String] $name) {
        $this.name = ([String]$name[0]).ToUpper() + $name.Substring(1);
    }
    [void] Salute() {
        Write-Host (&quot;Hello {0}!`n&quot; -f $this.name)
    }    
}

$g = [Greet]::new(&quot;World&quot;)
$g.Salute()
&lt;/pre&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Version 2 (Verbose):&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Explicitly adding instructions and keywords that are optional to the compiler.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;/div&gt;
&lt;pre class=&quot;brush: powershell&quot;&gt;class Greet {
    [String] $name;
    Greet([String] $name) {
        $this.name = ([String]$name[0]).ToUpper() + $name.Substring(1);
    }
    [void] Salute() {
        Write-Host (&quot;Hello {0}!`n&quot; -f $this.name)
    }    
}

$g = [Greet]::new(&quot;World&quot;)
$g.Salute()
&lt;/pre&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Both version are completely similar. 
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;The Program Output:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjIH5ljaabscAj9qaKHkeH9CQPLRERb0DqkuOXF60ZW5FUYqVrQSBPZ06K2G_R4cKwBeHmqHmTHqj4MloCRphvuZWFuA-XmYZ_URb39NJgZD5srXYe2KJszoCPiRW9RO3PRukiAwZihtM/s1600/oohellops1.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjIH5ljaabscAj9qaKHkeH9CQPLRERb0DqkuOXF60ZW5FUYqVrQSBPZ06K2G_R4cKwBeHmqHmTHqj4MloCRphvuZWFuA-XmYZ_URb39NJgZD5srXYe2KJszoCPiRW9RO3PRukiAwZihtM/s1600/oohellops1.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;u&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;PowerShell Info:&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
“PowerShell is an automation platform and scripting language for Windows and Windows Server that allows you to simplify the management of your systems. Unlike other text-based shells, PowerShell harnesses the power of the .NET Framework, providing rich objects and a massive set of built-in functionality for taking control of your Windows environments. ” Taken from:&amp;nbsp;&lt;a href=&quot;https://msdn.microsoft.com/en-us/mt173057.aspx&quot; target=&quot;_blank&quot;&gt;https://msdn.microsoft.com/en-us/mt173057.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoNormalTable&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-firstrow: yes; mso-yfti-irow: 0;&quot;&gt;   &lt;td style=&quot;border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Appeared:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;2006&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 1;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Current Version:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;5.0&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12pt;&quot;&gt;&amp;nbsp;(&lt;a href=&quot;http://carlosqt.blogspot.com/p/programming-languages.html&quot;&gt;latest version in &quot;Languages&quot; page&lt;/a&gt;)&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 2;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Developed by:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Microsoft&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 3;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Creator:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Jeffrey Snover, Bruce Payette, James Truher&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 4;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Influenced by:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;C# and Perl, Tcl, Cmd&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 5;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Predecessor Language&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
~WSH (VBScript, JScript)&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 6;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Predecessor Appeared&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
1998&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 7;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Predecessor Creator&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: serif , serif; font-size: 16px;&quot;&gt;Microsoft&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 8;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Runtime Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;CLR 4.x&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 9;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Latest Framework Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12pt;&quot;&gt;CLR 4.x&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 10;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Mono Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12pt;&quot;&gt;No&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 11;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Allows Unmanaged Code:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 12;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Source Code Extension:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;&quot;.ps1&quot;, &quot;ps*&quot;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 13;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Keywords:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12pt;&quot;&gt;35&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 14;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Case Sensitive:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;No&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 15;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Free Version Available:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Yes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 16;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Open Source:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;No&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 17;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Standard:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;No&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 18;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Latest IDE Support:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNoSpacing&quot;&gt;
PowerShell ISE&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;a href=&quot;https://www.microsoft.com/en-us/download/details.aspx?id=48729&quot; target=&quot;_blank&quot;&gt;https://www.microsoft.com/en-us/download/details.aspx?id=48729&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 19;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Language Reference:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;a href=&quot;https://www.microsoft.com/en-us/download/details.aspx?id=36389&quot; target=&quot;_blank&quot;&gt;https://www.microsoft.com/en-us/download/details.aspx?id=36389&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 20; mso-yfti-lastrow: yes;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;More Info:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;a href=&quot;http://blogs.msdn.com/b/powershell/&quot; target=&quot;_blank&quot;&gt;http://blogs.msdn.com/b/powershell/&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;a href=&quot;http://blogs.technet.com/b/heyscriptingguy/&quot; target=&quot;_blank&quot;&gt;http://blogs.technet.com/b/heyscriptingguy/&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;https://github.com/PowerShell&quot; target=&quot;_blank&quot;&gt;https://github.com/PowerShell&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 19.2pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/7288355178473858315/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2015/11/oo-hello-world-powershell_12.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/7288355178473858315'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/7288355178473858315'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2015/11/oo-hello-world-powershell_12.html' title='OO Hello World - PowerShell'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjIH5ljaabscAj9qaKHkeH9CQPLRERb0DqkuOXF60ZW5FUYqVrQSBPZ06K2G_R4cKwBeHmqHmTHqj4MloCRphvuZWFuA-XmYZ_URb39NJgZD5srXYe2KJszoCPiRW9RO3PRukiAwZihtM/s72-c/oohellops1.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-6424293467944543032</id><published>2015-11-08T05:04:00.000-08:00</published><updated>2015-11-08T05:04:26.300-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="Silver"/><category scheme="http://www.blogger.com/atom/ns#" term="Swift"/><title type='text'>OO Hello World - Silver</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;&lt;script src=&quot;http://platform.twitter.com/widgets.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Hi-yo Silver! Away!&lt;br /&gt;
&lt;br /&gt;
The Hello World in Silver is here! Silver is a free implementation of Apple&#39;s Swift programming language being actively developed by &lt;a href=&quot;http://www.remobjects.com/about/&quot; target=&quot;_blank&quot;&gt;RemObjects&lt;/a&gt;, the company behind the exceptional language Oxygene.&lt;br /&gt;
&lt;br /&gt;
As mentioned on their website: &quot;Silver is a truly native Swift compiler for the .NET CLR, the Java/Android JVM and the Cocoa runtime. Built on over ten years of solid compiler knowledge and technology, Silver is a truly native Swift compiler for the .NET CLR, the Java/Android JVM and the Cocoa runtime.&quot; &lt;a href=&quot;http://www.elementscompiler.com/elements/silver&quot; target=&quot;_blank&quot;&gt;http://www.elementscompiler.com/elements/silver&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
By the way, you can see my previous post here: &lt;a href=&quot;http://carlosqt.blogspot.com/2010/06/oo-hello-world.html&quot; target=&quot;_blank&quot;&gt;http://carlosqt.blogspot.com/2010/06/oo-hello-world.html&lt;/a&gt;&amp;nbsp;where I give some details on WHY these &quot;OO Hello World series&quot; samples.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Version 1 (Minimal):&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;The minimum you need to type to get your program compiled and running.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;/div&gt;
&lt;pre class=&quot;javascript&quot; name=&quot;code&quot;&gt;class Greet {
 var name: String

 init(name: String) {
        self.name = Char.ToUpper(name.0) + name.Substring(1)
    }

 func salute() {
  println(&quot;Hello \(name)!&quot;)
 }
}

let g = Greet(name: &quot;world&quot;)
g.salute()
&lt;/pre&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Version 2 (Verbose):&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Explicitly adding instructions and keywords that are optional to the compiler.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;/div&gt;
&lt;pre class=&quot;javascript&quot; name=&quot;code&quot;&gt;import System
class Greet {
 private var name: String

 public init(name: String) {
        self.name = Char.ToUpper(name.0) + name.Substring(1)
    }

 public func salute() {
  println(&quot;Hello \(name)!&quot;)
 }
}

let g = Greet(name: &quot;world&quot;)
g.salute()
&lt;/pre&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;The Program Output:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkFHQLMSd9czJmihROp20YNYpUI4hCUy2wo75-a_34TVjJ5scwW27iw4vYCXzexzpmFwclN_tr_-mqgGNAtAYhyphenhyphenDxlUM3ZwPRYm49jWyogF6sMfPjuo5ljhAyPZVwfi855eGalBpQi_QI/s1600/OOHelloWorldSilver.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkFHQLMSd9czJmihROp20YNYpUI4hCUy2wo75-a_34TVjJ5scwW27iw4vYCXzexzpmFwclN_tr_-mqgGNAtAYhyphenhyphenDxlUM3ZwPRYm49jWyogF6sMfPjuo5ljhAyPZVwfi855eGalBpQi_QI/s1600/OOHelloWorldSilver.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;u&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Swift (&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;u&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Silver)&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;u&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;&amp;nbsp;Info:&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
“Swift is a new programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming easier, more flexible, and more fun..” Taken from:&amp;nbsp;&lt;a href=&quot;https://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11&quot; target=&quot;_blank&quot;&gt;https://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoNormalTable&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-firstrow: yes; mso-yfti-irow: 0;&quot;&gt;   &lt;td style=&quot;border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Appeared:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;2014&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 1;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Current Version:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Silver 8.2 beta, Swift 2.1&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12pt;&quot;&gt;&amp;nbsp;(&lt;a href=&quot;http://carlosqt.blogspot.com/p/programming-languages.html&quot;&gt;latest version in &quot;Languages&quot; page&lt;/a&gt;)&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 2;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Developed by:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Silver by RemObjects, Swift by Apple Inc.&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 3;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Creator:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Silver by RemObjects,&amp;nbsp;Swift by Chris Lattner and Apple Inc.&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 4;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Influenced by:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, D&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 5;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Predecessor Language&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 6;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Predecessor Appeared&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 7;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Predecessor Creator&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 8;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Runtime Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;CLR and JVM&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 9;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Latest Framework Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12pt;&quot;&gt;CLR 4.x JDK 8&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 10;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Mono Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12pt;&quot;&gt;No&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 11;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Allows Unmanaged Code:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Yes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 12;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Source Code Extension:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;“.swift”&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 13;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Keywords:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12pt;&quot;&gt;Silver 89, Swift 80&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 14;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Case Sensitive:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Yes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 15;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Free Version Available:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Yes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 16;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Open Source:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Swift Yes, Silver No.&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 17;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Standard:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;No&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 18;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Latest IDE Support:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNoSpacing&quot;&gt;
Visual Studio 2013&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;a href=&quot;http://www.elementscompiler.com/elements/download.aspx&quot; target=&quot;_blank&quot;&gt;http://www.elementscompiler.com/elements/download.aspx&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 19;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;Language Reference:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;a href=&quot;http://docs.elementscompiler.com/Silver/&quot; target=&quot;_blank&quot;&gt;http://docs.elementscompiler.com/Silver/&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;a href=&quot;https://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11&quot; target=&quot;_blank&quot;&gt;https://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;mso-yfti-irow: 20; mso-yfti-lastrow: yes;&quot;&gt;   &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;&quot; valign=&quot;top&quot; width=&quot;227&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;&amp;quot; , serif , &amp;quot;&amp;quot; , serif; font-size: 12pt;&quot;&gt;More Info:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;&quot; valign=&quot;top&quot; width=&quot;468&quot;&gt;&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Swift_(programming_language)&quot; target=&quot;_blank&quot;&gt;https://en.wikipedia.org/wiki/Swift_(programming_language)&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;a href=&quot;http://www.elementscompiler.com/elements/silver/&quot; target=&quot;_blank&quot;&gt;http://www.elementscompiler.com/elements/silver/&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://swiftlang.eu/&quot; target=&quot;_blank&quot;&gt;http://swiftlang.eu&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 19.2pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/6424293467944543032/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2015/11/oo-hello-world-silver.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/6424293467944543032'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/6424293467944543032'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2015/11/oo-hello-world-silver.html' title='OO Hello World - Silver'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkFHQLMSd9czJmihROp20YNYpUI4hCUy2wo75-a_34TVjJ5scwW27iw4vYCXzexzpmFwclN_tr_-mqgGNAtAYhyphenhyphenDxlUM3ZwPRYm49jWyogF6sMfPjuo5ljhAyPZVwfi855eGalBpQi_QI/s72-c/OOHelloWorldSilver.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-1902574876760669960</id><published>2015-11-05T02:17:00.000-08:00</published><updated>2015-11-06T05:24:42.699-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ceylon"/><category scheme="http://www.blogger.com/atom/ns#" term="JVM"/><title type='text'>Arrays and Indexers in Ceylon</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Ceylon 1.2 was finally released, you can see the announcement and the new stuff included on the new release here: &lt;a href=&quot;http://www.ceylon-lang.org/blog/2015/10/29/ceylon-1-2-0/&quot; target=&quot;_blank&quot;&gt;http://www.ceylon-lang.org/blog/2015/10/29/ceylon-1-2-0/&lt;/a&gt;. &amp;nbsp;This version looks really impressive doesn&#39;t it?. Anyway, I took advantage of this 1 year long await to finally come up, me too, with a new post, et voilà! today&#39;s post is about Arrays and Indexers in Ceylon.&lt;br /&gt;
&lt;br /&gt;
Ceylon does not have primitives, nor arrays, but you have sequences (read only arrays), generics Array&lt;type&gt; and Java&#39;s interop arrays. In this post i used Array&lt;type&gt; instead of CharArray, IntArray and ObjectType&lt;string&gt; interop arrays.&lt;/string&gt;&lt;/type&gt;&lt;/type&gt;&lt;br /&gt;
&lt;br /&gt;
For the Java interop arrays, you can get some documentation in these 2 pages:&lt;br /&gt;
&lt;a href=&quot;http://ceylon-lang.org/documentation/1.0/reference/interoperability/java-from-ceylon/#java_array_types_milestone_5&quot; target=&quot;_blank&quot;&gt;http://ceylon-lang.org/documentation/1.0/reference/interoperability/java-from-ceylon/#java_array_types_milestone_5&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://ceylon-lang.org/documentation/1.0/reference/interoperability/type-mapping/&quot; target=&quot;_blank&quot;&gt;http://ceylon-lang.org/documentation/1.0/reference/interoperability/type-mapping/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
There isn&#39;t either Indexers in Ceylon, as a built in feature of the language, however, you can implement some interfaces have a syntax sugar array[index], which behind the scenes is the usual array.get(index) method call. More info here:&lt;br /&gt;
&lt;a href=&quot;http://www.ceylon-lang.org/documentation/1.2/tour/sequences/&quot; target=&quot;_blank&quot;&gt;http://www.ceylon-lang.org/documentation/1.2/tour/sequences/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Ceylon, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my (not so) recent post (anymore), &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in Java just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;scala&quot; name=&quot;code&quot;&gt;//module.ceylon
native(&quot;jvm&quot;) module com.carlosqt.hello &quot;1.0.0&quot; {
 import java.base &quot;8&quot;;
 import ceylon.interop.java &quot;1.2.0&quot;;
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;scala&quot; name=&quot;code&quot;&gt;//run.ceylon
import java.lang {  
 Str=String { 
  format 
 }
 ,Int=Integer
 ,Chr=Character
 /*,CharArray
  ,IntArray */
}
/*import ceylon.interop.java {
 createJavaIntArray
}*/
import java.util {
 Random
}

&quot;Run the module `com.carlosqt.hello`.&quot;
shared void run() {
 // Single-dimensional Array(s)  
 printTitle(&quot;Reverse Array Elements&quot;);  
 
 // Declare and Initialize Array of Chars
 //value letters = CharArray(5); // Java interop
 value letters = Array&amp;lt;Character&amp;gt;.ofSize(5, &#39; &#39;);
 letters.set(0, &#39;A&#39;);  
 letters.set(1, &#39;E&#39;); 
 letters.set(2, &#39;I&#39;); 
 letters.set(3, &#39;O&#39;); 
 letters.set(4, &#39;U&#39;); 
  
 printArray(letters);
 Array&amp;lt;Character&amp;gt; inverse_letters = reverseChar(letters);  
 printArray(inverse_letters);
 
 printTitle(&quot;Sort Integer Array Elements&quot;);
 
 // Declare and Initialize Array of Integers
 //IntArray numbers = IntArray(10, 8, 3, 1, 5) 
 //value x = createJavaIntArray({10, 8, 3, 1, 5});
 
 value numbers = Array&amp;lt;Integer|String&amp;gt;({10, 8, 3, 1, 5});
 printArray(numbers);
 value ordered_numbers = bubbleSort(numbers);   
 printArray(ordered_numbers);  
 
 printTitle(&quot;Sort String Array Elements&quot;);
 
 // Declare and Initialize and Array of Strings
 value names = Array&amp;lt;String|Integer&amp;gt;({
  &quot;Damian&quot;,  
  &quot;Rogelio&quot;,  
  &quot;Carlos&quot;,  
  &quot;Luis&quot;,  
  &quot;Daniel&quot;}
 ); 
 
 printArray(names);  
 value ordered_names = bubbleSort(names);  
 printArray(ordered_names);  
 
 // Multi-dimensional Array (Matrix row,column)  
 
 printTitle(&quot;Transpose Matrix&quot;); 
 
 /* Matrix row=2,col=3 
  * A =  [6  4 24] 
  *      [1 -9  8] 
  */
 value matrix = Array&amp;lt;Array&amp;lt;Integer&amp;gt;&amp;gt;({
  Array&amp;lt;Integer&amp;gt;({6, 4, 24}),
  Array&amp;lt;Integer&amp;gt;({1, -9, 8})
 });
  
 printMatrix(matrix);
 value transposed_matrix = transposeMatrix(matrix);  
 printMatrix(transposed_matrix);
 
 // Jagged Array (Array-of-Arrays)  
 
 printTitle(&quot;Upper Case Random Array &amp;amp; Graph Number of Elements&quot;);
 
 /* 
    * Creating an array of string arrays using the String.Split method 
    * instead of initializing it manually as follows: 
    * 
    * value text = Array&amp;lt;Array&amp;lt;String&amp;gt;&amp;gt;({ 
    *      Array&amp;lt;Integer&amp;gt;({&quot;word1&quot;, &quot;word2&quot;, &quot;wordN&quot;}), 
    *      Array&amp;lt;Integer&amp;gt;({&quot;word1&quot;, &quot;word2&quot;, &quot;wordM&quot;}),
    *      ... 
    *      ) 
    * 
    * Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot; 
    * 
    */  
 value text = Array&amp;lt;Array&amp;lt;String&amp;gt;&amp;gt;({  
  Array&amp;lt;String&amp;gt;(&quot;Hoy es el día más hermoso de nuestra vida, querido Sancho;&quot;.split()),
  Array&amp;lt;String&amp;gt;(&quot;los obstáculos más grandes, nuestras propias indecisiones;&quot;.split()),
  Array&amp;lt;String&amp;gt;(&quot;nuestro enemigo más fuerte, miedo al poderoso y nosotros mismos;&quot;.split()),
  Array&amp;lt;String&amp;gt;(&quot;la cosa más fácil, equivocarnos;&quot;.split()),
  Array&amp;lt;String&amp;gt;(&quot;la más destructiva, la mentira y el egoísmo;&quot;.split()),
  Array&amp;lt;String&amp;gt;(&quot;la peor derrota, el desaliento;&quot;.split()),
  Array&amp;lt;String&amp;gt;(&quot;los defectos más peligrosos, la soberbia y el rencor;&quot;.split()),
  Array&amp;lt;String&amp;gt;(&quot;las sensaciones más gratas, la buena conciencia...&quot;.split())
 });  
 
 printJaggedArray(text);  
 upperCaseRandomArray(text);  
 printJaggedArray(text);  
 graphJaggedArray(text);  
 
 // Array Exceptions  
 
 printTitle(&quot;Common Array Exceptions&quot;);  
 
 //printCommonArrayExceptions(null) // Null-Safety  
 printCommonArrayExceptions(text);
 
 // Accessing Class Array Elements through Indexer  
 
 printTitle(&quot;Alphabets&quot;);  
 
 
 value vowels = Alphabet(5);  
 vowels.set(0, &#39;a&#39;);  
 vowels.set(1, &#39;e&#39;);  
 vowels.set(2, &#39;i&#39;);  
 vowels.set(3, &#39;o&#39;);  
 vowels.set(4, &#39;u&#39;);  
 
 print(&quot;\nVowels = {``&quot;,&quot;.join({vowels.get(0), vowels.get(1)
  , vowels.get(2), vowels.get(3), vowels.get(4)})``}&quot;);
   
 value en = Alphabet.initstr(&quot;abcdefghijklmnopqrstuvwxyz&quot;);  
 print(&quot;English Alphabet = {``en.string``}&quot;);  
 
 print(&quot;Alphabet Extract en[9..19] = {``Alphabet.initarr(en.slice(9, 10))``}&quot;);  
 
 value word1 = &quot;&quot;.join({en.get(6), en.get(14), en.get(14), en.get(3)});  
 value word2 = &quot;&quot;.join({en.get(1), en.get(24), en.get(4)});
 value word3 = &quot;&quot;.join({en.get(4), en.get(21), en.get(4), en.get(17),  
  en.get(24), en.get(14), en.get(13), en.get(4)});
 
 print(&quot;\n``word1`` ``word2``, ``word3``!&quot;);  
}

Array&amp;lt;Character&amp;gt; reverseChar(Array&amp;lt;Character&amp;gt; arr) {
 variable Integer i = !arr.empty then arr.size-1 else 0;  
 value reversed = Array&amp;lt;Character&amp;gt;.ofSize(arr.size, &#39; &#39;);
 for (j in 0..i) {  
  if(exists c = arr.get(j)) {
   reversed.set(i, c);
  }
  i--;
 }  
 return reversed;  
}  

Array&amp;lt;Integer|String&amp;gt; bubbleSort(Array&amp;lt;Integer|String&amp;gt; arr) {
 if(!arr.empty) {   
  variable Integer|String swap;
  for(i in arr.indexes()) {  
   for(j in 0..arr.size - 2) {
    if(exists l = arr.get(j), exists r = arr.get(j+1)) {
     if (is Integer l, is Integer r,  l &amp;gt; r) {
      swap = l;
      arr.set(j, r);
      arr.set(j+1, swap);
     } else if (is String l, is String r, l &amp;gt; r) {
      swap = l;
      arr.set(j, r);
      arr.set(j+1, swap);
     }
    }
   }
  }
 }
 return arr;
}

Array&amp;lt;Array&amp;lt;Integer&amp;gt;&amp;gt; transposeMatrix(Array&amp;lt;Array&amp;lt;Integer&amp;gt;&amp;gt; m) {  
 /* Transposing a Matrix 2,3 
  * 
  * A =  [6  4 24]T [ 6  1] 
  *      [1 -9  8]  [ 4 -9] 
  *                 [24  8] 
  */
 if(!m.empty, exists r = m.get(0), exists c = r.get(0)) { 
  value transposed = Array&amp;lt;Array&amp;lt;Integer&amp;gt;&amp;gt;.ofSize(r.size, Array&amp;lt;Integer&amp;gt;.ofSize(m.size, 0));
  for(i in r.indexes()) {
   transposed.set(i, Array&amp;lt;Integer&amp;gt;.ofSize(m.size, 0));
  }
  for(i in m.indexes()) {     
     for(j in r.indexes()) {     
      //transposed[j][i] = m[i][j];      
      if (exists a = m.get(i), exists v = a.get(j), 
       exists tr = transposed.get(j)) {
        tr.set(i, v);
    }
   }
  }
  return transposed;
 }
 else {
  return m;
 }
}  

void upperCaseRandomArray(Array&amp;lt;Array&amp;lt;String&amp;gt;&amp;gt; arr) { 
 value r = Random();
 value i = Integer(r.nextInt(arr.size));
 if(exists s = arr.get(i)) {
  for (j in s.indexes()) {  
   //arr[i][j] = arr[i][j].toUpperCase()
   if(exists m = s.get(j)) {
    s.set(j, m.uppercased);
   }
  }
 }
}

/**/
//void printArrayChar(CharArray|IntArray|StringArray arr) {
// Using Union Types to print all types of Array content
void printArray(Array&amp;lt;Character&amp;gt;|Array&amp;lt;Integer&amp;gt;|Array&amp;lt;String&amp;gt;|Array&amp;lt;Integer|String&amp;gt; arr) {
 String arrtype; 
 if(!arr.empty, exists t = arr.get(0)) { 
  arrtype = className(t); 
 } else { 
  arrtype = &quot;empty&quot;;
 } 
 print(&quot;\nPrint Array Content ``className(arr)``&amp;lt;``arrtype``&amp;gt;[``arr.size``]&quot;);
 
 for (i in 0..arr.size-1) {
  print(format(&quot; array [%2d] = %2s&quot;, Int(i), Str(arr.get(i)?.string)));
 }
}

void printMatrix(Array&amp;lt;Array&amp;lt;Integer&amp;gt;&amp;gt; m) {   
 if(!m.empty, exists r = m.get(0), exists c = r.get(0)) { 
  print(&quot;\nPrint Matrix Content ``className(m)``&amp;lt;``className(r)``&amp;lt;``className(c)``&amp;gt;&amp;gt;[``m.size``,``r.size``]&quot;);
 
  for(i in m.indexes()) {
   if (exists e = m.get(i)) {  
    for(j in e.indexes()) {      
     if (exists f = e.get(j)) {
      print(format(&quot; array [%2d,%2d] = %2d&quot;, Int(i), Int(j), Int(f)));
     }  
    }  
   }
  }  
 }   
}  

void graphJaggedArray(Array&amp;lt;Array&amp;lt;String&amp;gt;&amp;gt; arr) {  
    /* When using Arrays, we can use foreach-like instead of for-like loop: 
     * 
     * for (i in arr.indexes()) 
     *   for (j in arr.indexes()) 
     * 
    */  
    print(&quot;\nPrint Text Content ``className(arr)``&quot;);
    if(!arr.empty) {  
     variable Integer lineCount = 1;
     variable String line = &quot;&quot;;  
     for(s in arr) {  
         //print(format(&quot;Line%2s|&quot;, Int(lineCount)));
         line = &quot;Line ``lineCount``|&quot;;  
         for(w in s) {  
             //print(format(&quot;%3s&quot;, Chr(&#39;*&#39;)));
             line += &quot; * &quot;;
         }  
         //print(&quot; (``s.size``)&quot;);
         line += &quot; (``s.size``)&quot;;
         print(line);
         lineCount += 1;
  }  
 }
}  

void printJaggedArray(Array&amp;lt;Array&amp;lt;String&amp;gt;&amp;gt; arr) {  
    print(&quot;\nPrint Jagged Array Content ``className(arr)``&quot;);
    if(!arr.empty) { 
     //variable StringBuilder line;
     for(i in arr.indexes()) {  
         value line = StringBuilder();
         if(exists r = arr.get(i)) {  
          for(j in r.indexes()) {          
              if(exists s = r.get(j)) {      
               line.append(&quot; &quot;).append(s);
              }  
          }  
          if (line.string == line.string.uppercased) {  
              line.append(&quot; &amp;lt;-- [UPPERCASED]&quot;);
          }          
          print(line);
         }
     }
 }  
}  

void printCommonArrayExceptions(Array&amp;lt;Array&amp;lt;String&amp;gt;&amp;gt; arr) {  
 try {
  if(exists i = arr.get(0)) {  
   i.set(100, &quot;hola&quot;);
  }
 } catch(AssertionError e) {  
  print(&quot;\nException: \n``className(e)``\n``e.message``\n&quot;);  
 }  
}  

void printTitle(String message) {  
 print(&quot;&quot;);  
 print(&quot;=&quot;.repeat(54));  
 print(message);  
 print(&quot;=&quot;.repeat(54));  
}  

class Alphabet {
 // Array field
 shared Array&amp;lt;Character&amp;gt; letters; //= Array&amp;lt;Character&amp;gt;.ofSize(size, &#39; &#39;);

 // Constructors  
 // Only one default constructor
 shared new(Integer size) {
  this.letters = Array&amp;lt;Character&amp;gt;.ofSize(size, &#39; &#39;);  
 }   
 // and 2 more named constructors
 shared new initstr(String list) {
  this.letters = Array&amp;lt;Character&amp;gt;(list.uppercased); 
 }
 
 shared new initarr(Array&amp;lt;Character&amp;gt; arr) {
  this.letters = arr;
 }

 shared Integer size() 
  =&amp;gt; this.letters.size;
 
 // Overridden Method
 
 // No indexers, using methods instead.
 &quot;Gets the item at the specified index&quot;
 shared Character get(Integer index) {
  if(exists l = letters.get(index)) {
   return l;
  } else {
   return &#39; &#39;;
  }
 }
 
 &quot;Sets the item at the specified index&quot;
 shared void set(Integer index, Character element) {
  if(!letters.empty, exists l = letters.get(index)) {
   letters.set(index, element.uppercased);   
  }
 }
  
 // Overriden (refined)
 &quot;Java&#39;s toString&quot;
 shared actual String string 
  =&amp;gt; &quot;.&quot;.join(letters);
  
  // Method  
  &quot;Returns a subset of this alphabet&quot;
  shared Array&amp;lt;Character&amp;gt; slice(Integer start, Integer len) 
   //=&amp;gt; Array&amp;lt;Character&amp;gt;(letters.sublist(start, start+len-1));  
  =&amp;gt; letters[start..start+len-1];  
  
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_XmUu05xjf_jlxiCXf75phCJH5VHSJg4b3mZOJNlIVFqCYX0sUi9_t9Vn-NeWmxw5O6H_2qjtdiCQQRMnLrmOkDI_Z3IDjzDsaGEZaTpgNcpC5u9F2jorU9DWaRi1iJVT-Qs_7gYK9Wc/s1600/ceylon+arrays.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_XmUu05xjf_jlxiCXf75phCJH5VHSJg4b3mZOJNlIVFqCYX0sUi9_t9Vn-NeWmxw5O6H_2qjtdiCQQRMnLrmOkDI_Z3IDjzDsaGEZaTpgNcpC5u9F2jorU9DWaRi1iJVT-Qs_7gYK9Wc/s1600/ceylon+arrays.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days (or months haha).
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/1902574876760669960/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2015/11/arrays-and-indexers-in-ceylon.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/1902574876760669960'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/1902574876760669960'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2015/11/arrays-and-indexers-in-ceylon.html' title='Arrays and Indexers in Ceylon'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_XmUu05xjf_jlxiCXf75phCJH5VHSJg4b3mZOJNlIVFqCYX0sUi9_t9Vn-NeWmxw5O6H_2qjtdiCQQRMnLrmOkDI_Z3IDjzDsaGEZaTpgNcpC5u9F2jorU9DWaRi1iJVT-Qs_7gYK9Wc/s72-c/ceylon+arrays.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-229773106213182639</id><published>2014-12-23T01:11:00.002-08:00</published><updated>2014-12-23T01:11:37.225-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JVM"/><category scheme="http://www.blogger.com/atom/ns#" term="Kotlin"/><title type='text'>Arrays and Indexers in Kotlin</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in Kotlin. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Kotlin, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my (not so) recent post (anymore), &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in Java just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;scala&quot; name=&quot;code&quot;&gt;package kotlinarrays

import java.util.Random

fun main(args: Array&amp;lt;String&amp;gt;) {
    // Single-dimensional Array(s)
    printTitle(&quot;Reverse Array Elements&quot;)

    // Declare and Initialize Array of Chars
    //val letters = Array&amp;lt;Char&amp;gt;(5, {c -&amp;gt; &#39; &#39;})
    val letters = CharArray(5)
    letters[0] = &#39;A&#39;
    letters[1] = &#39;E&#39;
    letters[2] = &#39;I&#39;
    letters[3] = &#39;O&#39;
    letters[4] = &#39;U&#39;

    printArrayChar(letters)
    val inverse_letters = reverseChar(letters)
    printArrayChar(inverse_letters)

    printTitle(&quot;Sort Integer Array Elements&quot;)

    // Declare and Initialize Array of Integers
    val numbers: IntArray = intArray(10, 8, 3, 1, 5)
    printArrayInt(numbers)
    val ordered_numbers = bubbleSortInt(numbers)
    printArrayInt(ordered_numbers)

    printTitle(&quot;Sort String Array Elements&quot;)

    // Declare and Initialize and Array of Strings
    val names: Array&amp;lt;String&amp;gt; = array(
        &quot;Damian&quot;,
        &quot;Rogelio&quot;,
        &quot;Carlos&quot;,
        &quot;Luis&quot;,
        &quot;Daniel&quot;
    )
    printArrayString(names)
    val ordered_names: Array&amp;lt;String&amp;gt; = bubbleSortString(names)
    printArrayString(ordered_names)

    // Multi-dimensional Array (Matrix row,column)

    printTitle(&quot;Transpose Matrix&quot;)

    /* Matrix row=2,col=3
     * A =  [6  4 24]
     *      [1 -9  8]
    */
    val matrix = array(array(6, 4, 24),
                       array(1, -9, 8))
    printMatrix(matrix)
    val transposed_matrix = transposeMatrix(matrix)
    printMatrix(transposed_matrix)

    // Jagged Array (Array-of-Arrays)

    printTitle(&quot;Upper Case Random Array &amp;amp; Graph Number of Elements&quot;)

    /*
     * Creating an array of string arrays using the String.Split method
     * instead of initializing it manually as follows:
     *
     * val text:Array&amp;lt;Array&amp;lt;String&amp;gt;&amp;gt; = array(
     *      array( &quot;word1&quot;, &quot;word2&quot;, &quot;wordN&quot; ),
     *      array( &quot;word1&quot;, &quot;word2&quot;, &quot;wordM&quot; ),
     *      ...
     *      )
     *
     * Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot;
     *
     */
    val text: Array&amp;lt;Array&amp;lt;String&amp;gt;&amp;gt; = array(
    &quot;Hoy es el día más hermoso de nuestra vida, querido Sancho;&quot;.split(&quot; &quot;),
    &quot;los obstáculos más grandes, nuestras propias indecisiones;&quot;.split(&quot; &quot;),
    &quot;nuestro enemigo más fuerte, miedo al poderoso y nosotros mismos;&quot;.split(&quot; &quot;),
    &quot;la cosa más fácil, equivocarnos;&quot;.split(&quot; &quot;),
    &quot;la más destructiva, la mentira y el egoísmo;&quot;.split(&quot; &quot;),
    &quot;la peor derrota, el desaliento;&quot;.split(&quot; &quot;),
    &quot;los defectos más peligrosos, la soberbia y el rencor;&quot;.split(&quot; &quot;),
    &quot;las sensaciones más gratas, la buena conciencia...&quot;.split(&quot; &quot;)
    )

    printJaggedArray(text)
    upperCaseRandomArray(text)
    printJaggedArray(text)
    graphJaggedArray(text)

    // Array Exceptions

    printTitle(&quot;Common Array Exceptions&quot;)

    //printCommonArrayExceptions(null) // Null-Safety
    printCommonArrayExceptions(text)

    // Accessing Class Array Elements through Indexer

    printTitle(&quot;Alphabets&quot;)

    val vowels = Alphabet(5)
    vowels[0] = &#39;a&#39;
    vowels[1] = &#39;e&#39;
    vowels[2] = &#39;i&#39;
    vowels[3] = &#39;o&#39;
    vowels[4] = &#39;u&#39;

    println(&quot;\nVowels = {${charArray(vowels[0], vowels[1], vowels[2], vowels[3], vowels[4]).joinToString(&quot;,&quot;)}}&quot;)

    val en = Alphabet(0)
    en.init(&quot;abcdefghijklmnopqrstuvwxyz&quot;)
    println(&quot;English Alphabet = {${en.toString()}}&quot;)

    val en2 = Alphabet(0)
    en2.init(en.slice(9, 10))
    println(&quot;Alphabet Extract en[9..19] = {${en2}}&quot;)

    val word1 = charArray(en[6], en[14], en[14], en[3]).joinToString(&quot;&quot;)
    val word2 = charArray(en[1], en[24], en[4]).joinToString(&quot;&quot;)
    val word3 = charArray(en[4], en[21], en[4], en[17],
            en[24], en[14], en[13], en[4]).joinToString(&quot;&quot;)

    println(&quot;\n$word1 $word2, $word3!&quot;)
}

fun reverseChar(arr: CharArray): CharArray {
    val reversed = CharArray(arr.size())
    var i: Int = arr.size()-1
    for (j in 0..i) {
        reversed[i] = arr[j]
        i--
    }
    return reversed
}

fun bubbleSortInt(arr: IntArray): IntArray {
    var swap: Int
    for(i in arr.indices) {
        for(j in 0..arr.size() - 2) {
            if (arr[j] &amp;gt; arr[j + 1]) {
                swap = arr[j]
                arr[j] = arr[j + 1]
                arr[j + 1] = swap
            }
        }
    }
    return arr
}

fun bubbleSortString(arr: Array&amp;lt;String&amp;gt;): Array&amp;lt;String&amp;gt; {
    var swap: String
    for(i in arr.indices) {
        for(j in 0..arr.size() - 2) {
            if (arr[j][0] &amp;gt; arr[j + 1][0]) {
                swap = arr[j]
                arr[j] = arr[j + 1]
                arr[j + 1] = swap
            }
        }
    }
    return arr
}

fun transposeMatrix(m: Array&amp;lt;Array&amp;lt;Int&amp;gt;&amp;gt;): Array&amp;lt;Array&amp;lt;Int&amp;gt;&amp;gt; {
    /* Transposing a Matrix 2,3
     *
     * A =  [6  4 24]T [ 6  1]
     *      [1 -9  8]  [ 4 -9]
     *                 [24  8]
    */
    val transposed = Array(m[0].size(), {c -&amp;gt; Array(m.size(), {v -&amp;gt; 0})})
    for (i in m.indices) {
        for (j in m[0].indices) {
            transposed[j][i] = m[i][j]
        }
    }
    return transposed
}

fun upperCaseRandomArray(arr: Array&amp;lt;Array&amp;lt;String&amp;gt;&amp;gt;) {
    val r = Random()
    val i = r.nextInt(arr.size())
    for (j in arr[i].indices) {
        arr[i][j] = arr[i][j].toUpperCase()
    }
}

fun printArrayChar(arr: CharArray) {
    println(&quot;\nPrint Array Content ${arr.javaClass.getName()}[${arr.size()}]&quot;)

    for (i in arr.indices) {
        println(java.lang.String.format(&quot; array [%2d] = %2s&quot;, i, arr[i]))
    }
}

fun printArrayInt(arr: IntArray) {
    println(&quot;\nPrint Array Content ${arr.javaClass.getName()}[${arr.size()}]&quot;)

    for (i in arr.indices) {
        println(java.lang.String.format(&quot; array [%2d] = %2d&quot;, i, arr[i]))
    }
}

fun printArrayString(arr: Array&amp;lt;String&amp;gt;) {
    println(&quot;\nPrint Array Content ${arr.javaClass.getName()}[${arr.size()}]&quot;)

    for (i in arr.indices) {
        println(java.lang.String.format(&quot; array [%2d] = %2s&quot;, i, arr[i]))
    }
}

fun printMatrix(m: Array&amp;lt;Array&amp;lt;Int&amp;gt;&amp;gt;) {
    println(&quot;\nPrint Matrix Content ${m.javaClass.getName()}[${m.size()},${m[0].size()}]&quot;)

    for(i in m.indices) {
        for(j in m[0].indices) {
            println(java.lang.String.format(&quot; array [%2d,%2d] = %2d&quot;, i, j, m[i][j]))
        }
    }
}

fun graphJaggedArray(arr:Array&amp;lt;Array&amp;lt;String&amp;gt;&amp;gt;) {
    /* When using Arrays, we can use foreach instead of for:
     *
     * for (i in arr.indices)
     *   for (j in arr.indices)
     *
    */
    println(&quot;\nPrint Text Content ${arr.javaClass.getName()}&quot;)
    var lineCount = 1
    for(s in arr) {
        print(java.lang.String.format(&quot;Line%2s|&quot;, lineCount))
        for(w in s) {
            print(java.lang.String.format(&quot;%3s&quot;, &#39;*&#39;))
        }
        println(&quot; (${s.size()})&quot;)
        lineCount += 1
    }
}

fun printJaggedArray(arr: Array&amp;lt;Array&amp;lt;String&amp;gt;&amp;gt;) {
    println(&quot;\nPrint Jagged Array Content ${arr.javaClass.getName()}&quot;)
    var line: StringBuilder
    for(i in arr.indices) {
        line = StringBuilder {}
        for(j in arr[i].indices) {
            line.append(&#39; &#39;).append(arr[i][j])
        }
        if (line.toString() == line.toString().toUpperCase())
            line.append(&quot; &amp;lt;-- [UPPERCASED]&quot;)
        println(line)
    }
}

fun printCommonArrayExceptions(arr: Array&amp;lt;Array&amp;lt;String&amp;gt;&amp;gt;) {
    try {
        arr[100][100] = &quot;hola&quot;
    } catch(ex: ArrayIndexOutOfBoundsException) {
        println(&quot;\nException: \n${ex.javaClass.getName()}\n${ex.getMessage()}\n&quot;)
    } catch(ex: Exception) {
        println(&quot;\nException: \n${ex.javaClass.getName()}\n${ex.getMessage()}\n&quot;)
    }
}

fun printTitle(message: String) {
    println()
    println(&quot;=&quot;.repeat(54))
    println(message)
    println(&quot;=&quot;.repeat(54))
}


// Main Constructor and Array Field
class Alphabet (private val size: Int) {
    private var letters = CharArray(size)

    // Indexer Getter/Setter
    fun get(index: Int): Char = letters[index]
    fun set(index: Int, value: Char) {
        letters[index] = value.toString().toUpperCase().charAt(0)
    }

    //
    fun size() = letters.size()

    // Constructors
    // Classes in Kotlin can only have a single constructor.
    // Using methods instead.
    fun init(list: String) {
        letters = list.toUpperCase().toCharArray()
    }

    fun init(arr: CharArray) {
        letters = arr
    }

    // Overridden Method
    override fun toString(): String = letters.joinToString(&quot;.&quot;)

    // Method
    fun slice(start: Int, length: Int): CharArray {
        val result = CharArray(length)
        var i: Int = 0
        for(c in letters.slice(start..start+length-1)) {
            result[i++] = c
        }
        return result
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicEmTmfVX1QrocR8yTgNFvN2ZV3ooBpnAO0WZ7WrrYbIw-L2Jt41E3jCYU6P97y16CNQ-UxjhyHPYzty1ZkS3OPTR-zA5o7E1pL5H_btzZ-RT8S7ZhLMkCP6Yp5Ueq-cXqBrV0PfLSvsE/s1600/KotlinArrays.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicEmTmfVX1QrocR8yTgNFvN2ZV3ooBpnAO0WZ7WrrYbIw-L2Jt41E3jCYU6P97y16CNQ-UxjhyHPYzty1ZkS3OPTR-zA5o7E1pL5H_btzZ-RT8S7ZhLMkCP6Yp5Ueq-cXqBrV0PfLSvsE/s1600/KotlinArrays.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/229773106213182639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2014/12/arrays-and-indexers-in-kotlin_23.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/229773106213182639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/229773106213182639'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2014/12/arrays-and-indexers-in-kotlin_23.html' title='Arrays and Indexers in Kotlin'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicEmTmfVX1QrocR8yTgNFvN2ZV3ooBpnAO0WZ7WrrYbIw-L2Jt41E3jCYU6P97y16CNQ-UxjhyHPYzty1ZkS3OPTR-zA5o7E1pL5H_btzZ-RT8S7ZhLMkCP6Yp5Ueq-cXqBrV0PfLSvsE/s72-c/KotlinArrays.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-6449499255291322513</id><published>2014-12-22T03:20:00.000-08:00</published><updated>2014-12-22T03:20:00.233-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JVM"/><category scheme="http://www.blogger.com/atom/ns#" term="Scala"/><title type='text'>Arrays and Indexers in Scala</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in Scala. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Scala, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my (not so) recent post (anymore), &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in Java just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;scala&quot; name=&quot;code&quot;&gt;package scalaarrays

import scala.util.Random

object ScalaArrays {

  /* Took this brilliant idea ??? 
   * from odersky http://www.scala-lang.org/old/node/11113.html */
  def ??? : Nothing =
    throw new UnsupportedOperationException(&quot;not implemented&quot;)

  def main(args:Array[String]) {
    // Single-dimensional Array(s)
    printTitle(&quot;Reverse Array Elements&quot;);

    // Declare and Initialize Array of Chars
    val letters = new Array[Char](5)
    letters(0) = &#39;A&#39;
    letters(1) = &#39;E&#39;
    letters(2) = &#39;I&#39;
    letters(3) = &#39;O&#39;
    letters(4) = &#39;U&#39;

    printArrayChar(letters)
    val inverse_letters = reverseChar(letters)
    printArrayChar(inverse_letters)

    printTitle(&quot;Sort Integer Array Elements&quot;)

    // Declare and Initialize Array of Integers
    val numbers:Array[Int] = Array(10, 8, 3, 1, 5)
    printArrayInt(numbers)
    val ordered_numbers = bubbleSortInt(numbers)
    printArrayInt(ordered_numbers)

    printTitle(&quot;Sort String Array Elements&quot;)

    // Declare and Initialize and Array of Strings
    val names = Array(
      &quot;Damian&quot;,
      &quot;Rogelio&quot;,
      &quot;Carlos&quot;,
      &quot;Luis&quot;,
      &quot;Daniel&quot;
    )
    printArrayString(names)
    val ordered_names = bubbleSortString(names)
    printArrayString(ordered_names)

    // Multi-dimensional Array (Matrix row,column)

    printTitle(&quot;Transpose Matrix&quot;)

    /* Matrix row=2,col=3
     * A =  [6  4 24]
     *      [1 -9  8]
    */
    //val matrix2 = Array.ofDim[Int](2,3)
    val matrix = Array(Array(6, 4, 24),
      Array(1, -9, 8))

    printMatrix(matrix)
    val transposed_matrix = transposeMatrix(matrix)
    printMatrix(transposed_matrix)

    // Jagged Array (Array-of-Arrays)

    printTitle(&quot;Upper Case Random Array &amp;amp; Graph Number of Elements&quot;)

    /*
     * Creating an array of string arrays using the String.Split method
     * instead of initializing it manually as follows:
     *
     * val text:Array[Array[String]] = Array(
     *      Array( &quot;word1&quot;, &quot;word2&quot;, &quot;wordN&quot; ),
     *      Array( &quot;word1&quot;, &quot;word2&quot;, &quot;wordM&quot; ),
     *      ...
     *      )
     *
     * Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot;
     *
     */
    val text: Array[Array[String]] = Array(
      &quot;Hoy es el día más hermoso de nuestra vida, querido Sancho;&quot;.split(&quot; &quot;),
      &quot;los obstáculos más grandes, nuestras propias indecisiones;&quot;.split(&quot; &quot;),
      &quot;nuestro enemigo más fuerte, miedo al poderoso y nosotros mismos;&quot;.split(&quot; &quot;),
      &quot;la cosa más fácil, equivocarnos;&quot;.split(&quot; &quot;),
      &quot;la más destructiva, la mentira y el egoísmo;&quot;.split(&quot; &quot;),
      &quot;la peor derrota, el desaliento;&quot;.split(&quot; &quot;),
      &quot;los defectos más peligrosos, la soberbia y el rencor;&quot;.split(&quot; &quot;),
      &quot;las sensaciones más gratas, la buena conciencia...&quot;.split(&quot; &quot;)
    )

    printJaggedArray(text)
    upperCaseRandomArray(text)
    printJaggedArray(text)
    graphJaggedArray(text)

    // Array Exceptions

    printTitle(&quot;Common Array Exceptions&quot;)

    printCommonArrayExceptions(null)
    printCommonArrayExceptions(text)

    // Accessing Class Array Elements through Indexer

    printTitle(&quot;Alphabets&quot;)

    val vowels = new Alphabet(5)
    vowels(0) = &#39;a&#39;
    vowels(1) = &#39;e&#39;
    vowels(2) = &#39;i&#39;
    vowels(3) = &#39;o&#39;
    vowels(4) = &#39;u&#39;

    println(s&quot;\nVowels = {${Array(vowels(0), vowels(1), vowels(2), vowels(3), vowels(4)).mkString(&quot;,&quot;)}}&quot;)

    val en = new Alphabet(&quot;abcdefghijklmnopqrstuvwxyz&quot;)
    println(s&quot;English Alphabet = {${en.toString()}}&quot;)

    println(s&quot;Alphabet Extract en[9..19] = {${new Alphabet(en.slice(9, 10))}}&quot;)

    val word1 = Array(en(6), en(14), en(14), en(3)).mkString
    val word2 = Array(en(1), en(24), en(4)).mkString
    val word3 = Array(en(4), en(21), en(4), en(17),
      en(24), en(14), en(13), en(4)).mkString

    println(s&quot;\n$word1 $word2, $word3!&quot;)
  }

  def reverseChar(arr:Array[Char]): Array[Char] = arr.reverse

  def bubbleSortInt(arr:Array[Int]): Array[Int] = {
    var swap = 0
    for(i &amp;lt;- arr.length - 1 to 0 by -1) {
      for (j &amp;lt;- 0 to arr.length - 2) {
        if(arr(j) &amp;gt; arr(j + 1)) {
          swap = arr(j)
          arr(j) = arr(j + 1)
          arr(j + 1) = swap
        }
      }
    }
    arr
  }

  def bubbleSortString(arr:Array[String]): Array[String] = {
    var swap = &quot;&quot;
    for(i &amp;lt;- arr.length-1 to 0 by -1) {
      for (j &amp;lt;- 0 to arr.length - 2) {
        if(arr(j)(0) &amp;gt; arr(j + 1)(0)) {
          swap = arr(j)
          arr(j) = arr(j + 1)
          arr(j + 1) = swap
        }
      }
    }
    arr
  }

  def transposeMatrix(m:Array[Array[Int]]) = {
    /* Transposing a Matrix 2,3
     *
     * A =  [6  4 24]T [ 6  1]
     *      [1 -9  8]  [ 4 -9]
     *                 [24  8]
    */
    val transposed = Array.ofDim[Int](m(0).length, m.length)
    for (i &amp;lt;- 0 to m.length - 1)
      for (j &amp;lt;- 0 to m(0).length - 1)
        transposed(j)(i) = m(i)(j)
    transposed
  }

  def upperCaseRandomArray(arr:Array[Array[String]]) {
    val r = scala.util.Random
    val i = r.nextInt(arr.length)
    for (j &amp;lt;- 0 to arr(i).length - 1)
      arr(i)(j) = arr(i)(j).toUpperCase
  }

  def printArrayChar(arr:Array[Char]) {
    println(s&quot;\nPrint Array Content ${arr.getClass.getName}[${arr.length}]&quot;)

    for (i &amp;lt;- 0 to arr.length-1) {
      printf(&quot; array [%2d] = %2s\n&quot;, i, arr(i))
    }
  }

  def printArrayInt(arr:Array[Int]) {
    println(s&quot;\nPrint Array Content ${arr.getClass.getName}[${arr.length}]&quot;)

    for (i &amp;lt;- 0 to arr.length-1) {
      printf(&quot; array [%2d] = %2d\n&quot;, i, arr(i))
    }
  }

  def printArrayString(arr:Array[String]) {
    println(s&quot;\nPrint Array Content ${arr.getClass.getName}[${arr.length}]&quot;)

    for (i &amp;lt;- 0 to arr.length-1) {
      printf(&quot; array [%2d] = %2s\n&quot;, i, arr(i))
    }
  }

  def printMatrix(m:Array[Array[Int]]) {
    println(s&quot;\nPrint Matrix Content ${m.getClass.getName}[${m.length},${m(0).length}]&quot;)

    for(i &amp;lt;- 0 to m.length - 1)
      for(j &amp;lt;- 0 to m(0).length - 1)
        printf(&quot; array [%2d,%2d] = %2d\n&quot;, i, j, m(i)(j))
  }

  def graphJaggedArray(arr:Array[Array[String]]) {
    /* When using Arrays, we can use foreach instead of for:
     *
     * for (i &amp;lt;- 0 to arr.length - 1)
     *   for (j &amp;lt;- 0 to arr.length - 1)
     *
    */
    println(s&quot;\nPrint Text Content ${arr.getClass.getName}&quot;)
    var lineCount = 1
    for(s &amp;lt;- arr) {
      printf(&quot;Line%2s|&quot;, lineCount)
      for(w &amp;lt;- s) {
        printf(&quot;%3s&quot;, &#39;*&#39;)
      }
      printf(&quot; (%d)\n&quot;, s.length)
      lineCount += 1
    }
  }

  def printJaggedArray(arr:Array[Array[String]]) {
    println(s&quot;\nPrint Jagged Array Content ${arr.getClass.getName}&quot;)
    var line = new StringBuilder
    for(i &amp;lt;- 0 to arr.length - 1) {
      line = new StringBuilder
      for(j &amp;lt;- 0 to arr(i).length - 1)
        line += &#39; &#39; ++= arr(i)(j)
      if (line.toString == line.toString.toUpperCase)
        line ++= &quot; &amp;lt;-- [UPPERCASED]&quot;
      println(line)
    }
  }

  def printCommonArrayExceptions(arr:Array[Array[String]]) {
    try {
      arr(100)(100) = &quot;hola&quot;
    } catch {
      case ex: ArrayIndexOutOfBoundsException =&amp;gt;
        println(s&quot;\nException: \n${ex.getClass.getName}\n${ex.getMessage}\n&quot;)
      case ex: Exception =&amp;gt;
        println(s&quot;\nException: \n${ex.getClass.getName}\n${ex.getMessage}\n&quot;)
    }
  }

  def printTitle(message:String) {
    println
    println(&quot;=&quot; * 54)
    println(message)
    println(&quot;=&quot; * 54)
  }

}

// Main Constructor and Array Field
class Alphabet (private val letters:Array[Char]) {

  // Indexer Getter/Setter
  def apply(index:Int) = letters(index)
  def update(index:Int, value:Char) = letters(index) = value.toUpper

  // Getter
  def length() = letters.length

  // Constructors
  //def this(size:Int) = this(new Array[Char](size))
  def this(size:Int) = this(Array.ofDim[Char](size))
  def this(lst:String) = this(lst.toUpperCase.toCharArray)

  // Overridden Method
  override def toString:String = letters.mkString(&quot;,&quot;)

  // Method
  def slice(start:Int, len:Int) = letters.slice(start, start+len)
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6GRvTvLivt8ncurODyU-5_cPUNa9r7-g9kWfe6z38i3l4Ri0Qw87iKv1ZBN_TZApIIpSFm4VV8r2lJTIy56L-oLUA7yzgwx_fy30R8a8eJhhpYIVzV1P5O_X1Ry5FuT1_VoZVn_-8mXw/s1600/ScalaArrays.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6GRvTvLivt8ncurODyU-5_cPUNa9r7-g9kWfe6z38i3l4Ri0Qw87iKv1ZBN_TZApIIpSFm4VV8r2lJTIy56L-oLUA7yzgwx_fy30R8a8eJhhpYIVzV1P5O_X1Ry5FuT1_VoZVn_-8mXw/s1600/ScalaArrays.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/6449499255291322513/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2014/12/arrays-and-indexers-in-scala.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/6449499255291322513'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/6449499255291322513'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2014/12/arrays-and-indexers-in-scala.html' title='Arrays and Indexers in Scala'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6GRvTvLivt8ncurODyU-5_cPUNa9r7-g9kWfe6z38i3l4Ri0Qw87iKv1ZBN_TZApIIpSFm4VV8r2lJTIy56L-oLUA7yzgwx_fy30R8a8eJhhpYIVzV1P5O_X1Ry5FuT1_VoZVn_-8mXw/s72-c/ScalaArrays.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-6496150292306902</id><published>2014-12-07T15:05:00.001-08:00</published><updated>2014-12-22T03:26:25.872-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JVM"/><category scheme="http://www.blogger.com/atom/ns#" term="Xtend"/><title type='text'>Arrays and Indexers in Xtend</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in Xtend. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Xtend, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my (not so) recent post (anymore), &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in Java just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&quot;Xtend does not support Multidimensional Arrays out-of-the box. You can add support by declaring a Java class like this : &quot; by Sven Efftinge - Google Groups: Xtend Programming Language 
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;// ArrayLiterals2.java
package xtendarrays;

import org.eclipse.xtext.xbase.lib.Inline;

public class ArrayLiterals2 {
 @Inline(&quot;new int[$1][$2]&quot;)
 public static int[][] new2DIntArrayOfSize(int outerSize, int innerSize) {
  throw new UnsupportedOperationException();
 }
}
&lt;/pre&gt;
&lt;br /&gt;
&quot;@Inline tells the compiler to replace any calls to the annotated method with the to-be-inlined Java expression (the &#39;value&#39; template).
Note that the @Inlined is not stable API (flagged as @Beta) and will likely be removed once Xtend has support for more powerful method-macros.&quot; by Sven Efftinge - Google Groups: Xtend Programming Language 
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;// XtendArrays.xtend
package xtendarrays

import java.util.Random
import java.lang.StringBuffer
import static extension xtendarrays.ArrayLiterals2.*

class XtendArrays {
 def static void main(String[] args) {
  // Single-dimensional Array(s)  
        printTitle(&quot;Reverse Array Elements&quot;)
        
        // Declare and Initialize Array of Chars  
        val char[] letters = newCharArrayOfSize(5)
        letters.set(0, &#39;A&#39;)
        letters.set(1, &#39;E&#39;)
        letters.set(2, &#39;I&#39;)
        letters.set(3, &#39;O&#39;)
        letters.set(4, &#39;U&#39;)
        
        printArrayChar(letters)  
        val char[] inverse_letters = reverseChar(letters)  
        printArrayChar(inverse_letters)
        
        printTitle(&quot;Sort Integer Array Elements&quot;)  

        // Declare and Initialize Array of Integers   
        val int[] numbers = #[10, 8, 3, 1, 5]
        printArrayInt(numbers)
        val int[] ordered_numbers = bubbleSortInt(numbers)
        printArrayInt(ordered_numbers)

        printTitle(&quot;Sort String Array Elements&quot;)  

        // Declare and Initialize and Array of Strings  
        val String[] names = #[                       
                &quot;Damian&quot;,   
                &quot;Rogelio&quot;,  
                &quot;Carlos&quot;,   
                &quot;Luis&quot;,                       
                &quot;Daniel&quot;  
            ]
        printArrayString(names)
        val String[] ordered_names = bubbleSortString(names)
        printArrayString(ordered_names)

        // Multi-dimensional Array (Matrix row,column)  

        printTitle(&quot;Transpose Matrix&quot;)

        /* Matrix row=2,col=3 
         * A =  [6  4 24] 
         *      [1 -9  8] 
        */  
        val int[][] matrix = #[#[6, 4, 24],   
                               #[1, -9, 8]]  
        printMatrix(matrix)
        val int[][] transposed_matrix = transposeMatrix(matrix)  
        printMatrix(transposed_matrix)

        // Jagged Array (Array-of-Arrays)  

        printTitle(&quot;Upper Case Random Array &amp;amp; Graph Number of Elements&quot;)
        
        /*              
         * Creating an array of string arrays using the String.Split method 
         * instead of initializing it manually as follows: 
         *  
         * val text = #[  
         *      #[ &quot;word1&quot;, &quot;word2&quot;, &quot;wordN&quot; ],  
         *      #[ &quot;word1&quot;, &quot;word2&quot;, &quot;wordM&quot; ],  
         *      ... 
         *      ] 
         *  
         * Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot; 
         *  
         */  
        val String[][] text = #[   
        &quot;Hoy es el día más hermoso de nuestra vida, querido Sancho;&quot;.split(&#39; &#39;),  
        &quot;los obstáculos más grandes, nuestras propias indecisiones;&quot;.split(&#39; &#39;),  
        &quot;nuestro enemigo más fuerte, miedo al poderoso y nosotros mismos;&quot;.split(&#39; &#39;),  
        &quot;la cosa más fácil, equivocarnos;&quot;.split(&#39; &#39;),  
        &quot;la más destructiva, la mentira y el egoísmo;&quot;.split(&#39; &#39;),  
        &quot;la peor derrota, el desaliento;&quot;.split(&#39; &#39;),  
        &quot;los defectos más peligrosos, la soberbia y el rencor;&quot;.split(&#39; &#39;),  
        &quot;las sensaciones más gratas, la buena conciencia...&quot;.split(&#39; &#39;)   
        ]       
        printJaggedArray(text)
        upperCaseRandomArray(text)  
        printJaggedArray(text)
        graphJaggedArray(text)  

        // Array Exceptions  

        printTitle(&quot;Common Array Exceptions&quot;)  
        
        printCommonArrayExceptions(null)  
        printCommonArrayExceptions(text)  

        // Accessing Class Array Elements through Indexer  

        printTitle(&quot;Alphabets&quot;)
        
        val vowels = new Alphabet(5)
        vowels.set(0, &#39;a&#39;)  
        vowels.set(1, &#39;e&#39;)  
        vowels.set(2, &#39;i&#39;)  
        vowels.set(3, &#39;o&#39;)  
        vowels.set(4, &#39;u&#39;)
        
        println(String.format(&quot;\nVowels = {%s}&quot;,  #[vowels.get(0), 
         vowels.get(1), vowels.get(2), vowels.get(3), vowels.get(4)].join(&#39;,&#39;)))
         
        var en = new Alphabet(&quot;abcdefghijklmnopqrstuvwxyz&quot;)
        println(&#39;&#39;&#39;English Alphabet = «en.toString»&#39;&#39;&#39;) 
        
        println(&#39;&#39;&#39;Alphabet Extract en[9..19] = «new Alphabet(en.slice(9, 10))»&#39;&#39;&#39;)   
     
      var word1 = #[en.get(6), en.get(14), en.get(14), en.get(3)].join(&#39;&#39;)
      var word2 = #[en.get(1), en.get(24), en.get(4)].join(&#39;&#39;)
      var word3 = #[en.get(4), en.get(21), en.get(4), en.get(17), 
           en.get(24), en.get(14), en.get(13), en.get(4)].join(&#39;&#39;)
  
      println
      println(&#39;&#39;&#39;«word1» «word2», «word3»!&#39;&#39;&#39;)                      
 }
 
 def static char[] reverseChar(char[] arr) {  
        val char[] reversed = newCharArrayOfSize(arr.length)  
        for (var i = 0, var j = arr.length - 1; j &amp;gt;= 0; i++, j--) {
            reversed.set(i, arr.get(j))  
        }
        return reversed
    }  
    
    def static int[] bubbleSortInt(int[] arr) {  
        var int swap = 0  
        for (var i = arr.length - 1; i &amp;gt; 0; i--) {  
            for (var j = 0; j &amp;lt; i; j++) {  
                if (arr.get(j) &amp;gt; arr.get(j + 1)) {  
                    swap = arr.get(j)  
                    arr.set(j, arr.get(j + 1))
                    arr.set(j + 1, swap)
                }  
            }  
        }  
  return arr;  
    }  
    
    def static String[] bubbleSortString(String[] arr) {  
        var String swap = &quot;&quot;
        for (var i = arr.length - 1; i &amp;gt; 0; i--) {  
            for (var j = 0; j &amp;lt; i; j++) {                  
                if (arr.get(j).charAt(0) &amp;gt; arr.get(j + 1).charAt(0)) {  
                    swap = arr.get(j)  
                    arr.set(j, arr.get(j + 1))  
                    arr.set(j + 1, swap)
                }  
            }  
        }  
        return arr;  
    }
    
    def static int[][] transposeMatrix(int[][] m) {  
        /* Transposing a Matrix 2,3  
         *  
         * A =  [6  4 24]T [ 6  1]  
         *      [1 -9  8]  [ 4 -9] 
         *                 [24  8] 
        */  
        val int[][] transposed = new2DIntArrayOfSize(m.get(0).length, m.length)   
        for (var i = 0; i &amp;lt; m.length; i++) {  
            for (var j = 0; j &amp;lt; m.get(0).length; j++) {  
                transposed.get(j).set(i, m.get(i).get(j))  
            }  
        }  
        return transposed
    }    
    
    def static void upperCaseRandomArray(String[][] arr) {  
        val r = new Random
        var int i = r.nextInt(arr.length)
        for (var j = 0; j &amp;lt; arr.get(i).length; j++) {
            arr.get(i).set(j, arr.get(i).get(j).toUpperCase)
        }
    }
 
 def static printArrayChar(char[] arr) {
  println
  println(&#39;&#39;&#39;Print Array Content «arr.class.name» «arr.class.name.class.name»[«arr.length»]&#39;&#39;&#39;)
  
     for(var i = 0; i &amp;lt; arr.length; i++) {
      println(String::format(&quot; array [%2d] = %2s&quot;, i, arr.get(i)))
     }
 }
 
 def static printArrayInt(int[] arr) {
  println
  println(&#39;&#39;&#39;Print Array Content «arr.class.name» «arr.class.name.class.name»[«arr.length»]&#39;&#39;&#39;)
  
     for(var i = 0; i &amp;lt; arr.length; i++) {
      println(String::format(&quot; array [%2d] = %2s&quot;, i, arr.get(i)))
     }
 }
 
 def static printArrayString(String[] arr) {
  println
  println(&#39;&#39;&#39;Print Array Content «arr.class.name» «arr.class.name.class.name»[«arr.length»]&#39;&#39;&#39;)
  
     for(var i = 0; i &amp;lt; arr.length; i++) {
      println(String::format(&quot; array [%2d] = %2s&quot;, i, arr.get(i)))
     }
 }
 
 def static void printMatrix(int[][] m) {  
        println(String.format(&quot;\nPrint Matrix Content %s[%d,%d]\n&quot;,  
            m.class.name.class.name,
            m.length,  
            m.get(0).length))

        for (var i = 0; i &amp;lt; m.length; i++) { 
            for (var j = 0; j &amp;lt; m.get(0).length; j++) {
                println(String.format(&quot; array [%2d,%2d] = %2d&quot;, i, j, m.get(i).get(j)))
            }
        }    
 }
 
 def static void graphJaggedArray(String[][] arr) {  
        /* When using Arrays, we can use foreach instead of for:  
         *  
         * for (var i = 0; i &amp;lt; arr.length; i++) 
         *   for (var j = 0; j &amp;lt; arr.length; j++)                 
         *  
        */  
        println(&quot;\nPrint Text Content &quot; + arr.class.name.class.name)
        var lineCount = 1
        for(s : arr) {  
            print(String.format(&quot;Line%2s|&quot;, lineCount))
            for(w : s) {  
                print(String.format(&quot;%3s&quot;, &#39;*&#39;))
            }  
            print(String.format(&quot; (%d)\n&quot;, s.length))  
            lineCount++
        }  
    }  
    
    def static void printJaggedArray(String[][] arr) {  
        var StringBuffer line
        println(&quot;\nPrint Jagged Array Content &quot; + arr.class.name + 
         &quot; &quot; + arr.class.name.class.name + &quot;[]&quot;) 
        for (var i = 0; i &amp;lt; arr.length; i++)  {  
            line = new StringBuffer 
            for (var j = 0; j &amp;lt; arr.get(i).length; j++) {  
                line.append(&quot; &quot;).append(arr.get(i).get(j)) 
            }
            if (line.toString.equals(line.toString.toUpperCase)) {
                line.append(&quot; &amp;lt;-- [UPPERCASED]&quot;)
            }
            println(line)
        }  
    }  
    
    def static void printCommonArrayExceptions(String[][] arr) {  
        try {  
            arr.get(100).set(100, &quot;hola&quot;) 
        }  
        catch (NullPointerException ex) { 
         println(String.format(&quot;\nException: \n%s\n%s\n&quot;, 
                    ex.class.name, ex.message))
        }
        catch (ArrayIndexOutOfBoundsException ex) {  
            println(String.format(&quot;\nException: \n%s\n%s\n&quot;, 
                    ex.class.name, ex.message))  
        }  
    }  
 
    def static printTitle(String message) {
        println
        println(&quot;======================================================&quot;)
        println(message)
        println(&quot;======================================================&quot;)
    }
}


class Alphabet {
 // Array Field
    var char[] letters
    
    // Indexer Getter/Setter 
    def char get(int index) {
     return letters.get(index)
    }
    def void set(int index, char value) {
     this.letters.set(index, value.toString.toUpperCase.charAt(0))
    }
    
    // Getter
    def int length() {  
        return this.letters.length  
    }  
    
    // Constructors  
    new(int size) {  
        this.letters = newCharArrayOfSize(size)  
    }  

    new(String list) {  
        this.letters = list.toUpperCase.toCharArray
    }  

    new(char[] list) {  
        this.letters = list  
    }  
    
    // Overridden Method  
    override String toString() {  
        return this.letters.join(&quot;,&quot;)
    } 
    
    // Method  
    def char[] slice(int start, int length) {  
        val char[] result = newCharArrayOfSize(length)  
        for (var i = 0, var j = start; i &amp;lt; length; i++, j++) {  
            result.set(i, this.letters.get(j))  
        }  
        return result
    }  
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhciSmiXrKJIJX9Td4vHzvi6UIBZuuLnS68D4fWAEemRSSpPcMkvG4Qz1LUELfry0L5NbwCr9U-Bekm3_qAITILoRYEZO7ew2Rn7qEw7viV4WuwFEjUiOWpO8rjJwx0Z7szhzTxTT1PeJg/s1600/XtendArrays.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhciSmiXrKJIJX9Td4vHzvi6UIBZuuLnS68D4fWAEemRSSpPcMkvG4Qz1LUELfry0L5NbwCr9U-Bekm3_qAITILoRYEZO7ew2Rn7qEw7viV4WuwFEjUiOWpO8rjJwx0Z7szhzTxTT1PeJg/s1600/XtendArrays.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/6496150292306902/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2014/12/arrays-and-indexers-in-xtend.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/6496150292306902'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/6496150292306902'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2014/12/arrays-and-indexers-in-xtend.html' title='Arrays and Indexers in Xtend'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhciSmiXrKJIJX9Td4vHzvi6UIBZuuLnS68D4fWAEemRSSpPcMkvG4Qz1LUELfry0L5NbwCr9U-Bekm3_qAITILoRYEZO7ew2Rn7qEw7viV4WuwFEjUiOWpO8rjJwx0Z7szhzTxTT1PeJg/s72-c/XtendArrays.png" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-6339397029074763595</id><published>2014-12-05T08:58:00.000-08:00</published><updated>2014-12-05T08:58:03.251-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Fantom"/><category scheme="http://www.blogger.com/atom/ns#" term="JVM"/><title type='text'>Arrays and Indexers in Fantom</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in Fantom. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Fantom, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my (not so) recent post (anymore), &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in Java just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;javascript&quot; name=&quot;code&quot;&gt;using [java] fanx.interop::CharArray
using [java] fanx.interop::IntArray 

class FantomArrays
{
  static Void main()
  {
    // For char and int I&#39;m using primitive arrays (CharArray and IntArray)
    // and for String arrays and Multi-dimensional arrays I&#39;m using List (Type[])
    // reference: http://fantom.org/doc/docLang/JavaFFI
    // section Interop Summary and Arrays
    
    // Single-dimensional Array(s)
    printTitle(&quot;Reverse Array Elements&quot;)
    
    // Declare and Initialize Array of Chars
    letters := CharArray.make(5)
    letters[0] = &#39;A&#39;
    letters[1] = &#39;E&#39;
    letters[2] = &#39;I&#39;
    letters[3] = &#39;O&#39;
    letters[4] = &#39;U&#39;

    printArrayChar(letters)
    CharArray inverse_letters := reverseChar(letters)
    printArrayChar(inverse_letters)
    
    printTitle(&quot;Sort Integer Array Elements&quot;)
    
    // Declare and Initialize Array of Integers
    numbers := IntArray(5)
    numbers[0] = 10
    numbers[1] = 8
    numbers[2] = 3
    numbers[3] = 1
    numbers[4] = 5
    
    printArrayInt(numbers)
    IntArray ordered_numbers := bubbleSortInt(numbers)
    printArrayInt(ordered_numbers)
    
    printTitle(&quot;Sort String Array Elements&quot;) 

    // Declare and Initialize and Array of Strings  
    Str[] names := Str[                      
            &quot;Damian&quot;,   
            &quot;Rogelio&quot;,  
            &quot;Carlos&quot;,   
            &quot;Luis&quot;,                       
            &quot;Daniel&quot;  
          ] 
    printArrayString(names)
    Str[] ordered_names := bubbleSortString(names)  
    printArrayString(ordered_names)

    // Multi-dimensional Array (Matrix row,column)  

    printTitle(&quot;Transpose Matrix&quot;)

    /* Matrix row=2,col=3 
     * A =  [6  4 24] 
     *      [1 -9  8] 
    */  
    Int[][] matrix := [[6, 4, 24],   
                       [1, -9, 8]]  
    printMatrix(matrix)
    Int[][] transposed_matrix := transposeMatrix(matrix)  
    printMatrix(transposed_matrix)

    // Jagged Array (Array-of-Arrays)  

    printTitle(&quot;Upper Case Random Array &amp;amp; Graph Number of Elements&quot;)  
        
    /*              
     * Creating an array of string arrays using the String.Split method 
     * instead of initializing it manually as follows: 
     *  
     * Str[][] text := [  
     *      [ &quot;word1&quot;, &quot;word2&quot;, &quot;wordN&quot; ],  
     *      [ &quot;word1&quot;, &quot;word2&quot;, &quot;wordM&quot; ],  
     *      ... 
     *      ]
     *  
     * Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot; 
     *  
     */  
    Str[][] text := [   
    &quot;Hoy es el dia mas hermoso de nuestra vida, querido Sancho;&quot;.split,  
    &quot;los obstaculos mas grandes, nuestras propias indecisiones;&quot;.split,  
    &quot;nuestro enemigo mas fuerte, miedo al poderoso y nosotros mismos;&quot;.split,  
    &quot;la cosa mas facil, equivocarnos;&quot;.split,  
    &quot;la mas destructiva, la mentira y el egoismo;&quot;.split,  
    &quot;la peor derrota, el desaliento;&quot;.split,  
    &quot;los defectos mas peligrosos, la soberbia y el rencor;&quot;.split,  
    &quot;las sensaciones mas gratas, la buena conciencia...&quot;.split    
    ]  
    printJaggedArray(text)  
    upperCaseRandomArray(text)
    printJaggedArray(text)
    graphJaggedArray(text)  

    // Array Exceptions  

    printTitle(&quot;Common Array Exceptions&quot;)  
    
    printCommonArrayExceptions(null)  
    printCommonArrayExceptions(text)

    // Accessing Class Array Elements through Indexer  

    printTitle(&quot;Alphabets&quot;)

    vowels := Alphabet(5)  
    vowels.set(0, &#39;a&#39;)  
    vowels.set(1, &#39;e&#39;)  
    vowels.set(2, &#39;i&#39;)  
    vowels.set(3, &#39;o&#39;)  
    vowels.set(4, &#39;u&#39;) 
    
    l := [vowels.get(0).toChar, vowels.get(1).toChar, vowels.get(2).toChar, vowels.get(3).toChar, vowels.get(4).toChar].join(&quot;,&quot;)
    echo(&quot;\nVowels = {$l}&quot;)
    
    //en := Alphabet.make(...) &amp;lt;-- this should work...
    en := Alphabet.makeFromStr(&quot;abcdefghijklmnopqrstuvwxyz&quot;)
    echo(&quot;English Alphabet = {${en.toStr}}&quot;) 
    
    //extract := Alphabet.make(...) &amp;lt;-- this should work...
    extract := Alphabet.makeFromList(en.slice(9, 10))
    echo(&quot;Alphabet Extract en[9..19] = {$extract}&quot;)
    
    word1 := [en.get(6).toChar, en.get(14).toChar, en.get(14).toChar, en.get(3).toChar].join
    word2 := [en.get(1).toChar, en.get(24).toChar, en.get(4).toChar].join
    word3 := [en.get(4).toChar, en.get(21).toChar, en.get(4).toChar, en.get(17).toChar, en.get(24).toChar, en.get(14).toChar, en.get(13).toChar, en.get(4).toChar].join
    
    echo(&quot;\n$word1 $word2, $word3!&quot;)
  }
  
  static CharArray reverseChar(CharArray arr) 
  {
    // for List Int[] you use arr.reverse() 
    reversed := CharArray.make(arr.size)
    Int j := arr.size - 1
    for (i := 0; i &amp;lt; arr.size; ++i) {
        reversed[i] = arr[j]
        j--
    }
    return reversed
  }
  
  static IntArray bubbleSortInt(IntArray arr) 
  {  
    Int swap := 0
    for (Int i := arr.size - 1; i &amp;gt; 0; i--) 
    {  
      for (Int j := 0; j &amp;lt; i; j++) 
      {  
        if (arr[j] &amp;gt; arr[j + 1]) 
        {  
          swap = arr[j]  
          arr[j] = arr[j + 1]  
          arr[j + 1] = swap 
        }  
      }  
    }  
    return arr
  } 
  
  static Str[] bubbleSortString(Str[] arr) 
  {  
    Str swap := &quot;&quot;  
    for (Int i := arr.size - 1; i &amp;gt; 0; i--) {  
      for (Int j := 0; j &amp;lt; i; j++) {                  
        if (arr[j][0] &amp;gt; arr[j + 1][0]) {  
          swap = arr[j];  
          arr[j] = arr[j + 1];  
          arr[j + 1] = swap;  
        }  
      }  
    }  
    return arr  
  }  
  
  static Int[][] transposeMatrix(Int[][] m) 
  {  
    /* Transposing a Matrix 2,3  
     *  
     * A =  [6  4 24]T [ 6  1]  
     *      [1 -9  8]  [ 4 -9] 
     *                 [24  8] 
    */
    Int[][] transposed := [,]    

    for (Int i := 0; i &amp;lt; m[0].size; i++) 
    { 
      Int[] row := [,]
      for (Int j := 0; j &amp;lt; m.size; j++) 
      {        
        row.add(m[j][i])        
      }  
      transposed.add(row)
    }
    return transposed
  }  
  
  static Void upperCaseRandomArray(Str[][] arr) 
  {   
    Int i := Int.random(0..&amp;lt;arr.size)
    for (Int j := 0; j &amp;lt; arr[i].size; j++) 
    {
      arr[i][j] = arr[i][j].upper
    }
  }
  
  static Void printArrayChar(CharArray arr) 
  {
    echo(&quot;\nPrint Array Content ${arr.typeof.name} [${arr.size}]&quot;)
  
    for (i := 0; i &amp;lt; arr.size; i++)  
    {
      echo(&quot; array [${i.toStr.padl(2)}] = ${arr[i].toChar.padl(2)}&quot;)
    }
  }
  
  static Void printArrayInt(IntArray arr) 
  {
    echo(&quot;\nPrint Array Content ${arr.typeof.name} [${arr.size}]&quot;)
  
    for (i := 0; i &amp;lt; arr.size; i++)  
    {
      echo(&quot; array [${i.toStr.padl(2)}] = ${arr[i].toStr.padl(2)}&quot;)
    }
  }
  
  static Void printArrayString(Str[] arr) 
  {
    echo(&quot;\nPrint Array Content ${arr.typeof.name} ${arr[0].typeof.name}[${arr.size}]&quot;)
  
    for (i := 0; i &amp;lt; arr.size; i++)  
    {
      echo(&quot; array [${i.toStr.padl(2)}] = ${arr[i].padl(2)}&quot;)
    }
  }
  
  static Void printMatrix(Int[][] m) 
  {  
    echo(&quot;\nPrint Matrix Content ${m.typeof.name} ${m[0][0].typeof.name}[${m.size},${m[0].size}]&quot;)
  
    for (Int i := 0; i &amp;lt; m.size; i++) 
    { 
      for (Int j := 0; j &amp;lt; m[0].size; j++) 
      {
        echo(&quot; array [${i.toStr.padl(2, &#39; &#39;)},${j.toStr.padl(2, &#39; &#39;)}] = ${m[i][j].toStr.padl(2, &#39; &#39;)}&quot;)
      }
    }
  }  
  
  static Void graphJaggedArray(Str[][] arr) 
  { 
    echo(&quot;\nPrint Text Content ${arr.typeof.name} ${arr[0][0].typeof.name}[${arr.size}]&quot;)
    Int lineCount := 1  
    arr.each |Str[] s| 
    {  
      Env.cur.out.print(&quot;Line${lineCount.toStr.padl(2)}|&quot;)  
      s.each |Str w| 
      {  
        Env.cur.out.print(&quot; * &quot;)  
      }  
      echo(&quot; (${s.size})&quot;)
      lineCount++  
    }      
  }
  
  static Void printJaggedArray(Str[][] arr) 
  {  
    echo(&quot;\nPrint Jagged Array Content ${arr.typeof.name} ${arr[0][0].typeof.name}[${arr.size}]&quot;)
    for (Int i := 0; i &amp;lt; arr.size; i++)  
    {  
      line := StrBuf()
      for (Int j := 0; j &amp;lt; arr[i].size; j++) 
      {  
          line.add(&quot; &quot;).add(arr[i][j])  
      }
      if (line.toStr == line.toStr.upper) 
      {
        line.add(&quot; &amp;lt;-- [UPPERCASED]&quot;)
      }
      echo(line)  
    }  
  }  
  
  static Void printCommonArrayExceptions(Str?[]?[]? arr) 
  {  
    try 
    {  
        arr[100][100] = &quot;hola&quot;        
    }  
    catch (NullErr ex) 
    {  
      echo(&quot;\nException: \n${ex.typeof.name}\n$ex&quot;) 
    } 
    catch (IndexErr ex) 
    {  
      echo(&quot;\nException: \n${ex.typeof.name}\n$ex&quot;) 
    } 
    catch (Err ex)
    {  
      echo(&quot;\nException: \n${ex.typeof.name}\n$ex&quot;) 
    } 
  }  
  
  static Void printTitle(Str message) 
  {
    echo()
    echo(&quot;&quot;.padr(54, &#39;=&#39;))
    echo(message)
    echo(&quot;&quot;.padr(54, &#39;=&#39;))
  }
}

class Alphabet
{
  // Array Field
  Int[] letters := [,]
  
  // Indexer Getter/Setter 
  Int get(Int index) 
  {
    return letters[index]
  }
  
  Void set(Int index, Int value) 
  {
    letters[index] = value.upper
  }
  
  // Constructors
  new make(Int size) 
  {  
    letters.fill(0, size)
  }  

  new makeFromStr(Str list) 
  {  
    letters = list.upper.chars
  }  

  new makeFromList(Int[] list) 
  {  
    letters = list
  }  
  
  // Overriden Method
  override Str toStr()
  {
    Str[] characters := [,]
    this.letters.each |Int c| { characters.add(c.toChar) }
    return characters.join(&quot;,&quot;)
  }
  
  // Method
  Int[] slice(Int start, Int length)
  {
    return letters.getRange(start..&amp;lt;start+length)
  }
  
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8CWUblX8vglnvvhlftzfZVM7nLxWIci-KO8orYZ_CUUeSIzgTnBqSnzF1UH1mzwA9Z-i9J5ellTHAekHykwWNsNXmYGRHyL61XNaoUSY0jOuVnZVwhneD8QoKCJhK2751vYYtnFFRLx0/s1600/FantomArrays.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8CWUblX8vglnvvhlftzfZVM7nLxWIci-KO8orYZ_CUUeSIzgTnBqSnzF1UH1mzwA9Z-i9J5ellTHAekHykwWNsNXmYGRHyL61XNaoUSY0jOuVnZVwhneD8QoKCJhK2751vYYtnFFRLx0/s1600/FantomArrays.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/6339397029074763595/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2014/12/arrays-and-indexers-in-fantom.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/6339397029074763595'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/6339397029074763595'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2014/12/arrays-and-indexers-in-fantom.html' title='Arrays and Indexers in Fantom'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8CWUblX8vglnvvhlftzfZVM7nLxWIci-KO8orYZ_CUUeSIzgTnBqSnzF1UH1mzwA9Z-i9J5ellTHAekHykwWNsNXmYGRHyL61XNaoUSY0jOuVnZVwhneD8QoKCJhK2751vYYtnFFRLx0/s72-c/FantomArrays.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-5603027541423340367</id><published>2014-12-04T00:42:00.002-08:00</published><updated>2014-12-04T00:42:46.647-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Gosu"/><category scheme="http://www.blogger.com/atom/ns#" term="JVM"/><title type='text'>Arrays and Indexers in Gosu</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in Gosu. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Gosu, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my (not so) recent post (anymore), &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in Java just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;javascript&quot; name=&quot;code&quot;&gt;package gosuarrays
uses java.lang.Character
uses java.lang.Integer
uses java.util.Random
uses java.lang.System
uses java.lang.StringBuffer
uses java.lang.Exception
uses java.util.Arrays

// Single-dimensional Array(s)
printTitle(&quot;Reverse Array Elements&quot;)

// Declare and Initialize Array of Chars
var letters = new Character[5]
letters[0] = &#39;A&#39;
letters[1] = &#39;E&#39;
letters[2] = &#39;I&#39;
letters[3] = &#39;O&#39;
letters[4] = &#39;U&#39;

printArrayChar(letters)
var inverse_letters = reverseChar(letters)
printArrayChar(inverse_letters)

printTitle(&quot;Sort Integer Array Elements&quot;)

// Declare and Initialize Array of Integers
var numbers: Integer[] = {10, 8, 3, 1, 5}
printArrayInt(numbers)

var ordered_numbers = bubbleSortInt(numbers)
printArrayInt(ordered_numbers)

printTitle(&quot;Sort String Array Elements&quot;);

// Declare and Initialize and Array of Strings
var names = new String[] {
    &quot;Damian&quot;,
    &quot;Rogelio&quot;,
    &quot;Carlos&quot;,
    &quot;Luis&quot;,
    &quot;Daniel&quot;
}
printArrayString(names)
var ordered_names = bubbleSortString(names)
printArrayString(ordered_names)

// Multi-dimensional Array (Matrix row,column)

printTitle(&quot;Transpose Matrix&quot;)

/* Matrix row=2,col=3
         * A =  [6  4 24]
         *      [1 -9  8]
        */
var matrix: Integer[][] = {{ 6, 4, 24 },
                           { 1, -9, 8 }}
printMatrix(matrix)
var transposed_matrix = transposeMatrix(matrix)
printMatrix(transposed_matrix)

// Jagged Array (Array-of-Arrays)

printTitle(&quot;Upper Case Random Array &amp;amp; Graph Number of Elements&quot;)

/*
 * Creating an array of string arrays using the String.Split method
 * instead of initializing it manually as follows:
 *
 * var text: String[][] = {
 *      { &quot;word1&quot;, &quot;word2&quot;, &quot;wordN&quot; },
 *      { &quot;word1&quot;, &quot;word2&quot;, &quot;wordM&quot; },
 *      ...
 *      }
 *
 * Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot;
 *
 */
var text: String[][] = {
    &quot;Hoy es el dÃ­a mÃ¡s hermoso de nuestra vida, querido Sancho;&quot;.split(&quot; &quot;),
    &quot;los obstÃ¡culos mÃ¡s grandes, nuestras propias indecisiones;&quot;.split(&quot; &quot;),
    &quot;nuestro enemigo mÃ¡s fuerte, miedo al poderoso y nosotros mismos;&quot;.split(&quot; &quot;),
    &quot;la cosa mÃ¡s fÃ¡cil, equivocarnos;&quot;.split(&quot; &quot;),
    &quot;la mÃ¡s destructiva, la mentira y el egoÃ­smo;&quot;.split(&quot; &quot;),
    &quot;la peor derrota, el desaliento;&quot;.split(&quot; &quot;),
    &quot;los defectos mÃ¡s peligrosos, la soberbia y el rencor;&quot;.split(&quot; &quot;),
    &quot;las sensaciones mÃ¡s gratas, la buena conciencia...&quot;.split(&quot; &quot;)
    }
printJaggedArray(text)
upperCaseRandomArray(text)
printJaggedArray(text)
graphJaggedArray(text)

// Array Exceptions

printTitle(&quot;Common Array Exceptions&quot;)

printCommonArrayExceptions(null)
printCommonArrayExceptions(text)

// Accessing Class Array Elements through Indexer

printTitle(&quot;Alphabets&quot;)

var vowels = new Alphabet(5)
vowels.setAt(0, &#39;a&#39;)
vowels.setAt(1, &#39;e&#39;)
vowels.setAt(2, &#39;i&#39;)
vowels.setAt(3, &#39;o&#39;)
vowels.setAt(4, &#39;u&#39;)

print(&quot;\nVowels = {${{vowels.getAt(0), vowels.getAt(1), vowels.getAt(2), vowels.getAt(3), vowels.getAt(4)}.join(&quot;,&quot;)}}&quot;)

var en = new Alphabet(&quot;abcdefghijklmnopqrstuvwxyz&quot;)
print(&quot;English Alphabet = {${en.toString()}}&quot;)

print(&quot;Alphabet Extract en[9..19] = {${new Alphabet(en.slice(9, 10))}}&quot;)

var word1 = {en.getAt(6), en.getAt(14), en.getAt(14), en.getAt(3)}.toTypedArray().join(&quot;&quot;)
var word2 = {en.getAt(1), en.getAt(24), en.getAt(4)}.toTypedArray().join(&quot;&quot;)
var word3 = {en.getAt(4), en.getAt(21), en.getAt(4), en.getAt(17),
             en.getAt(24), en.getAt(14), en.getAt(13), en.getAt(4)}.toTypedArray().join(&quot;&quot;)

print(&quot;\n${word1} ${word2}, ${word3}!&quot;)


function reverseChar(arr: Character[]): Character[] {
  var reversed = new Character[arr.length]
  for (c in arr index i) {
    reversed[i] = c
  }
  return reversed
}

function bubbleSortInt(arr: Integer[]): Integer[] {
  var swap: int = 0
  for (i in arr.length|..0) {
    for (j in 0..|i) {
      if (arr[j] &amp;gt; arr[j + 1]) {
        swap = arr[j]
        arr[j] = arr[j + 1]
        arr[j + 1] = swap
      }
    }
  }
  return arr
}

function bubbleSortString(arr: String[]): String[] {
  var swap = &quot;&quot;
  for (i in arr.length|..0) {
    for (j in 0..|i) {
      if (arr[j][0] &amp;gt; arr[j + 1][0]) {
        swap = arr[j]
        arr[j] = arr[j + 1]
        arr[j + 1] = swap
      }
    }
  }
  return arr
}

function transposeMatrix(m: Integer[][]): Integer[][] {
  /* Transposing a Matrix 2,3
   *
   * A =  [6  4 24]T [ 6  1]
   *      [1 -9  8]  [ 4 -9]
   *                 [24  8]
  */
  var transposed = new Integer[m[0].length][m.length]
  for (i in 0..|m.length) {
    for (j in 0..|m[0].length) {
      transposed[j][i] = m[i][j]
    }
  }
  return transposed
}

function upperCaseRandomArray(arr: String[][]) {
  var r = new Random()
  var i = r.nextInt(arr.length)
  for (j in 0..|arr[i].length) {
    arr[i][j] = arr[i][j].toUpperCase()
  }
}

function printArrayChar(arr: Character[]) {
  print(&quot;\nPrint Array Content ${arr.Class.Name} [${arr.length}]&quot;)

  for (i in 0..|arr.length) {
    print(&quot; array [${String.valueOf(i).leftPad(2)}] = ${String.valueOf(arr[i]).leftPad(2)}&quot;)
  }
}

function printArrayInt(arr: Integer[]) {
  print(&quot;\nPrint Array Content ${arr.Class.Name} [${arr.length}]&quot;)

  for (i in 0..|arr.length) {
    print(&quot; array [${String.valueOf(i).leftPad(2)}] = ${String.valueOf(arr[i]).leftPad(2)}&quot;)
  }
}

function printArrayString(arr: String[]) {
  print(&quot;\nPrint Array Content ${arr.Class.Name} [${arr.length}]&quot;)

  for (i in 0..|arr.length) {
    print(&quot; array [${String.valueOf(i).leftPad(2)}] = ${arr[i].leftPad(2)}&quot;)
  }
}

function printMatrix(m: Integer[][]) {
  print(&quot;\nPrint Matrix Content ${m.Class.Name}[${m.length},${m[0].length}]&quot;)

  for (i in 0..|m.length) {
    for (j in 0..|m[0].length) {
      print(&quot; array [${String.valueOf(i).leftPad(2)},${String.valueOf(i).leftPad(2)}] = ${m[i][j].toString().leftPad(2)}&quot;)
    }
  }
}

function graphJaggedArray(arr: String[][]) {
  /* When using Arrays, we can use foreach instead of for:
   *
   * for (i in 0..|arr.length)
   *   for (j in 0..|arr.length)
   *
  */
  print(&quot;\nPrint Text Content &quot; + arr.Class.Name)
  var lineCount = 1
  for(s in arr) {
    System.out.print(&quot;Line${String.valueOf(lineCount).leftPad(2)}|&quot;)
    for(w in s) {
      System.out.print(&quot;*&quot;.leftPad(3))
    }
    print(&quot; (${s.length})&quot;)
    lineCount++
  }
}

function printJaggedArray(arr: String[][]) {
  var line: StringBuffer
  print(&quot;\nPrint Jagged Array Content &quot; + arr.Class.Name)
  for (i in 0..|arr.length) {
    line = new StringBuffer()
    for (j in 0..|arr[i].length) {
      line.append(&quot; &quot;).append(arr[i][j])
    }
    if (line.toString() == line.toString().toUpperCase()) {
      line.append(&quot; &amp;lt;-- [UPPERCASED]&quot;)
    }
    print(line)
  }
}

function printCommonArrayExceptions(arr: String[][]) {
  try {
    arr[100][100] = &quot;hola&quot;
  }
  catch (ex: Exception) {
    print(&quot;\nException: \n${ex.Class.Name}\n${ex.Message}&quot;)
  }
}

function printTitle(message: String) {
  print(&quot;&quot;)
  print(&quot;=&quot;.repeat(54))
  print(message)
  print(&quot;=&quot;.repeat(54))
}

class Alphabet {
  // Array Field
  var _letters: Character[]

  // Indexer Getter/Setter
  // cannot use property get because no parameter allowed for index
  // cannot use property set because only 1 parameter allowed (can use Map&amp;lt;int,char&amp;gt;)
  // property get getAt(index:int): Character { return letters[index] }
  // property set setAt(value: Map&amp;lt;int, Character&amp;gt;) { letters[value[0]] = value[1]
  function getAt(index: int): Character {
    return _letters[index]
  }
  function setAt(index: int, value: Character) {
    _letters[index] = String.valueOf(value).toUpperCase().charAt(0)
  }

  // Getter
  function getLength(): int {
    return _letters.length
  }

  // Constructors
  construct(size: int) {
    _letters = new Character[size]
  }

  construct(list: String) {
    _letters = list.toUpperCase().toCharArray().toList().toTypedArray()
  }

  construct(list: Character[]) {
    _letters = list
  }

  // Overridden Method
  override function toString(): String {
    return _letters.join(&quot;,&quot;)
  }

  // Method
  function slice(start: int, length: int): Character[] {
    return _letters.toList().subList(start, start+length).toTypedArray()
  }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvfbl8lAnPAhv6dTw5oOW-KOStdY_lMkOTXDxpMWE3Ple9Ap2RysBYUQnBs0eAOMwxUSVFaAOQc8-L4_scsovL_zBQ0HRzNf9BETmFHurZxGdniZciP4tLfJibzanNW8YKCxUSy7jYqSk/s1600/GosuArrays.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvfbl8lAnPAhv6dTw5oOW-KOStdY_lMkOTXDxpMWE3Ple9Ap2RysBYUQnBs0eAOMwxUSVFaAOQc8-L4_scsovL_zBQ0HRzNf9BETmFHurZxGdniZciP4tLfJibzanNW8YKCxUSy7jYqSk/s1600/GosuArrays.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/5603027541423340367/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2014/12/arrays-and-indexers-in-gosu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/5603027541423340367'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/5603027541423340367'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2014/12/arrays-and-indexers-in-gosu.html' title='Arrays and Indexers in Gosu'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvfbl8lAnPAhv6dTw5oOW-KOStdY_lMkOTXDxpMWE3Ple9Ap2RysBYUQnBs0eAOMwxUSVFaAOQc8-L4_scsovL_zBQ0HRzNf9BETmFHurZxGdniZciP4tLfJibzanNW8YKCxUSy7jYqSk/s72-c/GosuArrays.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-8295782085038593480</id><published>2014-12-02T04:59:00.001-08:00</published><updated>2014-12-22T05:34:39.990-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Groovy"/><category scheme="http://www.blogger.com/atom/ns#" term="JVM"/><title type='text'>Arrays and Indexers in Groovy</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in Groovy. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Groovy, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my (not so) recent post (anymore), &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in Java just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;groovy&quot; name=&quot;code&quot;&gt;package groovyarrays

// Single-dimensional Array(s)  
printTitle(&quot;Reverse Array Elements&quot;)  

// Declare and Initialize Array of Chars  
def letters = new char[5] 
letters[0] = &#39;A&#39;  
letters[1] = &#39;E&#39;  
letters[2] = &#39;I&#39;  
letters[3] = &#39;O&#39;  
letters[4] = &#39;U&#39;  

printArray letters
def inverse_letters = reverseChar letters
printArray inverse_letters

printTitle &quot;Sort Integer Array Elements&quot;

// Declare and Initialize Array of Integers
def numbers = [ 10, 8, 3, 1, 5 ].toArray()
printArray numbers
def ordered_numbers = bubbleSort numbers
printArray ordered_numbers

printTitle &quot;Sort String Array Elements&quot;

// Declare and Initialize and Array of Strings
def names = [                       
    &quot;Damian&quot;,   
    &quot;Rogelio&quot;,  
    &quot;Carlos&quot;,   
    &quot;Luis&quot;,                       
    &quot;Daniel&quot;
    ].toArray()
printArray names
def ordered_names = bubbleSort names  
printArray ordered_names 

// Multi-dimensional Array (Matrix row,column)  

printTitle &quot;Transpose Matrix&quot;  

/* Matrix row=2,col=3 
 * A =  [6  4 24] 
 *      [1 -9  8] 
*/  
def matrix = [[6, 4, 24] as int[],
              [1, -9, 8] as int[]] as int[][]

printMatrix matrix
def transposed_matrix = transposeMatrix matrix
printMatrix transposed_matrix

// Jagged Array (Array-of-Arrays)

printTitle &quot;Upper Case Random Array &amp;amp; Graph Number of Elements&quot;

/*              
 * Creating an array of string arrays using the String.Split method 
 * instead of initializing it manually as follows: 
 *  
 * def text1 = [ 
 *      [ &quot;word1&quot;, &quot;word2&quot;, &quot;wordN&quot; ].toArray() as String[],   
 *      [ &quot;word1&quot;, &quot;word2&quot;, &quot;wordM&quot; ].toArray() as String[]  
 *      ... 
 *      ].toArray() as String[]
 *  
 * Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot; 
 *  
 */  
def text = [   
&quot;Hoy es el dÃ­a mÃ¡s hermoso de nuestra vida, querido Sancho;&quot;.split(&quot; &quot;),  
&quot;los obstÃ¡culos mÃ¡s grandes, nuestras propias indecisiones;&quot;.split(&quot; &quot;),  
&quot;nuestro enemigo mÃ¡s fuerte, miedo al poderoso y nosotros mismos;&quot;.split(&quot; &quot;),  
&quot;la cosa mÃ¡s fÃ¡cil, equivocarnos;&quot;.split(&quot; &quot;),  
&quot;la mÃ¡s destructiva, la mentira y el egoÃ­smo;&quot;.split(&quot; &quot;),  
&quot;la peor derrota, el desaliento;&quot;.split(&quot; &quot;),  
&quot;los defectos mÃ¡s peligrosos, la soberbia y el rencor;&quot;.split(&quot; &quot;),  
&quot;las sensaciones mÃ¡s gratas, la buena conciencia...&quot;.split(&quot; &quot;)   
].toArray()

printJaggedArray text  
upperCaseRandomArray text  
printJaggedArray text
graphJaggedArray text  

// Array Exceptions  

printTitle &quot;Common Array Exceptions&quot;

printCommonArrayExceptions null
printCommonArrayExceptions text  

// Accessing Class Array Elements through Indexer  

printTitle &quot;Alphabets&quot;

def vowels = new Alphabet(5)  
vowels[0] = &#39;a&#39;  
vowels[1] = &#39;e&#39;  
vowels[2] = &#39;i&#39;  
vowels[3] = &#39;o&#39;  
vowels[4] = &#39;u&#39;  
        
println &quot;\nVowels = {${[vowels[0], vowels[1], vowels[2], vowels[3], vowels[4]].join(&quot;,&quot;)}}&quot;                   

def en = new Alphabet(&quot;abcdefghijklmnopqrstuvwxyz&quot;) 
println &quot;English Alphabet = {${en.toString()}}&quot; 

println &quot;Alphabet Extract en[9..19] = {${new Alphabet(en.slice(9, 10))}}&quot;

word1 = [en[6], en[14], en[14], en[3]].toArray().join(&#39;&#39;)
word2 = [en[1], en[24], en[4]].toArray().join(&#39;&#39;)
word3 = [en[4], en[21], en[4], en[17], 
         en[24], en[14], en[13], en[4]].toArray().join(&#39;&#39;)

println &quot;\n$word1 $word2, $word3!&quot;  


def reverseChar(arr) {
    arr.toList().reverse().toArray() as char[]
    /* // or...
    def reversed = new char[arr.length]
    j = arr.length-1
    for (i in 0..&amp;lt;arr.length) {
        reversed[i] = arr[j]
        j--
    }
    reversed
    */
}

def bubbleSort(arr) {
    swap = 0
    for (int i = arr.length - 1; i &amp;gt; 0; i--)
        for (int j = 0; j &amp;lt; i; j++)
            if (arr[j] &amp;gt; arr[j + 1]) {
                swap = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = swap;
            }
    arr
}

def transposeMatrix(m) {
    /* Transposing a Matrix 2,3
     *
     * A =  [6  4 24]T [ 6  1]
     *      [1 -9  8]  [ 4 -9]
     *                 [24  8]
    */
    def transposed = new int[m[0].length][m.length]
    for (i in 0..&amp;lt;m.length)
        for (j in 0..&amp;lt;m[0].length)
            transposed[j][i] = m[i][j]   
    transposed
}

def upperCaseRandomArray(arr) {  
    def r = new Random() 
    int i = r.nextInt arr.length 
    for (j in 0..&amp;lt;arr[i].length) 
        arr[i][j] = arr[i][j].toUpperCase()
}

def printArray(arr) {
    println &quot;\nPrint Array Content ${arr.getClass().getName()}[$arr.length]&quot;
    for (i in 0..&amp;lt;arr.length)
        println sprintf(&quot; array [% 2d] = %2s&quot;, i, arr[i])
}

def printMatrix(m) {
    println sprintf(&quot;\nPrint Matrix Content %s[%d,%d]&quot;,
        m.getClass().getName(), m.length, m[0].length)

    for (int i = 0; i &amp;lt; m.length; i++)
        for (int j = 0; j &amp;lt; m[0].length; j++)
            println sprintf(&quot; array [%2d,%2d] = %2s&quot;, i, j, m[i][j].toString())
}

def graphJaggedArray(arr) {  
    /* When using Arrays, we can use foreach instead of for:  
     *  
     * for (i in 0..&amp;lt;arr.length) 
     *   for (j in 0..&amp;lt;arr.length)                 
     *  
    */  
    println &quot;\nPrint Text Content ${arr.getClass().getName()}&quot;  
    lineCount = 1  
    for(s in arr) {  
        print sprintf(&quot;Line%2s|&quot;, lineCount)
        for(w in s) 
            print sprintf(&quot;%3s&quot;, &#39;*&#39;)
        println sprintf(&quot; (%d)&quot;, s.length)  
        lineCount++
    }  
}  

def printJaggedArray(arr) {
    println &quot;\nPrint Jagged Array Content ${arr.getClass().getName()}&quot;
    for (i in 0..&amp;lt;arr.length) {
        def line = new StringBuffer()
        for (j in 0..&amp;lt;arr[i].length) 
            line.append(&quot; &quot;).append(arr[i][j])
        if (line.toString().equals(line.toString().toUpperCase())) 
            line.append(&quot; &amp;lt;-- [UPPERCASED]&quot;)
        println line
    }
}

def printCommonArrayExceptions(arr) {  
    try {  
        arr[100][100] = &quot;hola&quot; 
    }  
    catch (ex) {  
        println &quot;\nException: \n${ex.getClass().getName()}\n${ex.getMessage()}&quot;                
    }  
}  

def printTitle(message) {
    println &quot;&quot;
    println &quot;=&quot; * 54
    println message
    println &quot;=&quot; * 54
}


class Alphabet {
    // Array Field
    private char[] letters

    // Indexer Getter/Setter 
    def getAt(int index) {
        letters[index]
    }    
    def putAt(int index, def value) {
       letters[index] = value.toUpperCase()
    }

    // Getter
    def getLength() {  
        letters.length
    }  
  
    // Constructors  
    public Alphabet(int size) {  
        letters = new char[size]
    }  

    public Alphabet(String list) {  
        letters = list.toUpperCase().toCharArray()
    }  

    public Alphabet(char[] list) {  
        letters = list
    }  
    
    // Overridden Method  
    @Override
    String toString() {  
        letters.toString().split(&quot;&quot;).join(&quot;,&quot;)
    }  
    
    // Method  
    def slice(int start, int length) {  
        letters[start..&amp;lt;start+length].toArray() as char[]
    }  
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAYw3uIXPVbDzSvdDKaTZjs_WLavI63O4Ju9j1rFUtGDDwqb5I8jHeEgQ04Tp2uGg5p3Ch58Y9SgTf67fQ6bxLsYwRPEFoHj4bFTBRs77BKPkD1S0Wmgii7CxcvM9Zg42v3qNOtf4b6zU/s1600/GroovyArrays.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAYw3uIXPVbDzSvdDKaTZjs_WLavI63O4Ju9j1rFUtGDDwqb5I8jHeEgQ04Tp2uGg5p3Ch58Y9SgTf67fQ6bxLsYwRPEFoHj4bFTBRs77BKPkD1S0Wmgii7CxcvM9Zg42v3qNOtf4b6zU/s1600/GroovyArrays.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/8295782085038593480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2014/12/arrays-and-indexers-in-groovy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/8295782085038593480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/8295782085038593480'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2014/12/arrays-and-indexers-in-groovy.html' title='Arrays and Indexers in Groovy'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAYw3uIXPVbDzSvdDKaTZjs_WLavI63O4Ju9j1rFUtGDDwqb5I8jHeEgQ04Tp2uGg5p3Ch58Y9SgTf67fQ6bxLsYwRPEFoHj4bFTBRs77BKPkD1S0Wmgii7CxcvM9Zg42v3qNOtf4b6zU/s72-c/GroovyArrays.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-7695382544378783265</id><published>2014-11-30T12:58:00.001-08:00</published><updated>2014-11-30T12:58:06.717-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="JVM"/><title type='text'>Arrays and Indexers in Java</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in Java. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Java, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my (not so) recent post (anymore), &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in C# and C++ just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;package javaarrays;
import java.util.Random;

public class JavaArrays {
    
    public static void main(String[] args) {
        
        // Single-dimensional Array(s)  
        printTitle(&quot;Reverse Array Elements&quot;);  
  
        // Declare and Initialize Array of Chars  
        char[] letters = new char[5];  
        letters[0] = &#39;A&#39;;  
        letters[1] = &#39;E&#39;;  
        letters[2] = &#39;I&#39;;  
        letters[3] = &#39;O&#39;;  
        letters[4] = &#39;U&#39;;  
        
        printArrayChar(letters);  
        char[] inverse_letters = reverseChar(letters);  
        printArrayChar(inverse_letters);  

        printTitle(&quot;Sort Integer Array Elements&quot;);  

        // Declare and Initialize Array of Integers   
        int[] numbers = { 10, 8, 3, 1, 5 };  
        printArrayInt(numbers);  
        int[] ordered_numbers = bubbleSortInt(numbers);  
        printArrayInt(ordered_numbers);  

        printTitle(&quot;Sort String Array Elements&quot;);  

        // Declare and Initialize and Array of Strings  
        String[] names = new String[] {                       
                &quot;Damian&quot;,   
                &quot;Rogelio&quot;,  
                &quot;Carlos&quot;,   
                &quot;Luis&quot;,                       
                &quot;Daniel&quot;  
            };  
        printArrayString(names);
        String[] ordered_names = bubbleSortString(names);  
        printArrayString(ordered_names);  

        // Multi-dimensional Array (Matrix row,column)  

        printTitle(&quot;Transpose Matrix&quot;);  

        /* Matrix row=2,col=3 
         * A =  [6  4 24] 
         *      [1 -9  8] 
        */  
        int[][] matrix = { { 6, 4, 24 },   
                           { 1, -9, 8 } };  
        printMatrix(matrix);  
        int[][] transposed_matrix = transposeMatrix(matrix);  
        printMatrix(transposed_matrix);  

        // Jagged Array (Array-of-Arrays)  

        printTitle(&quot;Upper Case Random Array &amp;amp; Graph Number of Elements&quot;);  
        
        /*              
         * Creating an array of string arrays using the String.Split method 
         * instead of initializing it manually as follows: 
         *  
         * String[][] text = new String[][] {  
         *      new String[] { &quot;word1&quot;, &quot;word2&quot;, &quot;wordN&quot; },  
         *      new String[] { &quot;word1&quot;, &quot;word2&quot;, &quot;wordM&quot; },  
         *      ... 
         *      }; 
         *  
         * Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot; 
         *  
         */  
        String[][] text = {   
        &quot;Hoy es el dÃ­a mÃ¡s hermoso de nuestra vida, querido Sancho;&quot;.split(&quot; &quot;),  
        &quot;los obstÃ¡culos mÃ¡s grandes, nuestras propias indecisiones;&quot;.split(&quot; &quot;),  
        &quot;nuestro enemigo mÃ¡s fuerte, miedo al poderoso y nosotros mismos;&quot;.split(&quot; &quot;),  
        &quot;la cosa mÃ¡s fÃ¡cil, equivocarnos;&quot;.split(&quot; &quot;),  
        &quot;la mÃ¡s destructiva, la mentira y el egoÃ­smo;&quot;.split(&quot; &quot;),  
        &quot;la peor derrota, el desaliento;&quot;.split(&quot; &quot;),  
        &quot;los defectos mÃ¡s peligrosos, la soberbia y el rencor;&quot;.split(&quot; &quot;),  
        &quot;las sensaciones mÃ¡s gratas, la buena conciencia...&quot;.split(&quot; &quot;)   
        };  
        printJaggedArray(text);  
        upperCaseRandomArray(text);  
        printJaggedArray(text);  
        graphJaggedArray(text);  

        // Array Exceptions  

        printTitle(&quot;Common Array Exceptions&quot;);  

        printCommonArrayExceptions(null);  
        printCommonArrayExceptions(text);  

        // Accessing Class Array Elements through Indexer  

        printTitle(&quot;Alphabets&quot;);  

        Alphabet vowels = new Alphabet(5);  
        vowels.set(0, &#39;a&#39;);  
        vowels.set(1, &#39;e&#39;);  
        vowels.set(2, &#39;i&#39;);  
        vowels.set(3, &#39;o&#39;);  
        vowels.set(4, &#39;u&#39;);  
        
        System.out.format(&quot;\nVowels = {%s}\n&quot;,  
                String.join(&quot;,&quot;, String.valueOf(vowels.get(0)), 
                    String.valueOf(vowels.get(1)), String.valueOf(vowels.get(2)), 
                    String.valueOf(vowels.get(3)), String.valueOf(vowels.get(4))));
        
        Alphabet en = new Alphabet(&quot;abcdefghijklmnopqrstuvwxyz&quot;);  
        System.out.format(&quot;English Alphabet = {%s}\n&quot;, en.toString()); 
        
        System.out.format(&quot;Alphabet Extract en[9..19] = {%s}\n&quot;,   
                          new Alphabet(en.slice(9, 10))); 
        
        String word1 = String.join(&quot;&quot;, String.valueOf(en.get(6)), 
                String.valueOf(en.get(14)), String.valueOf(en.get(14)), 
                String.valueOf(en.get(3)));  
        String word2 = String.join(&quot;&quot;, String.valueOf(en.get(1)), 
                String.valueOf(en.get(24)), String.valueOf(en.get(4)));  
        String word3 = String.join(&quot;&quot;, String.valueOf(en.get(4)), 
                String.valueOf(en.get(21)), String.valueOf(en.get(4)), 
                String.valueOf(en.get(17)), String.valueOf(en.get(24)), 
                String.valueOf(en.get(14)), String.valueOf(en.get(13)), 
                String.valueOf(en.get(4)));  
  
        System.out.format(&quot;\n%s %s, %s!\n&quot;, word1, word2, word3);
    }
    
    private static char[] reverseChar(char[] arr) {  
        char[] reversed = new char[arr.length];  
        for (int i = 0, j = arr.length - 1; j &amp;gt;= 0; i++, j--) {
            reversed[i] = arr[j];  
        }
        return reversed;  
    }  
    
    static int[] bubbleSortInt(int[] arr) {  
        int swap;  
        for (int i = arr.length - 1; i &amp;gt; 0; i--) {  
            for (int j = 0; j &amp;lt; i; j++) {  
                if (arr[j] &amp;gt; arr[j + 1]) {  
                    swap = arr[j];  
                    arr[j] = arr[j + 1];  
                    arr[j + 1] = swap;  
                }  
            }  
        }  
        return arr;  
    }  

    static String[] bubbleSortString(String[] arr) {  
        String swap;  
        for (int i = arr.length - 1; i &amp;gt; 0; i--) {  
            for (int j = 0; j &amp;lt; i; j++) {                  
                if (arr[j].charAt(0) &amp;gt; arr[j + 1].charAt(0)) {  
                    swap = arr[j];  
                    arr[j] = arr[j + 1];  
                    arr[j + 1] = swap;  
                }  
            }  
        }  
        return arr;  
    }  
    
    private static int[][] transposeMatrix(int[][] m) {  
        /* Transposing a Matrix 2,3  
         *  
         * A =  [6  4 24]T [ 6  1]  
         *      [1 -9  8]  [ 4 -9] 
         *                 [24  8] 
        */  
        int[][] transposed = new int[m[0].length][m.length];  
        for (int i = 0; i &amp;lt; m.length; i++) {  
            for (int j = 0; j &amp;lt; m[0].length; j++) {  
                transposed[j][i] = m[i][j];  
            }  
        }  
        return transposed;  
    }  

    private static void upperCaseRandomArray(String[][] arr) {  
        Random r = new Random();  
        int i = r.nextInt(arr.length);  
        for (int j = 0; j &amp;lt;= arr[i].length - 1; j++) {
            arr[i][j] = arr[i][j].toUpperCase();  
        }
    }
    
    private static void printArrayChar(char[] arr) {  
        System.out.println(&quot;\nPrint Array Content &quot; 
                + arr.getClass().getName() + &quot;[&quot; + arr.length + &quot;]&quot;);

        for (int i = 0; i &amp;lt;= arr.length - 1; i++) {
            System.out.format(&quot; array [%2d] = %2s\n&quot;, i, arr[i]);   
        }
    }  
    
    private static void printArrayInt(int[] arr) {  
        System.out.println(&quot;\nPrint Array Content &quot; 
                + arr.getClass().getName() + &quot;[&quot; + arr.length + &quot;]&quot;);

        for (int i = 0; i &amp;lt;= arr.length - 1; i++) {
            System.out.format(&quot; array [%2d] = %2s\n&quot;, i, arr[i]);   
        }
    }
    
    private static void printArrayString(String[] arr) {  
        System.out.println(&quot;\nPrint Array Content &quot; 
                + arr.getClass().getName() + &quot;[&quot; + arr.length + &quot;]&quot;);

        for (int i = 0; i &amp;lt;= arr.length - 1; i++) {
            System.out.format(&quot; array [%2d] = %2s\n&quot;, i, arr[i]);   
        }
    }
    
    private static void printMatrix(int[][] m) {  
        System.out.format(&quot;\nPrint Matrix Content %s[%d,%d]\n&quot;,  
            m.getClass().getName(),
            m.length,  
            m[0].length);

        for (int i = 0; i &amp;lt;= m.length - 1; i++) { 
            for (int j = 0; j &amp;lt;= m[0].length - 1; j++) {
                System.out.format(&quot; array [%2d,%2d] = %2d\n&quot;, i, j, m[i][j]);
            }
        }
    }  
    
    private static void graphJaggedArray(String[][] arr) {  
        /* When using Arrays, we can use foreach instead of for:  
         *  
         * for (int i = 0; i &amp;lt;= arr.length - 1; i++) 
         *   for (int j = 0; j &amp;lt;= arr.length - 1; j++)                 
         *  
        */  
        System.out.println(&quot;\nPrint Text Content &quot; 
                + arr.getClass().getName());  
        int lineCount = 1;  
        for(String[] s : arr) {  
            System.out.format(&quot;Line%2s|&quot;, lineCount);  
            for(String w : s) {  
                System.out.format(&quot;%3s&quot;, &#39;*&#39;);  
            }  
            System.out.format(&quot; (%d)\n&quot;, s.length);  
            lineCount++;  
        }  
    }  
    
    private static void printJaggedArray(String[][] arr) {  
        StringBuffer line;  
        System.out.println(&quot;\nPrint Jagged Array Content &quot; 
                + arr.getClass().getName());  
        for (int i = 0; i &amp;lt; arr.length; i++)  {  
            line = new StringBuffer();  
            for (int j = 0; j &amp;lt; arr[i].length; j++) {  
                line.append(&quot; &quot;).append(arr[i][j]);  
            }
            if (line.toString().equals(line.toString().toUpperCase())) {
                line.append(&quot; &amp;lt;-- [UPPERCASED]&quot;);  
            }
            System.out.println(line);  
        }  
    }  
    
    private static void printCommonArrayExceptions(String[][] arr) {  
        try {  
            arr[100][100] = &quot;hola&quot;;  
        }  
        catch (NullPointerException | ArrayIndexOutOfBoundsException ex) {  
            System.out.format(&quot;\nException: \n%s\n%s\n&quot;, 
                    ex.getClass().getName(), ex.getMessage());  
        }  
    }  
    
    private static void printTitle(String message) {
        System.out.println();  
        System.out.println(&quot;======================================================&quot;);  
        System.out.println(message);
        System.out.println(&quot;======================================================&quot;);
    }
    
}

class Alphabet {
    // Array Field
    private char[] letters;

    // Indexer Getter/Setter 
    public char get(int index) {
        return letters[index];
    }
    
    public void set(int index, char value) {
       letters[index] = String.valueOf(value).toUpperCase().charAt(0);
    }

    // Getter
    public int getLength() {  
        return this.letters.length;  
    }  
  
    // Constructors  
    public Alphabet(int size) {  
        this.letters = new char[size];  
    }  

    public Alphabet(String list) {  
        this.letters = list.toUpperCase().toCharArray();
    }  

    public Alphabet(char[] list) {  
        this.letters = list;  
    }  
    
    // Overridden Method  
    @Override public String toString() {  
        return String.join(&quot;,&quot;, (new String(this.letters)).split(&quot;&quot;));  
    }  
    
    // Method  
    public char[] slice(int start, int length) {  
        char[] result = new char[length];  
        for (int i = 0, j = start; i &amp;lt; length; i++, j++) {  
            result[i] = this.letters[j];  
        }  
        return result;
    }  
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH9eeCUtErUdLOAAswqNhGE5ejwB4zXO-D9YYbJvZZEvmNMguvJ9N_O6jl6RYySnI7I_Sqi1foFPCnrgfIUaovBjBtWH8vu36AE0VGRGf8iEHGodcDX0hV0Lt9xnxXIUZwX-jqcqgNTWU/s1600/JavaArrays.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH9eeCUtErUdLOAAswqNhGE5ejwB4zXO-D9YYbJvZZEvmNMguvJ9N_O6jl6RYySnI7I_Sqi1foFPCnrgfIUaovBjBtWH8vu36AE0VGRGf8iEHGodcDX0hV0Lt9xnxXIUZwX-jqcqgNTWU/s1600/JavaArrays.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/7695382544378783265/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2014/11/arrays-and-indexers-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/7695382544378783265'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/7695382544378783265'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2014/11/arrays-and-indexers-in-java.html' title='Arrays and Indexers in Java'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH9eeCUtErUdLOAAswqNhGE5ejwB4zXO-D9YYbJvZZEvmNMguvJ9N_O6jl6RYySnI7I_Sqi1foFPCnrgfIUaovBjBtWH8vu36AE0VGRGf8iEHGodcDX0hV0Lt9xnxXIUZwX-jqcqgNTWU/s72-c/JavaArrays.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-5139409773730507623</id><published>2014-07-24T03:43:00.000-07:00</published><updated>2017-04-21T06:40:00.006-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JVM"/><category scheme="http://www.blogger.com/atom/ns#" term="Jython"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Arrays and Indexers in Jython</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in Jython. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Jython, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
This is the second post of a dynamic language. As with IronPython&#39;s version of the program, code structure changed slightly from previous posts. Besides that, because you normally don&#39;t use Arrays per se in Python (except for numerical arrays when better performance is required), it is more practical to use Python&#39;s List object instead of Java&#39;s java.lang.ArrayList, which can definitely be used in Jython, specially when you need to inter operate with other JVM languages. 
&lt;br /&gt;
By the way, if you missed my most recent post, &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in Boo (or Cobra or Jython later on) just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;import java  
from java.util import Random

# Console Program     
def main():     
    # Single-dimensional Array(s)     
    printtitle(&#39;Reverse Array Elements&#39;)   
  
    # Declare and Initialize Array (Python List) of Chars     
    # or letters = list(&#39;AEIOU&#39;)  
    # or letters = 5 * [&#39; &#39;]        
    letters = list(&#39; &#39; * 5) # letters = []  
    letters[0] = &#39;A&#39;        # letters.append(&#39;A&#39;)  
    letters[1] = &#39;E&#39;        # letters.append(&#39;E&#39;)  
    letters[2] = &#39;I&#39;        # letters.append(&#39;I&#39;)  
    letters[3] = &#39;O&#39;        # letters.append(&#39;O&#39;)  
    letters[4] = &#39;U&#39;        # letters.append(&#39;U&#39;)  
      
    printarray(letters)  
    inverse_letters = reversechar(letters)  
    printarray(inverse_letters)  
  
    printtitle(&#39;Sort Integer Array Elements&#39;)  
    # Declare and Initialize Array of Integers     
    numbers = [10, 8, 3, 1, 5]  
      
    printarray(numbers)     
    ordered_numbers = bubblesort(numbers)     
    printarray(ordered_numbers)  
  
    printtitle(&#39;Sort String Array Elements&#39;)    
  
    # Declare and Initialize and Array of Strings     
    names = [&#39;Damian&#39;, &#39;Rogelio&#39;, &#39;Carlos&#39;, &#39;Luis&#39;, &#39;Daniel&#39;]  
  
    printarray(names)     
    ordered_names = bubblesort(names)     
    printarray(ordered_names)  
  
    # Multi-dimensional Array (Matrix row,column)     
    printtitle(&#39;Transpose Matrix&#39;)     
  
    matrix = [[6, 4, 24],        
              [1, -9, 8]]  
  
    printmatrix(matrix)  
    transposed_matrix = transposematrix(matrix)     
    printmatrix(transposed_matrix)    
  
    # Jagged Array (Array-of-Arrays)     
    printtitle(&#39;Upper Case Random Array &amp;amp; Graph Number of Elements&#39;)     
  
    &#39;&#39;&#39; 
    Creating an array of string arrays using the String.Split method    
    instead of initializing it manually as follows:    
  
    $text = [     
        [ [&quot;word1&quot;, &quot;word2, &quot;wordN&quot;],     
        [ [&quot;word1&quot;, &quot;word2, &quot;wordN&quot;],     
        ... 
    ]    
      
    Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot;         
    &#39;&#39;&#39;  
    text = [  
    &#39;Hoy es el dia mas hermoso de nuestra vida, querido Sancho;&#39;.split(&#39; &#39;),      
    &#39;los obstaculos mas grandes, nuestras propias indecisiones;&#39;.split(&#39; &#39;),      
    &#39;nuestro enemigo mas fuerte, miedo al poderoso y nosotros mismos;&#39;.split(&#39; &#39;),      
    &#39;la cosa mas facil, equivocarnos;&#39;.split(&#39; &#39;),      
    &#39;la mas destructiva, la mentira y el egoismo;&#39;.split(&#39; &#39;),      
    &#39;la peor derrota, el desaliento;&#39;.split(&#39; &#39;),      
    &#39;los defectos mas peligrosos, la soberbia y el rencor;&#39;.split(&#39; &#39;),      
    &#39;las sensaciones mas gratas, la buena conciencia...&#39;.split(&#39; &#39;)  
    ]  
  
    printjaggedarray(text)     
    uppercaserandomarray(text)     
    printjaggedarray(text)     
    graphjaggedarray(text)  
  
    # Array Exceptions  
    printtitle(&#39;Common Array Exceptions&#39;)  
      
    printcommonarrayexceptions(None)     
    printcommonarrayexceptions(text)   
    a = java.util.ArrayList() 
    printcommonarrayexceptions(a)
    o = java.lang.Object
    printcommonarrayexceptions(o)
    # Accessing Class Array Elements through Indexer  
    printtitle(&#39;Alphabets&#39;)    
      
    vowels = Alphabet(5)  
    vowels[0] = &#39;a&#39;  
    vowels[1] = &#39;e&#39;  
    vowels[2] = &#39;i&#39;  
    vowels[3] = &#39;o&#39;  
    vowels[4] = &#39;u&#39;  
  
    print &#39;\nVowels = {%s}&#39; % &#39;,&#39;.join([vowels[0],vowels[1],vowels[2],vowels[3],vowels[4]])  
  
    en = Alphabet(&#39;abcdefghijklmnopqrstuvwxyz&#39;)     
    print &#39;English Alphabet = {%s}&#39; % (str(en))  
  
    print &#39;Alphabet Extract en[9..19] = {%s}&#39; % (str(Alphabet(en.slice(9, 10))))  
     
    word1 = &#39;&#39;.join([en[6], en[14], en[14], en[3]])  
    word2 = &#39;&#39;.join([en[1], en[24], en[4]])     
    word3 = &#39;&#39;.join([en[4], en[21], en[4], en[17], en[24], en[14], en[13], en[4]])     
    print &quot;\n%s %s, %s!\n&quot; % (word1, word2, word3)    
  
    raw_input()  
  
def reversechar(arr):  
    return list(reversed(arr))  
    # or   
    # return arr[::-1]  
    # or   
    # reversedarr = [], i = 0  
    # for j in range(len(arr) - 1,-1,-1):  
    #   reversedarr[i] = arr[j]  
    # return reversedarr  
    #  
  
def bubblesort(arr):  
    for i in reversed(arr):     
        for j in range(len(arr) - 1):     
            if arr[j] &amp;gt; arr[j + 1]:     
                swap = arr[j]     
                arr[j] = arr[j + 1]     
                arr[j + 1] = swap     
    return arr  
  
def transposematrix(m):     
    &#39;&#39;&#39; Transposing a Matrix 2,3   
      
     A =  [6  4 24]T [ 6  1]   
          [1 -9  8]  [ 4 -9]   
                     [24  8]   
    &#39;&#39;&#39;  
    transposed = [len(m)*[0] for i in range(len(m[0]))]  
    for i in range(len(m)):     
        for j in range(len(m[0])):     
            transposed[j][i] = m[i][j]  
    return transposed    
  
def uppercaserandomarray(arr):     
    r = Random()     
    i = r.nextInt(len(arr))     
    for j in range(len(arr[i])):  
        arr[i][j] = arr[i][j].upper()  
  
def printarray(arr):  
    print &#39;\nPrint Array Content &#39; + str(type(arr))[7:-2]  + &#39;[&#39; + str(len(arr)) + &#39;]&#39;  
    for i in range(len(arr)):     
        print &#39; array [{0:2}&#39;.format(i) + &#39;] = {0:2}&#39;.format(arr[i])  
  
def printmatrix(m):     
    print &#39;\nPrint Matrix Content &#39; + str(type(m))[7:-2]  + &#39;[&#39; + str(len(m)) + &#39;,&#39; + str(len(m[0])) + &#39;]&#39;  
    for i in range(len(m)):     
        for j in range(len(m[0])):     
            print &#39; array [{0:2},{1:2}] = {2:2} &#39;.format(i, j, m[i][j])  
  
def graphjaggedarray(arr):     
    &#39;&#39;&#39;When using Arrays, we can use for(each) instead of for by index: 
    for s as (string) in arr:   
        for w as string in s:  
    &#39;&#39;&#39;   
    print &#39;\nPrint Text Content &#39; + str(type(arr))[7:-2]  
    for i in range(len(arr)):     
        line = &#39;&#39;  
        line += &#39;Line{0:2}|&#39;.format(i+1)  
        for j in range(len(arr[i])):     
            line += &#39;{0:3}&#39;.format(&#39;*&#39;)     
        line += &#39;(&#39; + str(len(arr[i])) + &#39;)&#39;  
        print line  
          
  
def printjaggedarray(arr):  
    print &#39;\nPrint Jagged Array Content &#39; + str(type(arr))[7:-2]  
    for i in range(len(arr)):  
        line = &#39;&#39;  
        for j in range(len(arr[i])):        
            line += &#39; &#39; + arr[i][j]  
        if line == line.upper():  
            line += &#39; &amp;lt;-- [UPPERCASED]&#39;  
        print line  
  
def printcommonarrayexceptions(arr):  
    try:  
        print type(arr)
        arr[100][100] = &#39;hola&#39;
    except TypeError, e:  
        print &#39;\nType Exception: \n&#39;, e
    except IndexError, e:
        print &#39;\nIndex Exception: \n&#39;, e
    except java.lang.Exception, e:
        print &#39;\nJava Exception: &#39;, e
    #except e:  
    #    print &#39;\nException:&#39; 
    #else:  
  
def printtitle(message):      
    print &#39;&#39;    
    print &#39;=&#39; * 54     
    print message     
    print &#39;=&#39; * 54

class Alphabet:  
    # Array Field     
    _letters = []  
      
    # Indexer Get/Set Property  
    def __getitem__(self, idx):  
        return self._letters[idx]  
    def __setitem__(self, idx, value):  
        self._letters[idx] = str(value).upper()  
      
    # Read-Only Property  
    def get_Length(self):  
        return len(self._letters)     
    Length = property(fget=get_Length)  
  
    # Constructor  
    def __init__(self, param=None):             
        if type(param) == type(1):  
            self._letters = list(&#39; &#39; * param)  
        elif type(param) == type(&#39;&#39;):  
            self._letters = list(str(param).upper())  
        elif type(param) == type([]):  
            self._letters = param  
        else:  
            self._letters = None  
  
    # Overridden Method      
    def __str__(self):  
        return &#39;,&#39;.join(self._letters)  
  
    # Method     
    def slice(self, start, length):  
        return self._letters[start:start+length]  
  
if __name__ == &#39;__main__&#39;:  
    main()

&lt;/pre&gt;
&lt;br /&gt;
The output:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhrPdyB7U9TrGO6G4IHpqYfBKMFNnmy8LdHWtCy_vz5al8ewDK727_paCRJChcRpM9MfhNCk1sXBo73xmZXR9GfEOdfltXzRQ2j8kWQpsm7nRfkL9pkAW4bxp0TwcSHmwNeJ2G19mbM94/s1600/JyArraysOutput.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhrPdyB7U9TrGO6G4IHpqYfBKMFNnmy8LdHWtCy_vz5al8ewDK727_paCRJChcRpM9MfhNCk1sXBo73xmZXR9GfEOdfltXzRQ2j8kWQpsm7nRfkL9pkAW4bxp0TwcSHmwNeJ2G19mbM94/s1600/JyArraysOutput.png&quot;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.



&lt;!------&gt;&lt;!------&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/5139409773730507623/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2014/07/arrays-and-indexers-in-jython.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/5139409773730507623'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/5139409773730507623'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2014/07/arrays-and-indexers-in-jython.html' title='Arrays and Indexers in Jython'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhrPdyB7U9TrGO6G4IHpqYfBKMFNnmy8LdHWtCy_vz5al8ewDK727_paCRJChcRpM9MfhNCk1sXBo73xmZXR9GfEOdfltXzRQ2j8kWQpsm7nRfkL9pkAW4bxp0TwcSHmwNeJ2G19mbM94/s72-c/JyArraysOutput.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-6578878133949695264</id><published>2014-05-06T14:58:00.000-07:00</published><updated>2017-04-21T06:47:47.899-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JRuby"/><category scheme="http://www.blogger.com/atom/ns#" term="JVM"/><title type='text'>Arrays and Indexers in JRuby</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in JRuby. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in JRuby, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
This is the first post on this series on a language targeting the JVM. Besides the fact that I had the code from a previous post written in (Iron)Ruby, the newly released version of the (J)Ruby plugin for NetBeans IDE (&lt;a href=&quot;http://plugins.netbeans.org/plugin/38549/?show=true&quot;&gt;http://plugins.netbeans.org/plugin/38549/?show=true&lt;/a&gt;) helped me decide what to publish next. &lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my most recent post, &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts.  &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: ruby&quot;&gt;require &quot;java&quot;

# Console Program  
def main()  
    # Single-dimensional Array(s)  
    print_title(&quot;Reverse Array Elements&quot;)  
   
    # Declare and Initialize Array of Chars        
    letters = Array.new(5,&quot; &quot;)  
    letters[0] = &quot;A&quot;  
    letters[1] = &quot;E&quot;  
    letters[2] = &quot;I&quot;  
    letters[3] = &quot;O&quot;  
    letters[4] = &quot;U&quot;  
   
    print_array(letters)    
    inverse_letters = reverse_char(letters)  
    print_array(inverse_letters)  
  
    print_title(&quot;Sort Integer Array Elements&quot;)  
    # Declare and Initialize Array of Integers     
    numbers = [10, 8, 3, 1, 5]  
      
    print_array(numbers)         
    ordered_numbers = bubblesort(numbers)     
    print_array(ordered_numbers)  
  
    print_title(&quot;Sort String Array Elements&quot;)    
   
    # Declare and Initialize and Array of Strings   
    #names = Array.new(5, [&quot;Damian&quot;,&quot;Rogelio&quot;,&quot;Carlos&quot;,&quot;Luis&quot;,&quot;Daniel&quot;])  
    # or just   
    names = [&quot;Damian&quot;,   
      &quot;Rogelio&quot;,   
      &quot;Carlos&quot;,   
      &quot;Luis&quot;,   
      &quot;Daniel&quot;]  
  
    print_array(names)     
    ordered_names = bubblesort(names)     
    print_array(ordered_names)  
  
    # Multi-dimensional Array (Matrix row,column)     
    print_title(&quot;Transpose Matrix&quot;)     
  
    # for an empty table initialized to 0s  
    # matrix = Array.new(rows,0) { Array.new(cols,0) }  
    matrix = [[6, 4, 24],        
              [1, -9, 8]]  
  
    print_matrix(matrix)  
    transposed_matrix = transpose_matrix(matrix)     
    print_matrix(transposed_matrix)    
   
    # Jagged Array (Array-of-Arrays)     
    print_title(&quot;Upper Case Random Array &amp;amp; Graph Number of Elements&quot;)     
  
=begin  
# Creating an array of string arrays using the String.Split method     
# instead of initializing it manually as follows:     
#   
# text = [      
#  [ [&quot;word1&quot;, &quot;word2, &quot;wordN&quot;],      
#  [ [&quot;word1&quot;, &quot;word2, &quot;wordN&quot;],      
#  ...  
#  ]     
#       
# Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot;          
=end  
    text = [  
    &quot;Hoy es el dia mas hermoso de nuestra vida, querido Sancho;&quot;.split(&quot; &quot;),      
    &quot;los obstaculos mas grandes, nuestras propias indecisiones;&quot;.split(&quot; &quot;),      
    &quot;nuestro enemigo mas fuerte, miedo al poderoso y nosotros mismos;&quot;.split(&quot; &quot;),      
    &quot;la cosa mas facil, equivocarnos;&quot;.split(&quot; &quot;),      
    &quot;la mas destructiva, la mentira y el egoismo;&quot;.split(&quot; &quot;),      
    &quot;la peor derrota, el desaliento;&quot;.split(&quot; &quot;),      
    &quot;los defectos mas peligrosos, la soberbia y el rencor;&quot;.split(&quot; &quot;),      
    &quot;las sensaciones mas gratas, la buena conciencia...&quot;.split(&quot; &quot;)  
    ]   
   
    print_jagged_array(text)     
    uppercase_random_array(text)        
    print_jagged_array(text)     
    graph_jagged_array(text)  
  
    # Array Exceptions  
    print_title(&#39;Common Array Exceptions&#39;)  
      
    print_common_array_exceptions(nil)  
    print_common_array_exceptions(text)    
  
    # Accessing Class Array Elements through Indexer  
    print_title(&#39;Alphabets&#39;)  
      
    vowels = Alphabet.new(5)  
    vowels[0] = &quot;a&quot;  
    vowels[1] = &quot;e&quot;  
    vowels[2] = &quot;i&quot;  
    vowels[3] = &quot;o&quot;  
    vowels[4] = &quot;u&quot;  
  
    puts &quot;\nVowels={%s}&quot; % [vowels[0],vowels[1],vowels[2],vowels[3],vowels[4]].join(&quot;,&quot;)  
  
    en = Alphabet.new(&quot;abcdefghijklmnopqrstuvwxyz&quot;)     
  
    puts &quot;English Alphabet = {%s}&quot; % [en]  
  
    puts &quot;Alphabet Extract en[9..19] = {%s}&quot; % [Alphabet.new(en.slice(9, 10))]  
  
    word1 = [en[6],en[14],en[14],en[3]].join(&quot;&quot;)  
    word2 = [en[1],en[24],en[4]].join(&quot;&quot;)     
    word3 = [en[4],en[21],en[4],en[17],en[24],en[14],en[13],en[4]].join(&quot;&quot;)     
    puts &quot;\n%s %s, %s!\n&quot; % [word1, word2, word3]  
   
    gets  
end  
  
def reverse_char(arr)  
    arr.reverse  
end   
  
def bubblesort(arr)    
    for i in arr.reverse  
        for j in (0..arr.count-2)  
            if arr[j] &amp;gt; arr[j + 1]      
                swap = arr[j]     
                arr[j] = arr[j + 1]     
                arr[j + 1] = swap     
            end      
        end   
    end     
    arr  
end  
  
def transpose_matrix(m)    
=begin  
# Transposing a Matrix 2,3    
#       
#   A =  [6  4 24]T [ 6  1]    
#        [1 -9  8]  [ 4 -9]    
#                [24  8]    
=end  
    transposed = Array.new(m[0].size) { Array.new(m.size) }   
    for i in 0..(m.size-1)     
        for j in 0..(m[0].size-1)     
            transposed[j][i] = m[i][j]  
        end  
    end  
    transposed    
end  
  
def uppercase_random_array(arr)        
    r = java.util.Random.new()
    i = r.nextInt(arr.size)
    for j in 0..(arr[i].size-1)     
        arr[i][j] = arr[i][j].upcase  
    end  
end  
  
def print_array(arr)  
    puts &quot;\nPrint Array Content #{arr.class.name}[#{arr.size}]&quot;  
    for i in 0..(arr.size-1)  
        puts &quot; array [%2s] = %2s&quot; % [i, arr[i]]  
    end  
end  
  
def print_matrix(m)  
    puts &quot;\nPrint Array Content #{m.class.name}[#{m.size}][#{m[0].size}]&quot;  
    for i in 0..(m.size-1)  
        for j in 0..(m[0].size-1)  
            puts &quot; array [%2s,%2s] = %2s&quot; % [i, j, m[i][j]]  
        end  
    end  
    m  
end  
  
def graph_jagged_array(arr)  
=begin  
# When using Arrays, we can use for(each) instead of for by index  
#    for s in arr    
#        for w in s   
#        end  
#    end  
=end   
    puts &quot;\nPrint Text Content #{arr.class.name}&quot;  
    for i in 0..(arr.size-1)    
        line = &quot;&quot;  
        line += &quot;Line %2s|&quot; % (i+1).to_s   
        for j in 0..(arr[i].size-1)     
            line += &quot; * &quot;  
        end              
        line += &quot;(#{arr[i].size})&quot;  
        puts line  
    end  
end  
  
def print_jagged_array(arr)  
    puts &quot;\nPrint Jagged Array Content #{arr.class.name}&quot;  
    for i in 0..(arr.size-1)  
        line = &quot;&quot;  
        for j in 0..(arr[i].size-1)       
            line += &quot; &quot; + arr[i][j]  
        end  
        if line == line.upcase  
            line += &quot; &amp;lt;-- [UPPERCASED]&quot;  
        end  
        puts line  
    end  
end  
  
def print_common_array_exceptions(arr)  
    begin    
        arr.fetch(100)  
    rescue Exception =&amp;gt; ex  
      puts &quot;\nException: \n%s\n%s&quot; % [ex.class.name, ex.message]  
    #else  
    #   others  
    end  
end  
  
def print_title(message)     
    puts &quot;&quot;    
    puts (&quot;=&quot; * 54)     
    puts message     
    puts (&quot;=&quot; * 54)  
end       
  
  
class Alphabet  
    # Array Field     
    @letters = []  
  
    # Indexer Get/Set Property  
    def [](idx)  
        @letters[idx]  
    end  
    def []=(idx, value)  
        @letters[idx] = value.upcase  
    end  
      
    # Read-Only Getter  
    def length  
        @letters.size  
    end            
  
    # Constructor/Initializer  
    def initialize(param)    
        if param.class == 1.class  
            @letters = Array.new(param, &quot; &quot;)  
        elsif param.class == &quot;&quot;.class  
            @letters = param.upcase.chars.to_a  
        elsif param.class == [].class  
            @letters = param  
        else  
            @letters = nil  
        end  
    end  
  
    # Overridden Method      
    def to_s  
        @letters.join(&quot;,&quot;)  
    end  
   
    # Method     
    def slice(start, length)  
        @letters[start..start+length-1]  
    end  
  
end  
  
main
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0rmAvCDg_flZDt_7J7baLYscL-voB9hf3cfms3U6xwVRyu17rq4CxnPjJ-FVosJRYJxudpg_vRXMpGhczfpNc2X2TuL5QAcNGSC4Sjl7Hreie-dloO0CiUKvkw2XiJFdT5sQhC2lh0yQ/s1600/JRbArraysOutput.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0rmAvCDg_flZDt_7J7baLYscL-voB9hf3cfms3U6xwVRyu17rq4CxnPjJ-FVosJRYJxudpg_vRXMpGhczfpNc2X2TuL5QAcNGSC4Sjl7Hreie-dloO0CiUKvkw2XiJFdT5sQhC2lh0yQ/s1600/JRbArraysOutput.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/6578878133949695264/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2014/05/arrays-and-indexers-in-jruby.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/6578878133949695264'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/6578878133949695264'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2014/05/arrays-and-indexers-in-jruby.html' title='Arrays and Indexers in JRuby'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0rmAvCDg_flZDt_7J7baLYscL-voB9hf3cfms3U6xwVRyu17rq4CxnPjJ-FVosJRYJxudpg_vRXMpGhczfpNc2X2TuL5QAcNGSC4Sjl7Hreie-dloO0CiUKvkw2XiJFdT5sQhC2lh0yQ/s72-c/JRbArraysOutput.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-5594165416328636601</id><published>2014-03-06T09:37:00.005-08:00</published><updated>2014-03-06T09:37:58.829-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><title type='text'>Arrays and Indexers in F#</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in F#. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in F#, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my most recent post, &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in C# and C++ just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
WARNING! I know that F# is intended to be use in a Functional way, however, my goal is to show its Imperative and OO language features, so it can be compared with other OO languages. Said that, if you know how to do something on the examples below on a Functional way, you are welcome to add them as a comment :)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharp&quot; name=&quot;code&quot;&gt;open System
open System.Text

module FsArrays =
    type Alphabet public (size: int) as this = class    
        // Array Field 
        [&amp;lt;DefaultValue&amp;gt;]
        val mutable private letters: char array 
        do this.letters &amp;lt;- Array.create size &#39; &#39;
        // Indexer Get/Set Property  
        member public this.Item
            with get(index) = 
                this.letters.[index]
            and set index value = 
                this.letters.[index] &amp;lt;- value.ToString().ToUpper().[0]
        // Read-only Property
        member public this.Length
            with get() = this.letters.Length
        // Constructors  
        new() = new Alphabet(0)
        new(l: string) as this = new Alphabet(l.Length) then 
            this.letters &amp;lt;- l.ToUpper().ToCharArray()
        new(l: char[]) as this = new Alphabet(0) then 
            this.letters &amp;lt;- l
        // Overridden Method  
        override this.ToString() = 
            String.Join(&quot;,&quot;, [|for c in this.letters -&amp;gt; c.ToString()|])
        // Method
        member public this.Slice(start: int, length: int): char[] = 
            this.letters.[start .. start + length - 1]
    end

    let ReverseChar (arr: char array) : char array = 
        Array.rev arr

    let BubbleSortInt (arr: int array) = 
        let mutable swap = 0
        for i in Array.rev(arr) do
            for j in 0 .. arr.Length - 2 do
                if arr.[j] &amp;gt; arr.[j + 1] then
                    swap &amp;lt;- arr.[j]   
                    arr.[j] &amp;lt;- arr.[j + 1] 
                    arr.[j + 1] &amp;lt;- swap  
        arr  

    let BubbleSortString (arr: string array) = 
        let mutable swap = &quot;&quot;
        for i in Array.rev(arr) do
            for j in 0 .. arr.Length - 2 do
                if arr.[j].[0] &amp;gt; arr.[j + 1].[0] then
                    swap &amp;lt;- arr.[j]   
                    arr.[j] &amp;lt;- arr.[j + 1] 
                    arr.[j + 1] &amp;lt;- swap  
        arr  

    let TransposeMatrix(m: int[,]): int[,] =
        (* Transposing a Matrix 2,3  
            *  
            * A =  [6  4 24]T [ 6  1]  
            *      [1 -9  8]  [ 4 -9] 
            *                 [24  8] 
        *)  
        let transposed = Array2D.zeroCreate&amp;lt;int&amp;gt; (m.GetLength 1) (m.GetLength 0)  
        for i in 0 .. m.GetLength 0 - 1 do
            for j in 0 .. m.GetLength 1 - 1 do
                transposed.[j, i] &amp;lt;- m.[i, j]         
        transposed;  
  
    let UpperCaseRandomArray (arr: string[][]) =         
        let r = new System.Random()
        let i = r.Next (arr.Length - 1)
        for j in 0 .. arr.[i].Length - 1 do 
            arr.[i].[j] &amp;lt;- arr.[i].[j].ToUpper()

    let PrintArrayChar (arr: char array) =
        printfn &quot;\nPrint Array Content %s&quot; 
            (arr.GetType().Name.Replace(&quot;]&quot;, arr.Length.ToString() + &quot;]&quot;))
        for i in 0 .. arr.Length - 1 do
            printfn &quot; array [%2i] = %2c&quot; i arr.[i] 

    let PrintArrayInt (arr: int array) =
        printfn &quot;\nPrint Array Content %s&quot; 
            (arr.GetType().Name.Replace(&quot;]&quot;, arr.Length.ToString() + &quot;]&quot;))
        for i in 0 .. arr.Length - 1 do
            printfn &quot; array [%2i] = %2i&quot; i arr.[i] 

    let PrintArrayString (arr: string array) =
        printfn &quot;\nPrint Array Content %s&quot; 
            (arr.GetType().Name.Replace(&quot;]&quot;, arr.Length.ToString() + &quot;]&quot;))
        for i in 0 .. arr.Length - 1 do
            printfn &quot; array [%2i] = %2s&quot; i arr.[i] 

    let PrintMatrix (m: int[,]) = 
        printfn &quot;\nPrint Matrix Content %s[%i,%i]&quot; 
            (m.GetType().Name.Replace(&quot;[,]&quot;, &quot;&quot;)) (m.GetLength 0) (m.GetLength 1)
        for i in 0 .. m.GetLength 0 - 1 do
            for j in 0 .. m.GetLength 1 - 1 do
                printfn &quot; array [%2i,%2i] = %2i &quot; i j m.[i, j]  

    let GraphJaggedArray (arr: string[][]) =  
        (* When using Arrays, we can use foreach instead of for + index:  
        *  
        * for i in 0 .. m.GetLength 0 - 1 do
        *   for j in 0 .. m.GetLength 1 - 1 do              
        *  
        *)  
        printfn &quot;\nPrint Matrix Content %s&quot; (arr.GetType().Name)
        let mutable lineCount = 1
        for s in arr do
            printf &quot;Line%2i|&quot; lineCount  
            for w in s do  
                printf &quot;%3c&quot; &#39;*&#39;  
            printfn &quot; (%i)&quot; (s.Length)
            lineCount &amp;lt;- lineCount + 1

    let PrintJaggedArray (arr: string[][]) = 
        printfn &quot;\nPrint Jagged Array Content %s&quot; (arr.GetType().Name)  
        for i in 0 .. arr.Length - 1 do
            let line = new StringBuilder()
            for j in 0 .. arr.[i].Length - 1 do
                line.Append (&quot; &quot; + arr.[i].[j]) |&amp;gt; ignore
            if line.ToString() = line.ToString().ToUpper() then
                line.Append &quot; &amp;lt;-- [UPPERCASED]&quot; |&amp;gt; ignore
            printfn &quot;%s&quot; (line.ToString())

    let PrintTitle (message: string) = 
        printfn &quot;\n&quot;
        printfn &quot;%s&quot; ([|for i in 0..54 -&amp;gt; &quot;*&quot;|] |&amp;gt; String.concat &quot;&quot;)
        printfn &quot;%s&quot; message
        printfn &quot;%s&quot; ([|for i in 0..54 -&amp;gt; &quot;*&quot;|] |&amp;gt; String.concat &quot;&quot;)

    let PrintCommonArrayExceptions (arr: string[][]) =
        try
            arr.[100].[100] &amp;lt;- &quot;hola&quot;
        with
            (*
            | :? IndexOutOfRangeException as ex -&amp;gt; 
            | _ as ex -&amp;gt; 
            *)
            | ex -&amp;gt; 
                printfn &quot;\nException: \n%s\n%s&quot; (ex.GetType().Name) (ex.Message)

    [&amp;lt;EntryPoint&amp;gt;]
    let main argv =       
        // Single-dimensional Array(s)   
        PrintTitle &quot;Reverse Array Elements&quot;

        // Declare and Initialize Array of Chars
        let letters: char array = Array.create 5 &#39; &#39;
        letters.[0] &amp;lt;- &#39;A&#39;  
        letters.[1] &amp;lt;- &#39;E&#39;  
        letters.[2] &amp;lt;- &#39;I&#39;  
        letters.[3] &amp;lt;- &#39;O&#39;  
        letters.[4] &amp;lt;- &#39;U&#39;  

        PrintArrayChar letters
        let inverse_letters = ReverseChar letters   
        PrintArrayChar inverse_letters

        PrintTitle &quot;Sort Integer Array Elements&quot;   
 
        // Declare and Initialize Array of Integers    
        let numbers = [| 10; 8; 3; 1; 5 |]

        PrintArrayInt numbers   
        let ordered_numbers = BubbleSortInt numbers    
        PrintArrayInt ordered_numbers    

        PrintTitle &quot;Sort String Array Elements&quot;
    
        // Declare and Initialize and Array of Strings    
        let names : string array = [|&quot;Damian&quot;;    
                &quot;Rogelio&quot;;    
                &quot;Carlos&quot;;    
                &quot;Luis&quot;;   
                &quot;Daniel&quot;|]   

        PrintArrayString names
        let ordered_names = BubbleSortString names
        PrintArrayString ordered_names   

        // Multi-dimensional Array (Matrix row,column)      
        PrintTitle &quot;Transpose Matrix&quot;
    
        // let matrix = Array2D.zeroCreate&amp;lt;int&amp;gt; 2 3
        let matrix = array2D [|[|6; 4; 24|];
                                [|1; -9; 8|]|]    

        PrintMatrix matrix
        let transposed_matrix = TransposeMatrix matrix
        PrintMatrix transposed_matrix 
  
        // Jagged Array (Array-of-Arrays)  
  
        PrintTitle &quot;Upper Case Random Array &amp;amp; Graph Number of Elements&quot;
    
        (*              
        * Creating an array of string arrays using the String.Split method 
        * instead of initializing it manually as follows: 
        *  
        * let text: string[][] = [|  
        *      [| &quot;word1&quot;; &quot;word2&quot;; &quot;wordN&quot; |];  
        *      [| &quot;word1&quot;; &quot;word2&quot;; &quot;wordM&quot; |];  
        *      ... 
        *      |]
        *  
        * Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot; 
        *  
        *)  
        let mutable text = [|
            &quot;Hoy es el dÃ­a mÃ¡s hermoso de nuestra vida, querido Sancho;&quot;.Split &#39; &#39;;
            &quot;los obstÃ¡culos mÃ¡s grandes, nuestras propias indecisiones;&quot;.Split &#39; &#39;;
            &quot;nuestro enemigo mÃ¡s fuerte, miedo al poderoso y nosotros mismos;&quot;.Split &#39; &#39;;
            &quot;la cosa mÃ¡s fÃ¡cil, equivocarnos;&quot;.Split &#39; &#39;;
            &quot;la mÃ¡s destructiva, la mentira y el egoÃ­smo;&quot;.Split &#39; &#39;;
            &quot;la peor derrota, el desaliento;&quot;.Split &#39; &#39;;
            &quot;los defectos mÃ¡s peligrosos, la soberbia y el rencor;&quot;.Split &#39; &#39;;
            &quot;las sensaciones mÃ¡s gratas, la buena conciencia...&quot;.Split &#39; &#39; 
        |]
        PrintJaggedArray text
        UpperCaseRandomArray text
        PrintJaggedArray text
        GraphJaggedArray text  

        // Array Exceptions  
  
        PrintTitle &quot;Common Array Exceptions&quot;

        PrintCommonArrayExceptions null
        PrintCommonArrayExceptions text  

        // Accessing Class Array Elements through Indexer  
  
        PrintTitle &quot;Alphabets&quot; 

        let vowels = new Alphabet(5)
        vowels.[0] &amp;lt;- &#39;a&#39;
        vowels.[1] &amp;lt;- &#39;e&#39;
        vowels.[2] &amp;lt;- &#39;i&#39;
        vowels.[3] &amp;lt;- &#39;o&#39;
        vowels.[4] &amp;lt;- &#39;u&#39;

        printfn &quot;\nVowels = {%s}&quot; (String.Join(&quot;,&quot;, [|vowels.[0].ToString(); vowels.[1].ToString(); vowels.[2].ToString(); vowels.[3].ToString(); vowels.[4].ToString()|]))
  
        let en = new Alphabet(&quot;abcdefghijklmnopqrstuvwxyz&quot;)
        printfn &quot;English Alphabet = {%s}&quot; (en.ToString())  
  
        let x = new Alphabet(en.Slice(9, 10))
        printfn &quot;Alphabet Extract en[9..19] = {%s}&quot; (x.ToString())

        let word1 = String.Join(&quot;&quot;, [|en.[6].ToString(); en.[14].ToString(); en.[14].ToString(); en.[3].ToString()|])
        let word2 = String.Join(&quot;&quot;, [|en.[1].ToString(); en.[24].ToString(); en.[4].ToString()|])  
        let word3 = String.Join(&quot;&quot;, [|en.[4].ToString(); en.[21].ToString(); en.[4].ToString(); en.[17].ToString(); en.[24].ToString(); en.[14].ToString(); en.[13].ToString(); en.[4].ToString()|])  
  
        printfn &quot;\n%s %s, %s!\n&quot; word1 word2 word3

        Console.Read() |&amp;gt; ignore
        0 // Return
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9TGCpP8ybDpwnlDGFn37miiHkCFghx8DgthSqsZlfudtH6YE9b-EH6D5RrJLH2mZhytQtNxplN3dZBxXTR-ireBW3QSEOMjeTUNS2dLpLX1sI_6FVYU3CFCk55SP5kTGWB0RAQbhvC_k/s1600/FsArraysOutput.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9TGCpP8ybDpwnlDGFn37miiHkCFghx8DgthSqsZlfudtH6YE9b-EH6D5RrJLH2mZhytQtNxplN3dZBxXTR-ireBW3QSEOMjeTUNS2dLpLX1sI_6FVYU3CFCk55SP5kTGWB0RAQbhvC_k/s1600/FsArraysOutput.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/5594165416328636601/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2014/03/arrays-and-indexers-in-f.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/5594165416328636601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/5594165416328636601'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2014/03/arrays-and-indexers-in-f.html' title='Arrays and Indexers in F#'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9TGCpP8ybDpwnlDGFn37miiHkCFghx8DgthSqsZlfudtH6YE9b-EH6D5RrJLH2mZhytQtNxplN3dZBxXTR-ireBW3QSEOMjeTUNS2dLpLX1sI_6FVYU3CFCk55SP5kTGWB0RAQbhvC_k/s72-c/FsArraysOutput.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-1834677321300848839</id><published>2014-02-27T14:17:00.001-08:00</published><updated>2017-04-21T06:54:19.756-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="IronRuby"/><title type='text'>Arrays and Indexers in IronRuby</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in IronRuby. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in IronRuby, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
This is the last of the .NET dynamic languages. I&#39;m considering to stop writing about it because the project seems to be dead with no updates since 13/03/11)... will see, probably this will be the last post about it if no news, fortunately, there is still JRuby. &lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my most recent post, &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in JRuby, later on, just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: ruby&quot;&gt;require &quot;mscorlib&quot; 
include System

# Console Program
def main()
    # Single-dimensional Array(s)
    print_title(&quot;Reverse Array Elements&quot;)
 
    # Declare and Initialize Array of Chars      
    letters = Array.new(5,&quot; &quot;)
    letters[0] = &quot;A&quot;
    letters[1] = &quot;E&quot;
    letters[2] = &quot;I&quot;
    letters[3] = &quot;O&quot;
    letters[4] = &quot;U&quot;
 
    print_array(letters)  
    inverse_letters = reverse_char(letters)
    print_array(inverse_letters)

    print_title(&quot;Sort Integer Array Elements&quot;)
    # Declare and Initialize Array of Integers   
    numbers = [10, 8, 3, 1, 5]
    
    print_array(numbers)       
    ordered_numbers = bubblesort(numbers)   
    print_array(ordered_numbers)

    print_title(&quot;Sort String Array Elements&quot;)  
 
    # Declare and Initialize and Array of Strings 
    #names = Array.new(5, [&quot;Damian&quot;,&quot;Rogelio&quot;,&quot;Carlos&quot;,&quot;Luis&quot;,&quot;Daniel&quot;])
    # or just 
    names = [&quot;Damian&quot;, 
      &quot;Rogelio&quot;, 
      &quot;Carlos&quot;, 
      &quot;Luis&quot;, 
      &quot;Daniel&quot;]

    print_array(names)   
    ordered_names = bubblesort(names)   
    print_array(ordered_names)

    # Multi-dimensional Array (Matrix row,column)   
    print_title(&quot;Transpose Matrix&quot;)   

    # for an empty table initialized to 0s
    # matrix = Array.new(rows,0) { Array.new(cols,0) }
    matrix = [[6, 4, 24],      
              [1, -9, 8]]

    print_matrix(matrix)
    transposed_matrix = transpose_matrix(matrix)   
    print_matrix(transposed_matrix)  
 
    # Jagged Array (Array-of-Arrays)   
    print_title(&quot;Upper Case Random Array &amp;amp; Graph Number of Elements&quot;)   

=begin
# Creating an array of string arrays using the String.Split method   
# instead of initializing it manually as follows:   
# 
# text = [    
#  [ [&quot;word1&quot;, &quot;word2, &quot;wordN&quot;],    
#  [ [&quot;word1&quot;, &quot;word2, &quot;wordN&quot;],    
#  ...
#  ]   
#     
# Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot;        
=end
    text = [
    &quot;Hoy es el dia mas hermoso de nuestra vida, querido Sancho;&quot;.split(&quot; &quot;),    
    &quot;los obstaculos mas grandes, nuestras propias indecisiones;&quot;.split(&quot; &quot;),    
    &quot;nuestro enemigo mas fuerte, miedo al poderoso y nosotros mismos;&quot;.split(&quot; &quot;),    
    &quot;la cosa mas facil, equivocarnos;&quot;.split(&quot; &quot;),    
    &quot;la mas destructiva, la mentira y el egoismo;&quot;.split(&quot; &quot;),    
    &quot;la peor derrota, el desaliento;&quot;.split(&quot; &quot;),    
    &quot;los defectos mas peligrosos, la soberbia y el rencor;&quot;.split(&quot; &quot;),    
    &quot;las sensaciones mas gratas, la buena conciencia...&quot;.split(&quot; &quot;)
    ] 
 
    print_jagged_array(text)   
    uppercase_random_array(text)      
    print_jagged_array(text)   
    graph_jagged_array(text)

    # Array Exceptions
    print_title(&#39;Common Array Exceptions&#39;)
    
    print_common_array_exceptions(nil)
    print_common_array_exceptions(text)  

    # Accessing Class Array Elements through Indexer
    print_title(&#39;Alphabets&#39;)
    
    vowels = Alphabet.new(5)
    vowels[0] = &quot;a&quot;
    vowels[1] = &quot;e&quot;
    vowels[2] = &quot;i&quot;
    vowels[3] = &quot;o&quot;
    vowels[4] = &quot;u&quot;

    puts &quot;\nVowels={%s}&quot; % [vowels[0],vowels[1],vowels[2],vowels[3],vowels[4]].join(&quot;,&quot;)

    en = Alphabet.new(&quot;abcdefghijklmnopqrstuvwxyz&quot;)   

    puts &quot;English Alphabet = {%s}&quot; % [en]

    puts &quot;Alphabet Extract en[9..19] = {%s}&quot; % [Alphabet.new(en.slice(9, 10))]

    word1 = [en[6],en[14],en[14],en[3]].join(&quot;&quot;)
    word2 = [en[1],en[24],en[4]].join(&quot;&quot;)   
    word3 = [en[4],en[21],en[4],en[17],en[24],en[14],en[13],en[4]].join(&quot;&quot;)   

    puts &quot;\n%s %s, %s!\n&quot; % [word1, word2, word3]
 
    gets
end

def reverse_char(arr)
    arr.reverse
end 

def bubblesort(arr)  
    for i in arr.reverse
        for j in (0..arr.count-2)
            if arr[j] &amp;gt; arr[j + 1]    
                swap = arr[j]   
                arr[j] = arr[j + 1]   
                arr[j + 1] = swap   
            end    
        end 
    end   
    arr
end

def transpose_matrix(m)  
=begin
# Transposing a Matrix 2,3  
#     
#   A =  [6  4 24]T [ 6  1]  
#        [1 -9  8]  [ 4 -9]  
#                [24  8]  
=end
    transposed = Array.new(m[0].size) { Array.new(m.size) } 
    for i in 0..(m.size-1)   
        for j in 0..(m[0].size-1)   
            transposed[j][i] = m[i][j]
        end
    end
    transposed  
end

def uppercase_random_array(arr)      
    r = System::Random.new
    i = r.next(arr.size)
    for j in 0..(arr[i].size-1)   
        arr[i][j] = arr[i][j].upcase
    end
end

def print_array(arr)
    puts &quot;\nPrint Array Content #{arr.GetType().Name}[#{arr.size}]&quot;
    for i in 0..(arr.size-1)
        puts &quot; array [%2s] = %2s&quot; % [i, arr[i]]
    end
end

def print_matrix(m)
    puts &quot;\nPrint Array Content #{m.GetType().Name}[#{m.size}][#{m[0].size}]&quot;
    for i in 0..(m.size-1)
        for j in 0..(m[0].size-1)
            puts &quot; array [%2s,%2s] = %2s&quot; % [i, j, m[i][j]]
        end
    end
    m
end

def graph_jagged_array(arr)
=begin
# When using Arrays, we can use for(each) instead of for by index
#    for s in arr  
#        for w in s 
#        end
#    end
=end 
    puts &quot;\nPrint Text Content #{arr.GetType().Name}&quot;
    for i in 0..(arr.size-1)  
        line = &quot;&quot;
        line += &quot;Line %2s|&quot; % (i+1).to_s 
        for j in 0..(arr[i].size-1)   
            line += &quot; * &quot;
        end            
        line += &quot;(#{arr[i].size})&quot;
        puts line
    end
end

def print_jagged_array(arr)
    puts &quot;\nPrint Jagged Array Content #{arr.GetType().Name}&quot;
    for i in 0..(arr.size-1)
        line = &quot;&quot;
        for j in 0..(arr[i].size-1)     
            line += &quot; &quot; + arr[i][j]
        end
        if line == line.upcase
            line += &quot; &amp;lt;-- [UPPERCASED]&quot;
        end
        puts line
    end
end

def print_common_array_exceptions(arr)
    begin  
        arr.fetch(100)
    rescue Exception =&amp;gt; ex
        puts &quot;\nException: \n%s\n%s&quot; % [ex.GetType().Name, ex.message]
    #else
    #   others
    end
end

def print_title(message)   
    puts &quot;&quot;  
    puts (&quot;=&quot; * 54)   
    puts message   
    puts (&quot;=&quot; * 54)
end     


class Alphabet
    # Array Field   
    @letters = []

    # Indexer Get/Set Property
    def [](idx)
        @letters[idx]
    end
    def []=(idx, value)
        @letters[idx] = value.upcase
    end
    
    # Read-Only Getter
    def length
        @letters.size
    end          

    # Constructor/Initializer
    def initialize(param)  
        if param.class == 1.class
            @letters = Array.new(param, &quot; &quot;)
        elsif param.class == &quot;&quot;.class
            @letters = param.upcase.chars.to_a
        elsif param.class == [].class
            @letters = param
        else
            @letters = nil
        end
    end

    # Overridden Method    
    def to_s
        @letters.join(&quot;,&quot;)
    end
 
    # Method   
    def slice(start, length)
        @letters[start..start+length-1]
    end

end

main
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoO8U1KfZt37DLzhP5V_QG7UbX2zg82KBC4UnjDwQtBQYDf1kdDxQgrfZCiQ-e1q9jW0yjCSJNhngg1sdE6gtHug_ts-QpKW7_kMYYKuNktnptz17knhyphenhyphenc67hugheEhlub9Mqo8ZdVWtY/s1600/RbArraysOutput.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoO8U1KfZt37DLzhP5V_QG7UbX2zg82KBC4UnjDwQtBQYDf1kdDxQgrfZCiQ-e1q9jW0yjCSJNhngg1sdE6gtHug_ts-QpKW7_kMYYKuNktnptz17knhyphenhyphenc67hugheEhlub9Mqo8ZdVWtY/s1600/RbArraysOutput.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/1834677321300848839/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2014/02/arrays-and-indexers-in-ironruby.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/1834677321300848839'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/1834677321300848839'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2014/02/arrays-and-indexers-in-ironruby.html' title='Arrays and Indexers in IronRuby'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoO8U1KfZt37DLzhP5V_QG7UbX2zg82KBC4UnjDwQtBQYDf1kdDxQgrfZCiQ-e1q9jW0yjCSJNhngg1sdE6gtHug_ts-QpKW7_kMYYKuNktnptz17knhyphenhyphenc67hugheEhlub9Mqo8ZdVWtY/s72-c/RbArraysOutput.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-7897377584478167823</id><published>2014-02-25T13:18:00.001-08:00</published><updated>2017-04-21T06:40:19.667-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="IronPython"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Arrays and Indexers in IronPython</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in IronPython. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in IronPython, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
This is the second post of a dynamic language. As with Phalanger&#39;s version of the program, code structure changed slightly from previous posts. Besides that, because you normally don&#39;t use Arrays per se in Python (except for numerical arrays when better performance is required), it is more practical to use Python&#39;s List object instead of .NET&#39;s System.Array, which can definitely be used in IronPython, specially when you need to inter operate with other CLS languages. You can even initialize a System.Array with a Python List like this:&amp;nbsp;System.Array[int]([1, 2, 3]).&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my most recent post, &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in Boo (or Cobra or Jython later on) just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: python&quot;&gt;import clr
clr.AddReference(&quot;System&quot;)
import System
from System import Random
 
# Console Program   
def main():   
    # Single-dimensional Array(s)   
    printtitle(&#39;Reverse Array Elements&#39;); 

    # Declare and Initialize Array (Python List) of Chars   
    # or letters = list(&#39;AEIOU&#39;)
    # or letters = 5 * [&#39; &#39;]      
    letters = list(&#39; &#39; * 5) # letters = []
    letters[0] = &#39;A&#39;        # letters.append(&#39;A&#39;)
    letters[1] = &#39;E&#39;        # letters.append(&#39;E&#39;)
    letters[2] = &#39;I&#39;        # letters.append(&#39;I&#39;)
    letters[3] = &#39;O&#39;        # letters.append(&#39;O&#39;)
    letters[4] = &#39;U&#39;        # letters.append(&#39;U&#39;)
    
    printarray(letters)
    inverse_letters = reversechar(letters)
    printarray(inverse_letters)

    printtitle(&#39;Sort Integer Array Elements&#39;)
    # Declare and Initialize Array of Integers   
    numbers = [10, 8, 3, 1, 5]
    
    printarray(numbers)   
    ordered_numbers = bubblesort(numbers)   
    printarray(ordered_numbers)

    printtitle(&#39;Sort String Array Elements&#39;)  

    # Declare and Initialize and Array of Strings   
    names = [&#39;Damian&#39;, &#39;Rogelio&#39;, &#39;Carlos&#39;, &#39;Luis&#39;, &#39;Daniel&#39;]

    printarray(names)   
    ordered_names = bubblesort(names)   
    printarray(ordered_names)

    # Multi-dimensional Array (Matrix row,column)   
    printtitle(&#39;Transpose Matrix&#39;)   

    matrix = [[6, 4, 24],      
              [1, -9, 8]]

    printmatrix(matrix)
    transposed_matrix = transposematrix(matrix)   
    printmatrix(transposed_matrix)  

    # Jagged Array (Array-of-Arrays)   
    printtitle(&#39;Upper Case Random Array &amp;amp; Graph Number of Elements&#39;)   

    &#39;&#39;&#39;
    Creating an array of string arrays using the String.Split method   
    instead of initializing it manually as follows:   
 
    $text = [    
        [ [&quot;word1&quot;, &quot;word2, &quot;wordN&quot;],    
        [ [&quot;word1&quot;, &quot;word2, &quot;wordN&quot;],    
        ...
    ]   
     
    Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot;        
    &#39;&#39;&#39;
    text = [
    &#39;Hoy es el dia mas hermoso de nuestra vida, querido Sancho;&#39;.split(&#39; &#39;),    
    &#39;los obstaculos mas grandes, nuestras propias indecisiones;&#39;.split(&#39; &#39;),    
    &#39;nuestro enemigo mas fuerte, miedo al poderoso y nosotros mismos;&#39;.split(&#39; &#39;),    
    &#39;la cosa mas facil, equivocarnos;&#39;.split(&#39; &#39;),    
    &#39;la mas destructiva, la mentira y el egoismo;&#39;.split(&#39; &#39;),    
    &#39;la peor derrota, el desaliento;&#39;.split(&#39; &#39;),    
    &#39;los defectos mas peligrosos, la soberbia y el rencor;&#39;.split(&#39; &#39;),    
    &#39;las sensaciones mas gratas, la buena conciencia...&#39;.split(&#39; &#39;)
    ]

    printjaggedarray(text)   
    uppercaserandomarray(text)   
    printjaggedarray(text)   
    graphjaggedarray(text)

    # Array Exceptions
    printtitle(&#39;Common Array Exceptions&#39;)
    
    printcommonarrayexceptions(None)   
    printcommonarrayexceptions(text)  

    # Accessing Class Array Elements through Indexer
    printtitle(&#39;Alphabets&#39;)  
    
    vowels = Alphabet(5)
    vowels[0] = &#39;a&#39;
    vowels[1] = &#39;e&#39;
    vowels[2] = &#39;i&#39;
    vowels[3] = &#39;o&#39;
    vowels[4] = &#39;u&#39;

    print &#39;\nVowels = {%s}&#39; % &#39;,&#39;.join([vowels[0],vowels[1],vowels[2],vowels[3],vowels[4]])

    en = Alphabet(&#39;abcdefghijklmnopqrstuvwxyz&#39;)   
    print &#39;English Alphabet = {%s}&#39; % (str(en))

    print &#39;Alphabet Extract en[9..19] = {%s}&#39; % (str(Alphabet(en.slice(9, 10))))
   
    word1 = &#39;&#39;.join([en[6], en[14], en[14], en[3]])
    word2 = &#39;&#39;.join([en[1], en[24], en[4]])   
    word3 = &#39;&#39;.join([en[4], en[21], en[4], en[17], en[24], en[14], en[13], en[4]])   
    print &quot;\n%s %s, %s!\n&quot; % (word1, word2, word3)  

    raw_input()

def reversechar(arr):
    return list(reversed(arr))
    # or 
    # return arr[::-1]
    # or 
    # reversedarr = [], i = 0
    # for j in range(len(arr) - 1,-1,-1):
    #   reversedarr[i] = arr[j]
    # return reversedarr
    #

def bubblesort(arr):
    for i in reversed(arr):   
        for j in range(len(arr) - 1):   
            if arr[j] &amp;gt; arr[j + 1]:   
                swap = arr[j]   
                arr[j] = arr[j + 1]   
                arr[j + 1] = swap   
    return arr

def transposematrix(m):   
    &#39;&#39;&#39; Transposing a Matrix 2,3  
     
     A =  [6  4 24]T [ 6  1]  
          [1 -9  8]  [ 4 -9]  
                     [24  8]  
    &#39;&#39;&#39;
    transposed = [len(m)*[0] for i in range(len(m[0]))]
    for i in range(len(m)):   
        for j in range(len(m[0])):   
        transposed[j][i] = m[i][j]
    return transposed  

def uppercaserandomarray(arr):   
    r = Random()   
    i = r.Next(len(arr))   
    for j in range(len(arr[i])):
        arr[i][j] = arr[i][j].upper()

def printarray(arr):
    print &#39;\nPrint Array Content &#39; + arr.GetType().Name.Replace(&#39;]&#39;, str(len(arr)) + &#39;]&#39;)
    for i in range(len(arr)):   
        print &#39; array [{0:2}&#39;.format(i) + &#39;] = {0:2}&#39;.format(arr[i])

def printmatrix(m):   
    print &#39;\nPrint Matrix Content &#39; + m.GetType().Name + &#39;[&#39; + str(len(m)) + &#39;,&#39; + str(len(m[0])) + &#39;]&#39;
    for i in range(len(m)):   
        for j in range(len(m[0])):   
            print &#39; array [{0:2},{1:2}] = {2:2} &#39;.format(i, j, m[i][j])

def graphjaggedarray(arr):   
    &#39;&#39;&#39;When using Arrays, we can use for(each) instead of for by index:
    for s as (string) in arr:  
        for w as string in s: 
    &#39;&#39;&#39; 
    print &#39;\nPrint Text Content &#39; + arr.GetType().Name  
    for i in range(len(arr)):   
        line = &#39;&#39;
        line += &#39;Line{0:2}|&#39;.format(i+1)
        for j in range(len(arr[i])):   
            line += &#39;{0:3}&#39;.format(&#39;*&#39;)   
        line += &#39;(&#39; + str(len(arr[i])) + &#39;)&#39;
        print line
        

def printjaggedarray(arr):
    print &#39;\nPrint Jagged Array Content &#39; + arr.GetType().Name
    for i in range(len(arr)):
        line = &#39;&#39;
        for j in range(len(arr[i])):      
            line += &#39; &#39; + arr[i][j]
        if line == line.upper():
            line += &#39; &amp;lt;-- [UPPERCASED]&#39;
        print line

def printcommonarrayexceptions(arr):
    try:
        arr[100][100] = &#39;hola&#39;     
    except System.Exception as ex:
        print &#39;\nException: \n%s\n%s&#39; % (ex.GetType().Name, ex.Message)
    #except:
    #else:

def printtitle(message):    
    print &#39;&#39;  
    print &#39;=&#39; * 54   
    print message   
    print &#39;=&#39; * 54 


class Alphabet:
    # Array Field   
    _letters = []
    
    # Indexer Get/Set Property
    def __getitem__(self, idx):
        return self._letters[idx]
    def __setitem__(self, idx, value):
        self._letters[idx] = str(value).upper()
    
    # Read-Only Property
    def get_Length(self):
        return len(self._letters)   
    Length = property(fget=get_Length)

    # Constructor
    def __init__(self, param=None):           
        if type(param) == type(1):
            self._letters = list(&#39; &#39; * param)
        elif type(param) == type(&#39;&#39;):
            self._letters = list(str(param).upper())
        elif type(param) == type([]):
            self._letters = param
        else:
            self._letters = None

    # Overridden Method    
    def __str__(self):
        return &#39;,&#39;.join(self._letters)

    # Method   
    def slice(self, start, length):
        return self._letters[start:start+length]

if __name__ == &#39;__main__&#39;:
    main()
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKIJ09Zh2ksMXfFzGIocsqOyHsl_tLx5U3dx1H91__mCINfoPahJdhsezkGgr5gjSBa5QpwFjQ8szzxo5ztiVaaF5yYrwPMvvjf2kJZj_13a3fg4K4ShOJ-cDoNXmve_hLpM9p4vYulFU/s1600/PyArraysOutput.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKIJ09Zh2ksMXfFzGIocsqOyHsl_tLx5U3dx1H91__mCINfoPahJdhsezkGgr5gjSBa5QpwFjQ8szzxo5ztiVaaF5yYrwPMvvjf2kJZj_13a3fg4K4ShOJ-cDoNXmve_hLpM9p4vYulFU/s1600/PyArraysOutput.png&quot;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/7897377584478167823/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2014/02/arrays-and-indexers-in-ironpython.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/7897377584478167823'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/7897377584478167823'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2014/02/arrays-and-indexers-in-ironpython.html' title='Arrays and Indexers in IronPython'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKIJ09Zh2ksMXfFzGIocsqOyHsl_tLx5U3dx1H91__mCINfoPahJdhsezkGgr5gjSBa5QpwFjQ8szzxo5ztiVaaF5yYrwPMvvjf2kJZj_13a3fg4K4ShOJ-cDoNXmve_hLpM9p4vYulFU/s72-c/PyArraysOutput.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-3329318310560296976</id><published>2014-02-22T16:52:00.001-08:00</published><updated>2014-02-22T16:54:51.061-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="Zonnon"/><title type='text'>Arrays and Indexers in Zonnon</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in Zonnon. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Zonnon, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my most recent post, &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in C# and Oxygene just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on Zonnon Builder and run it. &lt;br /&gt;
&lt;br /&gt;
Last thing. There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;delphi&quot; name=&quot;code&quot;&gt;
(*****************************************
String Utilities Module
*****************************************)

module Str;

type {private} MArrayOfChar = array {math} * of char;
type {private} ArrayOfChar = array * of char;
type {private} ArrayOfString = array * of string;

procedure {public} CountWords(s: array * of char; sep: char): integer;
var i,slen,wlen,c: integer;
begin
  slen := len(s)-1;
  c := 0;
  for i := 0 to slen do
 wlen := 0;
 while (i &amp;lt; slen) &amp;amp; (s[i] # sep) do inc(wlen); inc(i); end;
 if (i &amp;lt;= slen) &amp;amp; (wlen &amp;gt; 0) then inc(c) end; 
  end;
  return c;
end CountWords;

procedure {public} Split(s: string; sep: char)
 : array * of string;
var i,j,k,slen,wlen,pos: integer;
 l: array * of char;
 a: array * of string;
begin
  l := new ArrayOfChar(len(s)+1);
  copy(s, l);
  slen := len(l)-1;
  a := new ArrayOfString(CountWords(l,sep));
  pos := 0; k := 0;
  for i := 0 to slen do
 wlen := 0;
 while (i &amp;lt; slen) &amp;amp; (l[i] # sep) do inc(wlen); inc(i); end;
 if (i &amp;lt;= slen) &amp;amp; (wlen &amp;gt; 0) then 
   if (i &amp;lt;= slen) then a[k] := s.Substring(pos,wlen); inc(k) end;
   for j := 0 to wlen do inc(pos) end;
 end; 
  end;
  return a;
end Split;

procedure {public} Join(c: char; arr: array {math} * of char): string;
var i: integer;
 s: string;
begin
  s := &amp;quot;&amp;quot;;
  for i := 0 to len(arr) - 1 do
    s := s + string(arr[i]) + string(c);
  end;
  if len(s) == 0 then return s end;
  return s.Substring(0,s.LastIndexOf(c));
end Join;

end Str.

(*****************************************
Alphabet Object
*****************************************)

object {ref} Alphabet(asize: integer; astr: string; achar: array * of char) 
 implements [];

import Str;

type {private} ArrayOfChar = array * of char;
type {private} ArrayOfString = array * of string;

(* Array Field *) 
var {private} letters: array {math} * of char;  

(* Indexer Get/Set Property *)
procedure {public} Get(i: integer): char implements [].Get;
begin 
  return self.letters[i];
end Get;
procedure {public} Set(i: integer; c: char) implements [].Set;
var s: string;
begin
  s := string(c); 
  if ~(s = s.ToUpper()) then s := s.ToUpper(); c := s[0] end;
  self.letters[i] := c; 
end Set;

(* No Property, Getter instead *)
procedure {public} GetLength: integer; 
begin 
  return len(self.letters); 
end GetLength;  

(* Override Method *)
procedure {public} ToString: string implements System.Object.ToString;
begin
  return Str.Join(char(&#39;,&#39;), self.letters);
end ToString;

(* Method *)
procedure {public} Slice(start: integer; length: integer)
  : array  * of char;
var l: integer;
 a: array  * of char;
begin
  a := new ArrayOfChar(len(self.letters));
  a := self.letters[start..length-1];
  return a;
end Slice;

(* No Overloaded Constructors Support in v 1.3.0 *)
(* Contructor | Initializer *) 
begin   
  if asize # 0 then
    self.letters := new ArrayOfChar(asize);
  elsif astr # nil then
    self.letters := new ArrayOfChar(len(astr));
    copy(astr.ToUpper(),self.letters);
  elsif achar # nil then
    self.letters := achar;
  else
    self.letters := new ArrayOfChar(0);  
  end;  
end Alphabet.


(*****************************************
Program Module
*****************************************)

module Main;  
import System.Random as Random,
 Str, Alphabet;

type {private} ArrayOfChar = array * of char;
type {private} ArrayOfString = array * of string;
type {private} ArrayMatrix = array {math} *,* of integer;
type {private} JaggedArrayOfString = array * of array * of string;


procedure ReverseChar(var arr: array * of char)
 : array * of char;
var 
  reversed: array * of char; 
  i,j: integer;
begin
  i := 0;
  reversed := new ArrayOfChar(len(arr));
  for j := len(arr,0)-1 to 0 by -1 do  
    reversed[i] := arr[j];  
    inc(i);
  end;
  return reversed;
end ReverseChar;

procedure BubbleSortInt(var arr: array {math} * of integer)
 : array {math} * of integer;   
var i, j, swap: integer;  
begin  
  swap := 0;  
  for i := len(arr) - 1 to 1 by -1 do  
    for j := 0 to i - 1 do  
      if arr[j] &amp;gt; arr[j + 1] then  
        swap := arr[j];    
        arr[j] := arr[j + 1];    
        arr[j + 1] := swap;   
      end;  
    end;  
  end;  
  return arr;  
end BubbleSortInt;  

procedure BubbleSortString(var arr: array * of string)
 : array * of string;   
var 
  i, j: integer;  
  swap: string;
begin  
  swap := &amp;quot;&amp;quot;;  
  for i := len(arr) - 1 to 1 by -1 do  
    for j := 0 to i - 1 do  
      if arr[j,0] &amp;gt; arr[j + 1,0] then  
        swap := arr[j];    
        arr[j] := arr[j + 1];    
        arr[j + 1] := swap;   
      end;  
    end;  
  end;  
  return arr;  
end BubbleSortString; 

procedure TransposeMatrix(m: array {math} *,* of integer)
 : array {math} *,* of integer;  
var   
  i, j: integer;
  transposed: array {math} *,* of integer;    
begin  
  (* Transposing a Matrix 2,3   
   *   
   * A =  [6  4 24]T [ 6  1]   
   *      [1 -9  8]  [ 4 -9]  
   *                 [24  8]  
   *)    
  transposed := new ArrayMatrix(len(m, 1), len(m, 0));
  for i := 0 to len(m,0) - 1 do 
    for j := 0 to len(m,1) - 1 do 
      transposed[j, i] := m[i, j];    
    end;  
  end;  
  return transposed;  
end TransposeMatrix;  

procedure UpperCaseRandomArray(arr: array * of array * of string); 
var r: Random; 
 i,j: integer;
 s: string; 
begin 
  r := new Random; 
  i := r.Next(0, len(arr) - 1); 
  for j := 0 to len(arr[i]) - 1 do 
 s := arr[i,j];
    arr[i,j] := s.ToUpper();
  end; 
end UpperCaseRandomArray; 

procedure PrintArrayChar(var arr: array * of char);
begin
  writeln(&amp;quot;Print Array Content Char[&amp;quot;:0,string(len(arr)):0,&amp;quot;]&amp;quot;:0);
  for i := 0 to len(arr, 0) - 1 do
    writeln(&amp;quot; array [&amp;quot;,i:2,&amp;quot;] = &amp;quot;,arr[i]:2,&amp;quot; &amp;quot;);
  end;
  writeln;
end PrintArrayChar;

procedure PrintArrayInt(var arr: array {math} * of integer);
begin
  writeln(&amp;quot;Print Array Content Int32[&amp;quot;:0, string(len(arr)):0, &amp;quot;]&amp;quot;:0);
  for i := 0 to len(arr, 0) - 1 do
    writeln(&amp;quot; array [&amp;quot;,i:2,&amp;quot;] = &amp;quot;,arr[i]:2,&amp;quot; &amp;quot;);
  end;
  writeln;
end PrintArrayInt;

procedure PrintArrayString(var arr: array * of string);
begin
  writeln(&amp;quot;Print Array Content String[&amp;quot;:0, string(len(arr)):0, &amp;quot;]&amp;quot;:0);
  for i := 0 to len(arr, 0) - 1 do
    writeln(&amp;quot; array [&amp;quot;,i:2,&amp;quot;] = &amp;quot;,arr[i]:2,&amp;quot; &amp;quot;);
  end;
  writeln;
end PrintArrayString;

procedure PrintMatrix(m: array {math} *,* of integer);   
var i,j: integer;
begin  
  writeln(&amp;quot;Print Matrix Content Int32[&amp;quot;:0, string(len(m,0)):0, &amp;quot;,&amp;quot;:0, string(len(m,1)):0, &amp;quot;]&amp;quot;:0); 
  
  for i := 0 to len(m,0) - 1 do 
    for j := 0 to len(m,1) - 1 do  
   writeln(&amp;quot; array [&amp;quot;:0,i:2,j:2,&amp;quot;] = &amp;quot;,m[i, j]:2,&amp;quot; &amp;quot;:0);
    end;  
  end;   
  writeln;
end PrintMatrix;  

procedure GraphJaggedArray(arr: array * of array * of string); 
var lineCount: integer; 
 i,j: integer;
begin
  writeln;
  writeln(&amp;quot;Print Text Content String[][]&amp;quot;:0); 
  lineCount := 1; 
  for i := 0 to len(arr) - 1 do 
    write(&amp;quot;Line&amp;quot;:0,lineCount:2,&amp;quot;|&amp;quot;:0); 
 for j := 0 to len(arr[i]) - 1 do 
      write(&amp;quot;*&amp;quot;:3);
    end; 
    writeln(&amp;quot; (&amp;quot;:0,string(len(arr[i])):0,&amp;quot;)&amp;quot;:0); 
    inc(lineCount);
  end; 
  writeln;
end GraphJaggedArray; 

procedure PrintJaggedArray(arr: array * of array * of string); 
var i,j: integer;
 line: string; 
 linearr: array * of string;
begin 
  writeln;
  writeln(&amp;quot;Print Jagged Array Content String[][]&amp;quot;:0); 
  for i := 0 to len(arr) - 1 do 
    line := &amp;quot;&amp;quot;;
    for j := 0 to len(arr[i]) - 1 do 
      line := line + &amp;quot; &amp;quot; + arr[i,j];   
    end; 
    if line = line.ToUpper() then 
   line := line + &amp;quot; &amp;lt;-- [UPPERCASED]&amp;quot;; 
    end; 
    writeln(line:0);
  end; 
end PrintJaggedArray; 

procedure PrintCommonArrayExceptions(arr: array * of array * of string); 
(* 
&amp;quot;Extra information about the exception can be accessed 
by calling the predefined function &#39;reason&#39;. This causes the 
runtime system to return a string which explains the reason 
for the exception.&amp;quot; Not working in Zonnon version 1.3.0
var s: string;
do ... on exception do
s := reason; &amp;lt;- This gives a &amp;quot;reason not declared&amp;quot; error at compile time.
end; 
*)
begin 
  do 
    arr[100,100] := &#39;hola&#39;; 
  on NilReference do
    writeln;
    writeln(&amp;quot;Exception: NilReference&amp;quot;:0);
  on OutOfRange do
    writeln;
    writeln(&amp;quot;Exception: OutOfRange&amp;quot;:0);
  on exception do  
    writeln;
    writeln(&amp;quot;Exception: Other&amp;quot;:0); 
  on termination do
    (* nothing *)
  end; 
  writeln;
end PrintCommonArrayExceptions; 

procedure PrintTitle(message: string);   
begin  
  writeln(&#39;======================================================&#39;:0);
  writeln(message:0);
  writeln(&#39;======================================================&#39;:0);
  writeln;
end PrintTitle;  

var
(*writeln(pos,wlen,Substring(s,pos,wlen),s.Substring(pos,wlen));*)
  i: integer;
  (* Declare Array of Chars *)
  letters: array 5 of char;
  inverse_letters: array * of char;

  (* Mathematical extensions
  Mathematical extensions of Zonnon let use arrays in a more convenient way 
  for writing applications where multidimensional algebra is used. 
  Arrays to be used in mathematical extensions should be defined with special
  {math} modifier. ArrayType = array &amp;quot;{&amp;quot; math &amp;quot;}&amp;quot; Length {&amp;quot;,&amp;quot; Length} of Type.
  This option allow you to initialize math array with array expressions, 
  but it only works for numerical arrays such as 
  array {math} of integer | real | boolean but not of string.
  *)

  (* Declare Array of Integers *)
  numbers, ordered_numbers: array {math} * of integer;
  (* Declare Array of Strings *)
  names: array 5 of string;
  ordered_names: array * of string;
  (* Declare multi-dimensional Array *)
  matrix: array {math} 2, 3 of integer;
  transposed_matrix: array {math} *,* of integer;
  (* Declare Jagged Array *)
  text: array * of array * of string;
  (* Indexer *)
  vowels,en,na: Alphabet;
  vs,w: array {math} * of char;
  word1,word2,word3: string;
begin  
  (* Single-dimensional Array(s) *)
  PrintTitle(&amp;quot;Reverse Array Elements&amp;quot;); 

  (* Initialize Array of Chars  *)
  letters[0] := &#39;A&#39;;
  letters[1] := &#39;E&#39;;  
  letters[2] := &#39;I&#39;;  
  letters[3] := &#39;O&#39;;  
  letters[4] := &#39;U&#39;; 

  PrintArrayChar(letters);   
  inverse_letters := ReverseChar(letters);    
  PrintArrayChar(inverse_letters); 
  
  PrintTitle(&amp;quot;Sort Integer Array Elements&amp;quot;);  

  (* Initialize Math Array of Integers *)
  numbers := [ 10, 8, 3, 1, 5];    
  PrintArrayInt(numbers);
  ordered_numbers := BubbleSortInt(numbers);    
  PrintArrayInt(ordered_numbers);
  
  PrintTitle(&amp;quot;Sort String Array Elements&amp;quot;);    
    
  (* Initialize Array of Strings *)
  names[0] := &amp;quot;Damian&amp;quot;;     
  names[1] := &amp;quot;Rogelio&amp;quot;; 
  names[2] := &amp;quot;Carlos&amp;quot;;     
  names[3] := &amp;quot;Luis&amp;quot;;               
  names[4] := &amp;quot;Daniel&amp;quot;;    
  PrintArrayString(names);  
  ordered_names := BubbleSortString(names);     
  PrintArrayString(ordered_names);

  (* Multi-dimensional Array (Matrix row,column) *)
    
  PrintTitle(&amp;quot;Transpose Matrix&amp;quot;);    
    
  (* Matrix row=2,col=3  
   * A =  [6  4 24]  
   *      [1 -9  8]  
  *)    
  (* Array inline expression used to declare and initialize array *)
  matrix := [[6, 4, 24], 
    [1, -9, 8]];   

  PrintMatrix(matrix);    
  transposed_matrix := TransposeMatrix(matrix);    
  PrintMatrix(transposed_matrix);
  
  (* Jagged Array (Array-of-Arrays) *)
    
  PrintTitle(&amp;quot;Upper Case Random Array &amp;amp; Graph Number of Elements&amp;quot;);
  
  (*
  * Creating an array of System.String arrays using the (System.)String.Split method
  *
  * Text extract from: &#39;El ingenioso hidalgo don Quijote de la Mancha&#39;  
  *   
  *)
  text := new JaggedArrayOfString(8,0);
  text[0] := Str.Split(&amp;quot;Hoy es el di&amp;Acirc;&amp;shy;a mas hermoso de nuestra vida, querido Sancho;&amp;quot;, &#39; &#39;);
  text[1] := Str.Split(&amp;quot;los obstaculos mas grandes, nuestras propias indecisiones;&amp;quot;, &#39; &#39;);
  text[2] := Str.Split(&amp;quot;nuestro enemigo mas fuerte, miedo al poderoso y nosotros mismos;&amp;quot;, &#39; &#39;);
  text[3] := Str.Split(&amp;quot;la cosa mas facil, equivocarnos;&amp;quot;, &#39; &#39;);
  text[4] := Str.Split(&amp;quot;la mas destructiva, la mentira y el egoi&amp;Acirc;&amp;shy;smo;&amp;quot;, &#39; &#39;);
  text[5] := Str.Split(&amp;quot;la peor derrota, el desaliento;&amp;quot;, &#39; &#39;);
  text[6] := Str.Split(&amp;quot;los defectos mas peligrosos, la soberbia y el rencor;&amp;quot;, &#39; &#39;);
  text[7] := Str.Split(&amp;quot;las sensaciones mas gratas, la buena conciencia...&amp;quot;, &#39; &#39;);

  PrintJaggedArray(text);
  UpperCaseRandomArray(text); 
  PrintJaggedArray(text); 
  GraphJaggedArray(text);

  (* Array Exceptions *)

  PrintTitle(&amp;quot;Common Array Exceptions&amp;quot;); 

  PrintCommonArrayExceptions(nil); 
  PrintCommonArrayExceptions(text);  

  (* Accessing Class Array Elements through Indexer *) 

  PrintTitle(&amp;quot;Alphabets&amp;quot;); 

  vowels := new Alphabet(5,nil,nil); 
  vowels[0] := char(&#39;a&#39;); 
  vowels[1] := char(&#39;e&#39;); 
  vowels[2] := char(&#39;i&#39;); 
  vowels[3] := char(&#39;o&#39;); 
  vowels[4] := char(&#39;u&#39;);

  vs := new ArrayOfChar(5);
  vs[0] := vowels[0]; vs[1] := vowels[1]; 
  vs[2] := vowels[2]; vs[3] := vowels[3]; 
  vs[4] := vowels[4];
  
  writeln;
  writeln(&amp;quot;Vowels = {&amp;quot;:0, Str.Join(&#39;,&#39;, vs):0, &amp;quot;}&amp;quot;:0);

  en := new Alphabet(0,&#39;abcdefghijklmnopqrstuvwxyz&#39;,nil);
  writeln(&amp;quot;English Alphabet = {&amp;quot;:0,en.ToString(),&amp;quot;}&amp;quot;:0);  
  
  na := new Alphabet(0,nil,en.Slice(9, 19));
  writeln(&amp;quot;Alphabet Extract en[9..19] = {&amp;quot;:0,na.ToString():0,&amp;quot;}&amp;quot;:0);             

  w := new ArrayOfChar(5); 
  w[0] := en[6]; w[1] := en[14]; w[2] := en[14]; w[3] := en[3];
  copy(w, word1);

  w := new ArrayOfChar(4); 
  w[0] := en[1]; w[1] := en[24]; w[2] := en[4];
  copy(w, word2);
  
  w := new ArrayOfChar(9); 
  w[0] := en[4]; w[1] := en[21]; w[2] := en[4]; w[3] := en[17]; 
  w[4] := en[24]; w[5] := en[14]; w[6] := en[13]; w[7] := en[4];
  copy(w, word3);

  writeln;
  writeln(word1:0, &amp;quot; &amp;quot;:0, word2:0, &amp;quot;, &amp;quot;:0, word3:0, &amp;quot;!&amp;quot;:0); 
  writeln;

  readln; 
end Main.
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4PoCdlTmnVhyphenhyphen-QVyH-LVDteVE2Q_8Vz9HNrgePfUWiQETqIlyuf32XF6mpgXOzyHz02JgJ_-DCoCL2078w1B-qjluOmSJo_h8kKkiuvM7klI6PVtmhfhyLKKjAureBMpYFJcxPb0eUsw/s1600/ZnnArraysOutput.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4PoCdlTmnVhyphenhyphen-QVyH-LVDteVE2Q_8Vz9HNrgePfUWiQETqIlyuf32XF6mpgXOzyHz02JgJ_-DCoCL2078w1B-qjluOmSJo_h8kKkiuvM7klI6PVtmhfhyLKKjAureBMpYFJcxPb0eUsw/s1600/ZnnArraysOutput.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/3329318310560296976/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2014/02/arrays-and-indexers-in-zonnon.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/3329318310560296976'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/3329318310560296976'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2014/02/arrays-and-indexers-in-zonnon.html' title='Arrays and Indexers in Zonnon'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4PoCdlTmnVhyphenhyphen-QVyH-LVDteVE2Q_8Vz9HNrgePfUWiQETqIlyuf32XF6mpgXOzyHz02JgJ_-DCoCL2078w1B-qjluOmSJo_h8kKkiuvM7klI6PVtmhfhyLKKjAureBMpYFJcxPb0eUsw/s72-c/ZnnArraysOutput.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-2738882324274585357</id><published>2013-11-19T09:25:00.000-08:00</published><updated>2013-11-19T11:23:03.961-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="Cobra"/><title type='text'>Arrays and Indexers in Cobra</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in Cobra. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Cobra, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my most recent post, &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in C# and C++ just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;python&quot; name=&quot;code&quot;&gt;
use System.Text

namespace CobraArrays

class Program is public
    shared   
        def main
            # Single-dimensional Array(s)  
            .printTitle(&amp;quot;Reverse Array Elements&amp;quot;)
            
            # Declare and initialize Array of Chars 
            letters as char[] = char[](5)
            letters[0] = c&#39;A&#39;  
            letters[1] = c&#39;E&#39;  
            letters[2] = c&#39;I&#39;  
            letters[3] = c&#39;O&#39;  
            letters[4] = c&#39;U&#39;
            
            .printArrayChar(letters)  
            inverse_letters as char[] = .reverseChar(letters)  
            .printArrayChar(inverse_letters)
        
            .printTitle(&amp;quot;Sort Integer Array Elements&amp;quot;)  

            # Declare and Initialize Array of Integers  
            numbers as int[] = @[10, 8, 3, 1, 5]
            .printArrayInt(numbers)  
            ordered_numbers as int[] = .bubblesortInt(numbers)  
            .printArrayInt(ordered_numbers)  

            .printTitle(&amp;quot;Sort String Array Elements&amp;quot;)  

            # Declare and Initialize and Array of Strings  
            names as String[] = @[   
                &#39;Damian&#39;, 
                &#39;Rogelio&#39;,   
                &#39;Carlos&#39;, 
                &#39;Luis&#39;, 
                &#39;Daniel&#39;  
            ]  
            .printArrayString(names)  
            ordered_names as String[] = .bubblesortString(names)  
            .printArrayString(ordered_names)  

            # Multi-dimensional Array (Matrix row,column) 
            # Cobra does not support multi-dimensional arrays syntax            
            # using List&amp;lt;of List&amp;lt;of Type&amp;gt;&amp;gt; instead
            .printTitle(&amp;quot;Transpose Matrix&amp;quot;)  

            /# Matrix row=2,col=3   
            # A =  [6  4 24]   
            #      [1 -9  8]   
            #/               
            matrix as List&amp;lt;of List&amp;lt;of int&amp;gt;&amp;gt; = [[6, 4, 24],
                                                [1, -9, 8]]            

            .printMatrix(matrix)  
            transposed_matrix as List&amp;lt;of List&amp;lt;of int&amp;gt;&amp;gt; = .transposeMatrix(matrix)  
            .printMatrix(transposed_matrix)  
        
            # Jagged Array (Array-of-Arrays)  
            .printTitle(&amp;quot;Upper Case Random Array &amp;amp; Graph Number of Elements&amp;quot;)  

            /#               
            # Creating an array of string arrays using the String.Split method  
            # instead of initializing it manually as follows:  
            #   
            # text as String[] = @[   
            #      @[ &#39;word1&#39;, &#39;word2&#39;, &#39;wordN&#39; ],   
            #      @[ &#39;word1&#39;, &#39;word2&#39;, &#39;wordM&#39; ],   
            #      ...  
            #      ]  
            #   
            # Text extract from: &amp;quot;El ingenioso hidalgo don Quijote de la Mancha&amp;quot;  
            #   
            #/  
            text = [ _
            &amp;quot;Hoy es el d&amp;Atilde;&amp;shy;a m&amp;Atilde;&amp;iexcl;s hermoso de nuestra vida, querido Sancho;&amp;quot;.split(c&#39; &#39;),   
            &amp;quot;los obst&amp;Atilde;&amp;iexcl;culos m&amp;Atilde;&amp;iexcl;s grandes, nuestras propias indecisiones;&amp;quot;.split(c&#39; &#39;),
            &amp;quot;nuestro enemigo m&amp;Atilde;&amp;iexcl;s fuerte, miedo al poderoso y nosotros mismos;&amp;quot;.split(c&#39; &#39;),
            &amp;quot;la cosa m&amp;Atilde;&amp;iexcl;s f&amp;Atilde;&amp;iexcl;cil, equivocarnos;&amp;quot;.split(c&#39; &#39;),
            &amp;quot;la m&amp;Atilde;&amp;iexcl;s destructiva, la mentira y el ego&amp;Atilde;&amp;shy;smo;&amp;quot;.split(c&#39; &#39;),
            &amp;quot;la peor derrota, el desaliento;&amp;quot;.split(c&#39; &#39;),
            &amp;quot;los defectos m&amp;Atilde;&amp;iexcl;s peligrosos, la soberbia y el rencor;&amp;quot;.split(c&#39; &#39;),
            &amp;quot;las sensaciones m&amp;Atilde;&amp;iexcl;s gratas, la buena conciencia...&amp;quot;.split(c&#39; &#39;)
            ]
            
            .printJaggedArray(text)  
            /#
            .uppercaserandomArray(text)  
            #/
            .printJaggedArray(text)  
            .graphJaggedArray(text)  
            
            # Array Exceptions  
            .printTitle(&amp;quot;Common Array Exceptions&amp;quot;)  

            .printCommonArrayExceptions(nil)  
            .printCommonArrayExceptions(text)  

            # Accessing Class Array Elements through Indexer      
            .printTitle(&amp;quot;Alphabets&amp;quot;)  
            
            vowels as Alphabet = Alphabet(5)  
            vowels[0] = c&#39;a&#39;  
            vowels[1] = c&#39;e&#39;  
            vowels[2] = c&#39;i&#39;  
            vowels[3] = c&#39;o&#39;  
            vowels[4] = c&#39;u&#39;  

            print &amp;quot;\nVowels = {&amp;quot; + [vowels[0], vowels[1], vowels[2], 
                                vowels[3], vowels[4]].join(&amp;quot;,&amp;quot;) + &amp;quot;}&amp;quot;  

            en as Alphabet = Alphabet(&amp;quot;abcdefghijklmnopqrstuvwxyz&amp;quot;)  
            print &amp;quot;English Alphabet = {[en.toString]}&amp;quot;  

            print &amp;quot;Alphabet Extract en\[9..19\] = {[Alphabet(en.slice(9, 10))]}&amp;quot;

            word1 as String = [en[6], en[14], en[14], en[3]].join(&#39;&#39;)  
            word2 as String = [en[1], en[24], en[4]].join(&#39;&#39;)
            word3 as String = [en[4], en[21], en[4], en[17], en[24],   
                                en[14], en[13], en[4]].join(&#39;&#39;)
            print &amp;quot;\n[word1] [word2], [word3]!&amp;quot;  

            Console.read
        
        def reverseChar(arr as char[]) as char[]
            reversed as char[] = char[](arr.length)  
            i as int = 0  
            for j in arr.length-1:-1:-1
                reversed[i] = arr[j]  
                i += 1
            return reversed
            
        def bubblesortInt(arr as int[]) as int[]  
            swap as int = 0  
            for i in arr.length-1:-1:-1  
                for j in arr.length-1
                    if arr[j] &amp;gt; arr[j + 1]
                        swap = arr[j]  
                        arr[j] = arr[j + 1]  
                        arr[j + 1] = swap  
            return arr 
            
        def bubblesortString(arr as String[]) as String[]
            swap as String = &amp;quot;&amp;quot;  
            for i in arr.length-1:-1:-1  
                for j in arr.length-1
                    if arr[j][0] &amp;gt; arr[j + 1][0]
                        swap = arr[j]  
                        arr[j] = arr[j + 1]  
                        arr[j + 1] = swap  
            return arr 
        
        def transposeMatrix(m as List&amp;lt;of List&amp;lt;of int&amp;gt;&amp;gt;) as List&amp;lt;of List&amp;lt;of int&amp;gt;&amp;gt;
            /# Transposing a Matrix 2,3   
            #   
            # A =  [6  4 24]T [ 6  1]   
            #      [1 -9  8]  [ 4 -9]  
            #                 [24  8]  
            #/ 
            transposed = [[0]] # to get [int] instead of [object]
            transposed.clear
            for i in 0:m[0].count
                transposed.add([0]) # same here
                transposed[i].clear
                for j in 0:m.count    
                    transposed[i].add(m[j][i])
            return transposed        
        
        def printArrayChar(arr as char[]) 
            print &amp;quot;\nPrint Array Content &amp;quot; + arr.getType.name.replace(&#39;]&#39;, _
                arr.length.toString + &#39;]&#39;)
            for i in arr.length
                print &amp;quot; array &amp;quot; + String.format(&amp;quot;[[{0,2}]] = {1,2}&amp;quot;, i, arr[i])
                
        def printArrayInt(arr as int[]) 
            print &amp;quot;\nPrint Array Content &amp;quot; + arr.getType.name.replace(&#39;]&#39;, _
                arr.length.toString + &#39;]&#39;)
            for i in arr.length
                print &amp;quot; array &amp;quot; + String.format(&amp;quot;[[{0,2}]] = {1,2}&amp;quot;, i, arr[i])
        
        def printArrayString(arr as String[]) 
            print &amp;quot;\nPrint Array Content &amp;quot; + arr.getType.name.replace(&#39;]&#39;, _
                arr.length.toString + &#39;]&#39;)
            for i in arr.length
                print &amp;quot; array &amp;quot; + String.format(&amp;quot;[[{0,2}]] = {1,2}&amp;quot;, i, arr[i])
        
        def printMatrix(m as List&amp;lt;of List&amp;lt;of int&amp;gt;&amp;gt;)
            print &amp;quot;\nPrint Matrix Content &amp;quot; + m.getType.name 
            for i in 0:m.count 
                for j in 0:m[0].count  
                    print &amp;quot; array &amp;quot; + String.format(&amp;quot;[[{0,2},{1,2}]] = {2,2} &amp;quot; _ 
                        , i, j, m[i][j])
        
        def graphJaggedArray(arr as List&amp;lt;of String[]?&amp;gt;)  
            /# When using Arrays, we can use for(each) instead of for by index:         
            #    
            # for s in arr: 
            #   for w as String in s 
            #    
            #/  
            print &amp;quot;\nPrint Text Content [arr.getType.name]&amp;quot;  
            for i in arr.count  
                Console.write(&amp;quot;Line{0,2}|&amp;quot;, i+1)
                for j in arr[i].length  
                    Console.write(&amp;quot;{0,3}&amp;quot;, &amp;quot;*&amp;quot;)
                print &amp;quot; ([arr[i].length.toString])&amp;quot;  
        
        def printJaggedArray(arr as List&amp;lt;of String[]?&amp;gt;)  
            line as StringBuilder?      
            print &amp;quot;\nPrint Jagged Array Content [arr.getType.name]&amp;quot;
            for i in arr.count
                line = StringBuilder() 
                for j in arr[i].length
                    line.append(&amp;quot; &amp;quot; + arr[i][j])
                if line.toString == line.toString.toUpper  
                    line.append(r&amp;quot; &amp;lt;-- [UPPERCASED]&amp;quot;)  
                print line.toString
        
        def printCommonArrayExceptions(arr as List&amp;lt;of String[]?&amp;gt;?)  
            try  
                arr[100][100] = &amp;quot;hola&amp;quot;    
            catch ex as Exception      
                print &amp;quot;\nException: \n[ex.getType.name]\n[ex.message]&amp;quot;  
        
        def printTitle(message as String) 
            print &amp;quot;&amp;quot;
            print &amp;quot;======================================================&amp;quot;
            print message
            print &amp;quot;======================================================&amp;quot;
    
class Alphabet is public
    # Array Field
    var _letters as char[]? is private
    
    # Indexer Get/Set Property  
    pro [index as int] as char is public
        get
            return _letters[index]
        set
            _letters[index] = value.toUpper
            
    # Read-Only Property  
    get length as int is public
        return _letters.length
    
    # Constructors
    cue init(size as int) is public  
        base.init  
        _letters = char[](size)
    
    cue init(list as String) is public
        base.init
        _letters = list.toUpper.toCharArray
    
    cue init(list as char[]) is public
        base.init
        _letters = list
    
    # Overridden Method    
    def toString as String is override
        return &amp;quot;&amp;quot; + _letters.join(&#39;,&#39;)

    # Method 
    def slice(start as int, length as int) as char[]?
        return _letters[start:start+length]
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8MbWW2ZrV4M8dshGAiXd-p3e6pj76_YrmBNNBWCOOWKDjq-9mUMeuBx1CVVz9FoMpGXz1EuDP5nHs5dSHnysIXV01O0zyTwVINuBPhl3uP5Zpn_TOE56__tt1FZ9s0qFr285-kt7uxN0/s1600/cobraarraysoutput.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8MbWW2ZrV4M8dshGAiXd-p3e6pj76_YrmBNNBWCOOWKDjq-9mUMeuBx1CVVz9FoMpGXz1EuDP5nHs5dSHnysIXV01O0zyTwVINuBPhl3uP5Zpn_TOE56__tt1FZ9s0qFr285-kt7uxN0/s1600/cobraarraysoutput.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/2738882324274585357/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2013/11/arrays-and-indexers-in-cobra.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/2738882324274585357'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/2738882324274585357'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2013/11/arrays-and-indexers-in-cobra.html' title='Arrays and Indexers in Cobra'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8MbWW2ZrV4M8dshGAiXd-p3e6pj76_YrmBNNBWCOOWKDjq-9mUMeuBx1CVVz9FoMpGXz1EuDP5nHs5dSHnysIXV01O0zyTwVINuBPhl3uP5Zpn_TOE56__tt1FZ9s0qFr285-kt7uxN0/s72-c/cobraarraysoutput.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-7245681699888808648</id><published>2013-10-27T08:02:00.000-07:00</published><updated>2016-09-05T05:54:18.255-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="Phalanger"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><title type='text'>Arrays and Indexers in Phalanger</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in Phalanger (PHP). Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Phalanger (PHP), in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
This is the first post of a &quot;dynamic&quot; language implemented for the DLR. You will notice that the code structure its slightly different from previous posts. Besides that, because Phalanger is PHP, it is definitely better to use PHP&#39;s array type instead of System\Array, implemented in Phalanger as PhpArray which at the end, stores the data as a Dictionary&amp;lt;object,object&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my most recent post, &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in C# and C++ just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;php&quot; name=&quot;code&quot;&gt;&amp;lt;?php
namespace PhpArrays 
{    
    use System as S;
    use System\Console;
    use System\Random;
    use System\Text as T;
    
    class Program
    {
        static function Main()
        {            
            /* 
             * An array in PHP is actually an ordered map.
             * implements arrays as Phpp.Runtime.PhpArray class 
             * that internally implements a Dictionary&amp;lt;object,object&amp;gt;.
            */
            
            // Single-dimensional Array(s)  
            self::printTitle(&quot;Reverse Array Elements&quot;);
            
            // Declare and Initialize Array of Chars  
            $letters = array();  
            $letters[0] = &quot;A&quot;;  
            $letters[1] = &quot;E&quot;;  
            $letters[2] = &quot;I&quot;;  
            $letters[3] = &quot;O&quot;;  
            $letters[4] = &quot;U&quot;; 
            
            //print_r($letters);
            self::printArray($letters);
            $inverse_letters = self::reverseChar($letters);  
            self::printArray($inverse_letters);  
            
            self::printTitle(&quot;Sort Integer Array Elements&quot;);  
            
            // Declare and Initialize Array of Integers   
            $numbers = array ( 10, 8, 3, 1, 5 );  
            self::printArray($numbers);  
            $ordered_numbers = self::bubbleSort($numbers);  
            self::printArray($ordered_numbers);  
            
            self::printTitle(&quot;Sort String Array Elements&quot;);  
            
            // Declare and Initialize and Array of Strings  
            $names = array (                       
                    &quot;Damian&quot;,   
                    &quot;Rogelio&quot;,  
                    &quot;Carlos&quot;,   
                    &quot;Luis&quot;,                       
                    &quot;Daniel&quot;  
                );  
            self::printArray($names);  
            $ordered_names = self::bubbleSort($names);  
            self::printArray($ordered_names);  
            
            // Multi-dimensional Array (Matrix row,column)  
            // in PHP they are the same as Jagged Arrays or &quot;array of arrays&quot;
            
            self::printTitle(&quot;Transpose Matrix&quot;);  
            
            /* Matrix row=2,col=3 
             * A =  [6  4 24] 
             *      [1 -9  8] 
             */  
            $matrix = array ( array ( 6, 4, 24 ),   
                              array ( 1, -9, 8 ));  
            self::printMatrix($matrix);  
            $transposed_matrix = self::transposeMatrix($matrix);  
            self::printMatrix($transposed_matrix);  
            
            // Jagged Array (Array-of-Arrays)         
            
            self::printTitle(&quot;Upper Case Random Array &amp;amp; Graph Number of Elements&quot;);  
            
            /*              
             * Creating an array of string arrays using the String.Split method 
             * instead of initializing it manually as follows: 
             *  
             * $text = array (  
             *      array ( &quot;word1&quot;, &quot;word2&quot;, &quot;wordN&quot; ),  
             *      array ( &quot;word1&quot;, &quot;word2&quot;, &quot;wordM&quot; ),  
             *      ... 
             *      ); 
             *  
             * Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot; 
             *  
             */  
            // using php function explode (split also works)
            $text = array (   
            \explode(&quot; &quot;, &quot;Hoy es el día más hermoso de nuestra vida, querido Sancho;&quot;),  
            \explode(&quot; &quot;, &quot;los obstáculos más grandes, nuestras propias indecisiones;&quot;),  
            \explode(&quot; &quot;, &quot;nuestro enemigo más fuerte, miedo al poderoso y nosotros mismos;&quot;),  
            \explode(&quot; &quot;, &quot;la cosa más fácil, equivocarnos;&quot;),
            \explode(&quot; &quot;, &quot;la más destructiva, la mentira y el egoísmo;&quot;),
            \explode(&quot; &quot;, &quot;la peor derrota, el desaliento;&quot;),
            \explode(&quot; &quot;, &quot;los defectos más peligrosos, la soberbia y el rencor;&quot;),
            \explode(&quot; &quot;, &quot;las sensaciones más gratas, la buena conciencia...&quot;)
            );          
            //print_r ($text);
            self::printJaggedArray($text);  
            $text = self::upperCaseRandomArray($text);  // param not by reference
            self::printJaggedArray($text);  
            self::graphJaggedArray($text);  
            
            // Array Exceptions  
            
            self::printTitle(&quot;Common Array Exceptions&quot;);  
            
            self::printCommonArrayExceptions(NULL);  
            self::printCommonArrayExceptions($text);  
            
            // Accessing Class Array Elements through Indexer  
            
            self::printTitle(&quot;Alphabets&quot;);  
            
            $vowels = new Alphabet(5);  
            $vowels[0] = &#39;a&#39;;  
            $vowels[1] = &#39;e&#39;;  
            $vowels[2] = &#39;i&#39;;  
            $vowels[3] = &#39;o&#39;;  
            $vowels[4] = &#39;u&#39;;  
            
            //print_r ($vowels);
            
            echo &quot;\nVowels = {&quot; 
                . \implode(&quot;,&quot;, array($vowels[0], $vowels[1], $vowels[2], $vowels[3], $vowels[4])) 
                . &quot;}\n&quot;;                  
            
            $en = new Alphabet(&quot;abcdefghijklmnopqrstuvwxyz&quot;);  
            echo &quot;English Alphabet = {{$en}}\n&quot;;  
  
            echo &quot;Alphabet Extract en[9..19] = {&quot;
                . new Alphabet($en-&amp;gt;slice(9, 10))  
                . &quot;}\n&quot;;
            
            $word1 = \implode(&quot;&quot;, array ($en[6], $en[14], $en[14], $en[3]));  
            $word2 = \implode(&quot;&quot;, array ($en[1], $en[24], $en[4]));  
            $word3 = \implode(&quot;&quot;, array ($en[4], $en[21], $en[4], $en[17],  
                                         $en[24], $en[14], $en[13], $en[4]));  
  
            echo &quot;\n$word1 $word2, $word3!\n&quot;;
  
            \fgets(STDIN);

            return 0;
        }
        
        static function reverseChar($arr)
        {              
            $reversed = array();  
            for ($i = 0, $j = \count($arr) - 1; $j &amp;gt;= 0; $i++, $j--)  
            {
                $reversed[$i] = $arr[$j]; 
            }
            return $reversed;  
            // or: return \array_reverse($arr);
        }  
        
        static function bubbleSort($arr)  
        {  
            $swap = 0;  
            for ($i = \count($arr) - 1; $i &amp;gt; 0; $i--)  
            {  
                for ($j = 0; $j &amp;lt; $i; $j++)  
                {  
                    // if ($arr[$j][0] &amp;gt; $arr[$j + 1][0])  
                    if (\is_numeric($arr[$j]) ? 
                        $arr[$j] &amp;gt; $arr[$j + 1] : 
                        $arr[$j][0] &amp;gt; $arr[$j + 1][0])  
                    {  
                        $swap = $arr[$j];  
                        $arr[$j] = $arr[$j + 1];  
                        $arr[$j + 1] = $swap;  
                    }  
                }  
            }  
            return $arr;  
        }  
                                    
        static function transposeMatrix($m)  
        {  
            /* Transposing a Matrix 2,3  
             *  
             * A =  [6  4 24]T [ 6  1]  
             *      [1 -9  8]  [ 4 -9] 
             *                 [24  8] 
             */
            $transposed = array();  
            for ($i = 0; $i &amp;lt; \count($m); $i++)  
            {  
                for ($j = 0; $j &amp;lt; \count($m[0]); $j++)  
                {  
                    $transposed[$j][$i] = $m[$i][$j];                  
                }  
            }  
            return $transposed;  
        }  
        
        static function upperCaseRandomArray($arr)  
        {  
            $r = new Random();  
            $i = $r-&amp;gt;Next(0, \count($arr) - 1);  
            for ($j = 0; $j &amp;lt; \count($arr[$i]); $j++)  
            {
                $arr[$i][$j] = \strtoupper($arr[$i][$j]);  
            }
            return $arr;
        }  
        
        static function printArray($arr)  
        {  
            echo &quot;\nPrint Array Content &quot; . $arr-&amp;gt;GetType()-&amp;gt;Name . &quot;\n&quot;;
            
            for ($i = 0; $i &amp;lt; \count($arr); $i++)  
            {
                Console::WriteLine(&quot; array [{0,2}] = {1,2} &quot;, $i, $arr[$i]);          
            }
        }  
        
        static function printMatrix($m)  
        {  
            echo &quot;\nPrint Matrix Content &quot; . $m-&amp;gt;GetType()-&amp;gt;Name 
            . &quot;[&quot; . \count($m) . &quot;,&quot; . \count($m[0]) . &quot;]\n&quot;;        
            
            for ($i = 0; $i &amp;lt; \count($m); $i++)  
            {
                for ($j = 0; $j &amp;lt; \count($m[0]); $j++)  
                {
                    Console::WriteLine(&quot; array [{0,2},{1,2}] = {2,2} &quot;, $i, $j, $m[$i][$j]);  
                }
            }
        }  
        
        static function graphJaggedArray($arr)  
        {  
            /* When using Arrays, we can use foreach instead of for:  
             *  
             * for (int i = 0; i &amp;lt;= arr.Length - 1; i++) 
             *   for (int j = 0; j &amp;lt;= arr.Length - 1; j++)                 
             *  
             */  
            echo &quot;\nPrint Text Content &quot; . $arr-&amp;gt;GetType()-&amp;gt;Name . &quot;\n&quot;;  
            $lineCount = 1;  
            foreach ($arr as $s)  
            {  
                Console::Write(&quot;Line{0,2}|&quot;, $lineCount);  
                foreach ($s as $w)  
                {  
                    Console::Write(&quot;{0,3}&quot;, &#39;*&#39;);  
                }  
                echo &quot; (&quot; . \count($s) . &quot;)\n&quot;;  
                $lineCount++;  
            }  
        }  
        
        static function printJaggedArray($arr)  
        {          
            echo &quot;\nPrint Jagged Array Content &quot; . $arr-&amp;gt;GetType()-&amp;gt;Name . &quot;\n&quot;;  
            for ($i = 0; $i &amp;lt; \count($arr); $i++)  
            {  
                $line = new T\StringBuilder();  
                for ($j = 0; $j &amp;lt; \count($arr[$i]); $j++)
                {
                    $line-&amp;gt;Append(&quot; &quot; . $arr[$i][$j]);  
                }
                if ($line-&amp;gt;ToString() == \strtoupper($line-&amp;gt;ToString()))  
                {
                    $line-&amp;gt;Append(&quot; &amp;lt;-- [UPPERCASED]&quot;);  
                }
                echo $line . &quot;\n&quot;;  
            }  
        }  

        static function printCommonArrayExceptions($arr)  
        {  
            // there is a bug throwing System\Exception(s) in Phalanger.
            // but apparently it has been quickly fixed after reported.
            try  
            {  
                /* Throwing System\Exception(s) do not get caught in
                 * the catch, instead they give an error message and 
                 * continue executing. i.e.
                 * throw new S\NullReferenceException(&quot;&quot;);                    
                 * throw new S\Exception(&quot;&quot;);
                */
                
                if (\is_null($arr))
                {
                    throw new \ErrorException(
                        &quot;Object reference not set to an instance of an object.&quot;, 
                        0, \E_ERROR);                    
                }
                if (!isset($arr[100][100]))
                {
                    throw new \OutOfRangeException(
                        &quot;Index was outside the bounds of the array.&quot;, 0);
                }      
            }  
            catch (\OutOfRangeException $ex)  
            {  
                echo &quot;\nException: OutOfRangeException\n&quot; . 
                    $ex-&amp;gt;getMessage() . &quot;\n&quot;;  
            } 
            catch (\ErrorException $ex)  
            {  
                echo &quot;\nException: ErrorException &quot; .
                    $ex-&amp;gt;getSeverity() . &quot;\n&quot; . $ex-&amp;gt;getMessage() . &quot;\n&quot;;                
            }             
            /*catch (S\Exception $ex)
            {
                echo &quot;\nException: &quot;, &quot;Exception&quot;, 
                    $ex-&amp;gt;getMessage(), &quot;\n&quot;;  
            }*/
        }  
        
        static function printTitle(string $message)
        {
            echo &quot;\n&quot;;
            echo \str_repeat(&quot;=&quot;, 54) . &quot;\n&quot;;
            echo $message . &quot;\n&quot;;
            echo \str_repeat(&quot;=&quot;, 54) . &quot;\n&quot;;
        }
    }

    [\Export]    
    class Alphabet implements \ArrayAccess   
    {    
        // Array Field
        private $letters = array();
        
        // Indexer Get/Set methods
        // Implementing ArrayAccess methods
        public function offsetSet($offset, $value) {
            if (\is_null($offset)) 
            {
                $this-&amp;gt;letters[] = $value;
            } else 
            {
                $this-&amp;gt;letters[$offset] = \strtoupper($value);
            }
        }
        public function offsetExists($offset) {
            return isset($this-&amp;gt;letters[$offset]);
        }
        public function offsetUnset($offset) {
            unset($this-&amp;gt;letters[$offset]);
        }
        public function offsetGet($offset) {
            return isset($this-&amp;gt;letters[$offset]) ? $this-&amp;gt;letters[$offset] : NULL;
        }
        
        // Read-Only Property  
        public function getLength()
        {  
            return \count($this-&amp;gt;letters); 
        }  
        
        // Constructor 
        // No Overloaded Constructors support in (PHP) Phalanger 
        public function __construct($param = NULL)    
        {   
            // int $size
            if(\is_numeric($param))
            {
                $this-&amp;gt;letters = \array_pad($this-&amp;gt;letters, $size, &#39; &#39;); 
            }
            // string $list
            else if(\is_string($param))
            {
                $this-&amp;gt;letters = \str_split(\strtoupper($param));
            }
            // array $list
            else if(\is_array($param))
            {
                $this-&amp;gt;letters = $param;
            }
            else 
            {
                $this-&amp;gt;letters = NULL;
            }
        }    
        
        // Overridden Method
        public function __toString()    
        {    
            return \join(&quot;,&quot;, $this-&amp;gt;letters); 
        }
        
        // Method  
        public function slice($start, $length)  
        {  
            return \array_slice($this-&amp;gt;letters, $start, $length);              
        }  
    }    
}
?&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZmbM61teWAtkGH0ygijWY3umb5iiuzr8-dt9TURmHYykdh-nWD0TGHRd1WMeNAq4uW7wWC-uwK96GfZPgTOWOaq3hRMRwsYOwCxTBKGg1llYBy2DExSDCZt2QZJjfsD5vTmkEPpdhxtw/s1600/PhpArraysOutput.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZmbM61teWAtkGH0ygijWY3umb5iiuzr8-dt9TURmHYykdh-nWD0TGHRd1WMeNAq4uW7wWC-uwK96GfZPgTOWOaq3hRMRwsYOwCxTBKGg1llYBy2DExSDCZt2QZJjfsD5vTmkEPpdhxtw/s1600/PhpArraysOutput.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/7245681699888808648/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2013/10/arrays-and-indexers-in-phalanger.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/7245681699888808648'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/7245681699888808648'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2013/10/arrays-and-indexers-in-phalanger.html' title='Arrays and Indexers in Phalanger'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZmbM61teWAtkGH0ygijWY3umb5iiuzr8-dt9TURmHYykdh-nWD0TGHRd1WMeNAq4uW7wWC-uwK96GfZPgTOWOaq3hRMRwsYOwCxTBKGg1llYBy2DExSDCZt2QZJjfsD5vTmkEPpdhxtw/s72-c/PhpArraysOutput.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-3520499226927777053</id><published>2013-10-22T12:03:00.000-07:00</published><updated>2017-05-12T01:49:01.760-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="Nemerle"/><title type='text'>Arrays and Indexers in Nemerle</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in Nemerle. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Nemerle, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my most recent post, &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in C# and C++ just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot;&gt;
using Nemerle.IO;
using System;
using System.Console;
using System.Text;

namespace NsArrays
{  
    module Program
    {
        Main() : void
        {
            // Single-dimensional Array(s)  
            PrintTitle(&amp;quot;Reverse Array Elements&amp;quot;);  
            
            // Declare and Initialize Array of Chars  
            def letters : array[char] = array(5);  
            letters[0] = &#39;A&#39;;  
            letters[1] = &#39;E&#39;;  
            letters[2] = &#39;I&#39;;  
            letters[3] = &#39;O&#39;;  
            letters[4] = &#39;U&#39;;  
            
            PrintArrayChar(letters); 
            def inverse_letters : array[char] = ReverseChar(letters);  
            PrintArrayChar(inverse_letters);  
            
            PrintTitle(&amp;quot;Sort Integer Array Elements&amp;quot;);  
  
            // Declare and Initialize Array of Integers   
            def numbers : array[int] = array [10, 8, 3, 1, 5];
            PrintArrayInt(numbers);
            def ordered_numbers : array[int] = BubbleSortInt(numbers);  
            PrintArrayInt(ordered_numbers);  
  
            PrintTitle(&amp;quot;Sort String Array Elements&amp;quot;);  
  
            // Declare and Initialize and Array of Strings   
            def names : array[string] = array[
                    &amp;quot;Damian&amp;quot;,   
                    &amp;quot;Rogelio&amp;quot;,  
                    &amp;quot;Carlos&amp;quot;,   
                    &amp;quot;Luis&amp;quot;,                       
                    &amp;quot;Daniel&amp;quot;  
                ];
            
            PrintArrayString(names);  
            def ordered_names : array[string] = BubbleSortString(names);  
            PrintArrayString(ordered_names);  
  
            // Multi-dimensional Array (Matrix row,column)  
  
            PrintTitle(&amp;quot;Transpose Matrix&amp;quot;);  
  
            /* Matrix row=2,col=3 
             * A =  [6  4 24] 
             *      [1 -9  8] 
            */
            def matrix : array[2,int] = array.[2][[ 6, 4, 24 ],   
                                                  [ 1, -9, 8 ]];
            
            PrintMatrix(matrix);  
            def transposed_matrix : array[2,int] = TransposeMatrix(matrix);  
            PrintMatrix(transposed_matrix);
            
            // Jagged Array (Array-of-Arrays)  
  
            PrintTitle(&amp;quot;Upper Case Random Array &amp;amp; Graph Number of Elements&amp;quot;);  
  
            /*              
             * Creating an array of string arrays using the String.Split method 
             * instead of initializing it manually as follows: 
             *  
             * def text : array[array[string]] = array[ 
             *      array[ &amp;quot;word1&amp;quot;, &amp;quot;word2&amp;quot;, &amp;quot;wordN&amp;quot; ],  
             *      array[ &amp;quot;word1&amp;quot;, &amp;quot;word2&amp;quot;, &amp;quot;wordM&amp;quot; ],  
             *      ... 
             *      ]; 
             *  
             * Text extract from: &amp;quot;El ingenioso hidalgo don Quijote de la Mancha&amp;quot; 
             *  
             */           
            def text : array[array[string]] = array[   
            &quot;Hoy es el día más hermoso de nuestra vida, querido Sancho;&quot;.Split(&#39; &#39;),  
            &quot;los obstáculos más grandes, nuestras propias indecisiones;&quot;.Split(&#39; &#39;),  
            &quot;nuestro enemigo más fuerte, miedo al poderoso y nosotros mismos;&quot;.Split(&#39; &#39;),  
            &quot;la cosa más fácil, equivocarnos;&quot;.Split(&#39; &#39;),  
            &quot;la más destructiva, la mentira y el egoísmo;&quot;.Split(&#39; &#39;),  
            &quot;la peor derrota, el desaliento;&quot;.Split(&#39; &#39;),  
            &quot;los defectos más peligrosos, la soberbia y el rencor;&quot;.Split(&#39; &#39;),  
            &quot;las sensaciones más gratas, la buena conciencia...&quot;.Split(&#39; &#39;)
            ];  
            PrintJaggedArray(text);  
            UpperCaseRandomArray(text);  
            PrintJaggedArray(text);  
            GraphJaggedArray(text);  
            
            // Array Exceptions  
  
            PrintTitle(&amp;quot;Common Array Exceptions&amp;quot;);  
            
            PrintCommonArrayExceptions(null);  
            PrintCommonArrayExceptions(text);  
  
            // Accessing Class Array Elements through Indexer  
  
            PrintTitle(&amp;quot;Alphabets&amp;quot;);  
  
            def vowels : Alphabet = Alphabet(5);  
            vowels[0] = &#39;a&#39;;  
            vowels[1] = &#39;e&#39;;  
            vowels[2] = &#39;i&#39;;  
            vowels[3] = &#39;o&#39;;  
            vowels[4] = &#39;u&#39;;  
  
            printf(&amp;quot;\nVowels = {%s}\n&amp;quot;,  
                String.Join(&amp;quot;,&amp;quot;, vowels[0], vowels[1], vowels[2], vowels[3], vowels[4]));  
  
            def en : Alphabet = Alphabet(&amp;quot;abcdefghijklmnopqrstuvwxyz&amp;quot;);  
            printf(&amp;quot;English Alphabet = {%s}\n&amp;quot;, en.ToString());  
  
            printf(&amp;quot;Alphabet Extract en[9..19] = {%s}\n&amp;quot;,   
                          Alphabet(en.Slice(9, 10)).ToString());  
  
            def word1 : string = String.Join(&amp;quot;&amp;quot;, en[6], en[14], en[14], en[3]);  
            def word2 : string = String.Join(&amp;quot;&amp;quot;, en[1], en[24], en[4]);  
            def word3 : string = String.Join(&amp;quot;&amp;quot;, en[4], en[21], en[4], en[17],  
                                           en[24], en[14], en[13], en[4]);  
  
            printf(&amp;quot;\n%s %s, %s!\n\n&amp;quot;, word1, word2, word3);  
                                                  
            _ = ReadLine();
        }
        
        ReverseChar(arr : array[char]) : array[char]
        {
            def reversed : array[char] = array(arr.Length);
            mutable i : int = 0;
            for (mutable j : int = arr.Length - 1; j &amp;gt;= 0; j--)  
            {
                reversed[i] = arr[j];
                i++;
            }
            reversed;
        }
        
        BubbleSortInt(arr : array[int]) : array[int]
        {
            mutable swap : int = 0;
            for (mutable i : int = arr.Length - 1; i &amp;gt; 0; i--)
            {
                for (mutable j: int = 0; j &amp;lt; i; j++)
                {                    
                    if (arr[j] &amp;gt; arr[j + 1])  
                    { 
                        swap = arr[j];  
                        arr[j] = arr[j + 1];
                        arr[j + 1] = swap;
                    }
                    else{}
                }
            }
            arr;
        }

        BubbleSortString(arr : array[string]) : array[string]
        {
            mutable swap : string = &amp;quot;&amp;quot;;
            for (mutable i : int = arr.Length - 1; i &amp;gt; 0; i--)
            {
                for (mutable j: int = 0; j &amp;lt; i; j++)
                {
                    if (arr[j][0] &amp;gt; arr[j + 1][0]) 
                    {
                        swap = arr[j];  
                        arr[j] = arr[j + 1];  
                        arr[j + 1] = swap;
                    }
                    else{}
                }
            }
            arr;
        }
        
        TransposeMatrix(m : array[2, int]) : array[2, int]
        {  
            /* Transposing a Matrix 2,3  
             *  
             * A =  [6  4 24]T [ 6  1]  
             *      [1 -9  8]  [ 4 -9] 
             *                 [24  8] 
            */  
            def transposed : array[2, int] = array(m.GetUpperBound(1) + 1,  
                                                   m.GetUpperBound(0) + 1);  
            for (mutable i : int = 0; i &amp;lt; m.GetUpperBound(0) + 1; i++)  
            {  
                for (mutable j = 0; j &amp;lt; m.GetUpperBound(1) + 1; j++)  
                {  
                    transposed[j, i] = m[i, j];  
                }  
            }  
            transposed;  
        }  
        
        UpperCaseRandomArray(arr : array[array[string]]) : void
        {  
            def r : Random = Random();  
            mutable i : int = r.Next(0, arr.Length - 1);  
            for (mutable j : int = 0; j &amp;lt;= arr[i].Length - 1; j++)  
                arr[i][j] = arr[i][j].ToUpper();  
        }  
        
        PrintArrayChar(arr : array[char]) : void  
        {
            printf(&amp;quot;\nPrint Array Content %s\n&amp;quot;, 
                arr.GetType().Name.Replace(&amp;quot;]&amp;quot;, arr.Length.ToString() + &amp;quot;]&amp;quot;));  
              
            for (mutable i : int = 0; i &amp;lt;= arr.Length - 1; i++)  
                WriteLine(&amp;quot;  array [{0,2}] = {1,2} &amp;quot;, i, arr[i]);
        }  
        
        PrintArrayInt(arr : array[int]) : void  
        {
            printf(&amp;quot;\nPrint Array Content %s\n&amp;quot;, 
                arr.GetType().Name.Replace(&amp;quot;]&amp;quot;, arr.Length.ToString() + &amp;quot;]&amp;quot;));  
              
            for (mutable i : int = 0; i &amp;lt;= arr.Length - 1; i++)  
                WriteLine(&amp;quot;  array [{0,2}] = {1,2} &amp;quot;, i, arr[i]);
        } 
        
        PrintArrayString(arr : array[string]) : void  
        {
            printf(&amp;quot;\nPrint Array Content %s\n&amp;quot;, 
                arr.GetType().Name.Replace(&amp;quot;]&amp;quot;, arr.Length.ToString() + &amp;quot;]&amp;quot;));  
              
            for (mutable i : int = 0; i &amp;lt;= arr.Length - 1; i++)  
                WriteLine(&amp;quot;  array [{0,2}] = {1,2} &amp;quot;, i, arr[i]);
        } 
        
        PrintMatrix(m : array[2,int]) : void  
        {  
            printf(&amp;quot;\nPrint Matrix Content %s[%s,%s]\n&amp;quot;,  
                m.GetType().Name.Replace(&amp;quot;[,]&amp;quot;, &amp;quot;&amp;quot;),  
                (m.GetUpperBound(0) + 1).ToString(),  
                (m.GetUpperBound(1) + 1).ToString());  
  
            for (mutable i : int = 0; i &amp;lt;= m.GetUpperBound(0); i++)  
                for (mutable j : int = 0; j &amp;lt;= m.GetUpperBound(1); j++)  
                    WriteLine(&amp;quot; array [{0,2},{1,2}] = {2,2} &amp;quot;, i, j, m[i, j]);  
        }  
        
        GraphJaggedArray(arr : array[array[string]]) : void  
        {  
            /* When using Arrays, we can use foreach instead of for:  
             *  
             * for (mutable i : int = 0; i &amp;lt;= arr.Length - 1; i++) 
             *   for (mutable j : int = 0; j &amp;lt;= arr.Length - 1; j++)                 
             *  
            */  
            printf(&amp;quot;\nPrint Text Content %s\n&amp;quot;, arr.GetType().Name);  
            mutable lineCount : int = 1;  
            foreach (s : array[string] in arr)  
            {  
                Write(&amp;quot;Line{0,2}|&amp;quot;, lineCount);  
                foreach (_ : string in s)  
                {  
                    Write(&amp;quot;{0,3}&amp;quot;, &#39;*&#39;);  
                }  
                printf(&amp;quot; (%s)\n&amp;quot;, s.Length.ToString());  
                lineCount++;  
            }  
        }  
        
        PrintJaggedArray(arr : array[array[string]]) : void  
        {  
            mutable line : StringBuilder;  
            printf(&amp;quot;\nPrint Jagged Array Content %s\n&amp;quot;, arr.GetType().Name);  
            for (mutable i : int = 0; i &amp;lt;= arr.Length - 1; i++)  
            {  
                line = StringBuilder();  
                for (mutable j : int = 0; j &amp;lt;= arr[i].Length - 1; j++)  
                    _ = line.Append(&amp;quot; &amp;quot; + arr[i][j]);  
                if (line.ToString() == line.ToString().ToUpper()) 
                {
                    _ = line.Append(&amp;quot; &amp;lt;-- [UPPERCASED]&amp;quot;);  
                }
                else {}
                printf(&amp;quot;%s\n&amp;quot;, line.ToString());  
            }  
        }  
        
        PrintCommonArrayExceptions(arr : array[array[string]]) : void
        {  
            try  
            {  
                arr[100][100] = &amp;quot;hola&amp;quot;;  
            }  
            catch             
            {  
            | ex is Exception =&amp;gt;
                printf(&amp;quot;\nException: \n%s\n%s\n&amp;quot;, ex.GetType().Name, ex.Message);  
            }  
        }  
                
        PrintTitle(message : string) : void
        {
            print(&amp;quot;\n&amp;quot;);
            print(&amp;quot;======================================================\n&amp;quot;);
            printf(&amp;quot;%s\n&amp;quot;, message);  
            print(&amp;quot;======================================================\n&amp;quot;);  
        }
    }
    
    class Alphabet  
    {  
        // Array Field  
        private letters : array[char];  
  
        // Indexer Get/Set Property  
        public Item[index : int] : char
        {  
            get { letters[index] }  
            set { letters[index] = Char.ToUpper(value) }  
        }  

        // Read-Only Property  
        public Length : int
        {  
            get { this.letters.Length }  
        }  
  
        // Constructors  
        public this(size : int)  
        {  
            this.letters = array(size); 
        }  
  
        public this(lst : string)  
        {  
            this.letters = lst.ToUpper().ToCharArray();  
        }  
  
        public this(lst : array[char])  
        {  
            this.letters = lst;
        }  
  
        // Overridden Method  
        public override ToString() : string
        {  
            String.Join(&amp;quot;,&amp;quot;, this.letters); 
        }  
  
        // Method  
        public Slice(start : int, length : int) : array[char]
        {  
            def result : array[char] = array(length);  
            mutable j : int = start;
            for (mutable i : int = 0; i &amp;lt; length; i++)  
            {  
                result[i] = this[j];  
                j++;
            }  
            result;
        }  
  
    }  
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq59V-FOLgu0dsWuWBGojUPj2bUeaAliWXfzw3t1KlMf27Ups3sQImtaA7jS9IBntUK-eBhyQDDLMZyEttNPiHdSH1iDQli2mFttHjeOQMZ7W9uMFs44pOVen1DyJ1swQVuBpZUTv4A_M/s1599/arrays_indexers_cs+-+Copie.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq59V-FOLgu0dsWuWBGojUPj2bUeaAliWXfzw3t1KlMf27Ups3sQImtaA7jS9IBntUK-eBhyQDDLMZyEttNPiHdSH1iDQli2mFttHjeOQMZ7W9uMFs44pOVen1DyJ1swQVuBpZUTv4A_M/s1600/arrays_indexers_cs+-+Copie.png&quot;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/3520499226927777053/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2013/10/arrays-and-indexers-in-nemerle.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/3520499226927777053'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/3520499226927777053'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2013/10/arrays-and-indexers-in-nemerle.html' title='Arrays and Indexers in Nemerle'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq59V-FOLgu0dsWuWBGojUPj2bUeaAliWXfzw3t1KlMf27Ups3sQImtaA7jS9IBntUK-eBhyQDDLMZyEttNPiHdSH1iDQli2mFttHjeOQMZ7W9uMFs44pOVen1DyJ1swQVuBpZUTv4A_M/s72-c/arrays_indexers_cs+-+Copie.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-4260823498562335765</id><published>2013-09-14T14:16:00.001-07:00</published><updated>2013-10-23T00:43:24.325-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Boo"/><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><title type='text'>Arrays and Indexers in Boo</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in Boo. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in Boo, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my most recent post, &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in C# and C++ just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharp&quot; name=&quot;code&quot;&gt;namespace BooArrays
# python&#39;s import syntax supported only on latest Boo version (2.0.9.5 assemblies)
from System import Random
from System.Text import StringBuilder
from System.Console import WriteLine, Write, ReadKey
from System.Convert import ToChar 
from System.Char import ToUpper

# Console Program
public def Main(argv as (string)): 
 # Single-dimensional Array(s)
 printtitle(&#39;Reverse Array Elements&#39;);
 
 # Declare and initialize Array of Chars
 # Boo doesn&#39;t support yet (version 2.0.9.5 assemblies) Char literals.
 # 1 character literal such as &#39;A&#39; or &quot;A&quot; are strings
 # so, I&#39;m converting Convert.ToChar before assignment by element.
 # There are 2 ways to initialize inline. i.e.
 # option 1: a as (char) = (ToChar(&#39;A&#39;), ToChar(&#39;B&#39;), ToChar(&#39;C&#39;))
 # option 2: a as (char) = &quot;ABC&quot;.ToCharArray()
 letters as (char) = array(char, 5)
 letters[0] = ToChar(&#39;A&#39;)
 letters[1] = ToChar(&#39;E&#39;)
 letters[2] = ToChar(&#39;I&#39;)
 letters[3] = ToChar(&#39;O&#39;)
 letters[4] = ToChar(&#39;U&#39;)
 
 printarraychar(letters)
 inverse_letters as (char) = reversechar(letters)
 printarraychar(inverse_letters)
 
 printtitle(&#39;Sort Integer Array Elements&#39;)
 
 # Declare and Initialize Array of Integers
 numbers as (int) = (10, 8, 3, 1, 5) 
 printarrayint(numbers)
 ordered_numbers as (int) = bubblesortint(numbers)
 printarrayint(ordered_numbers)
  
 printtitle(&#39;Sort String Array Elements&#39;)
 
 # Declare and Initialize and Array of Strings
 names as (string) = (
        &#39;Damian&#39;, 
        &#39;Rogelio&#39;, 
        &#39;Carlos&#39;, 
        &#39;Luis&#39;, 
        &#39;Daniel&#39;
    )
 printarraystring(names)
 ordered_names as (string) = bubblesortstring(names)
 printarraystring(ordered_names)
 
 # Multi-dimensional Array (Matrix row,column)
 printtitle(&#39;Transpose Matrix&#39;)
 
 /* Matrix row=2,col=3  
 * A =  [6  4 24]  
 *   [1 -9  8]  
 */ 
 matrx as (int, 2) = matrix(int, 2, 3) 
 # or alternative syntax: = matrix of int(2, 3)
 matrx[0,0] = 6
 matrx[0,1] = 4
 matrx[0,2] = 24
 matrx[1,0] = 1
 matrx[1,1] = -9
 matrx[1,2] = 8
 
 printmatrix(matrx)
 transposed_matrix as (int, 2) = transposematrix(matrx)
 printmatrix(transposed_matrix)
 
 # Jagged Array (Array-of-Arrays)
 printtitle(&#39;Upper Case Random Array &amp;amp; Graph Number of Elements&#39;)
 
 /*              
 * Creating an array of string arrays using the String.Split method 
 * instead of initializing it manually as follows: 
 *  
 * text as ((string)) = (  
 *      ( &#39;word1&#39;, &#39;word2&#39;, &#39;wordN&#39; ),  
 *      ( &#39;word1&#39;, &#39;word2&#39;, &#39;wordM&#39; ),  
 *      ... 
 *      } 
 *  
 * Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot; 
 *  
 */
 text as ((string)) = (
    &#39;Hoy es el día más hermoso de nuestra vida, querido Sancho;&#39;.Split(ToChar(&#39; &#39;)), 
    &#39;los obstáculos más grandes, nuestras propias indecisiones;&#39;.Split(ToChar(&#39; &#39;)), 
    &#39;nuestro enemigo más fuerte, miedo al poderoso y nosotros mismos;&#39;.Split(ToChar(&#39; &#39;)), 
    &#39;la cosa más fácil, equivocarnos;&#39;.Split(ToChar(&#39; &#39;)), 
    &#39;la más destructiva, la mentira y el egoísmo;&#39;.Split(ToChar(&#39; &#39;)), 
    &#39;la peor derrota, el desaliento;&#39;.Split(ToChar(&#39; &#39;)), 
    &#39;los defectos más peligrosos, la soberbia y el rencor;&#39;.Split(ToChar(&#39; &#39;)), 
    &#39;las sensaciones más gratas, la buena conciencia...&#39;.Split(ToChar(&#39; &#39;)))
 
 printjaggedarray(text)
 uppercaserandomarray(text)
 printjaggedarray(text)
 graphjaggedarray(text)
 
 # Array Exceptions
 printtitle(&#39;Common Array Exceptions&#39;)

 printcommonarrayexceptions(null)
 printcommonarrayexceptions(text)
 
 # Accessing Class Array Elements through Indexer    
 printtitle(&#39;Alphabets&#39;)

 vowels as Alphabet = Alphabet(5)
 vowels[0] = ToChar(&#39;a&#39;)
 vowels[1] = ToChar(&#39;e&#39;)
 vowels[2] = ToChar(&#39;i&#39;)
 vowels[3] = ToChar(&#39;o&#39;)
 vowels[4] = ToChar(&#39;u&#39;)
 
 print &#39;\nVowels = {&#39; + join((vowels[0], vowels[1], vowels[2], 
                        vowels[3], vowels[4]), &#39;,&#39;) + &#39;}&#39;
 
 en as Alphabet = Alphabet(&#39;abcdefghijklmnopqrstuvwxyz&#39;)
 print &quot;English Alphabet = {${en.ToString()}}&quot;
 
 print &quot;Alphabet Extract en[9..19] = {${Alphabet(en.slice(9, 10))}}&quot;
 
 word1 as string = join((en[6], en[14], en[14], en[3]), &#39;&#39;)
 word2 as string = join((en[1], en[24], en[4]), &#39;&#39;)
 word3 as string = join((en[4], en[21], en[4], en[17], en[24], 
                            en[14], en[13], en[4]), &#39;&#39;)
 print &quot;\n$word1 $word2, $word3!\n&quot;
 
 ReadKey()

def reversechar(arr as (char)) as (char): 
 reversed as (char) = array(char, arr.Length)
 i as int = 0
 for j in range(len(arr) - 1, -1, -1):
  reversed[i] = arr[j]
  i++
 return reversed

def bubblesortint(arr as (int)) as (int):
 swap as int = 0
 for i in range(len(arr) - 1, -1, -1):
  for j in range(0, len(arr) - 1):
   if arr[j] &amp;gt; arr[j + 1]:
    swap = arr[j]
    arr[j] = arr[j + 1]
    arr[j + 1] = swap
 return arr

def bubblesortstring(arr as (string)) as (string):
 swap as string = &#39;&#39;
 for i in range(len(arr) - 1, -1, -1):
  for j in range(0, len(arr) - 1):
   if arr[j][0] &amp;gt; arr[j + 1][0]:
    swap = arr[j]
    arr[j] = arr[j + 1]
    arr[j + 1] = swap
 return arr

def transposematrix(m as (int, 2)) as (int, 2):
 /* Transposing a Matrix 2,3
 *
 * A =  [6  4 24]T [ 6  1]
 *    [1 -9  8]  [ 4 -9]
 *      [24  8]
 */
 transposed as (int, 2) = matrix(int, len(m, 1), len(m, 0))
 for i in range(len(m, 0)):
  for j in range(len(m, 1)):
   transposed[j, i] = m[i, j]
 return transposed

def uppercaserandomarray(arr as ((string))) as void:
 r as Random = Random()
 i as int = r.Next(len(arr))
 for j as int in range(len(arr[i])):    
  arr[i][j] = arr[i][j].ToUpper()
  
def printarraychar(arr as (char)) as void:
 print &#39;\nPrint Array Content &#39; + arr.GetType().Name.Replace(&#39;]&#39;, len
(arr).ToString() + &#39;]&#39;) 
 for i in range(len(arr)):
  WriteLine(&#39; array [{0,2}] = {1,2} &#39;, i, arr[i])
  
def printarrayint(arr as (int)):
 print &#39;\nPrint Array Content &#39; + arr.GetType().Name.Replace(&#39;]&#39;, len
(arr).ToString() + &#39;]&#39;) 
 for i in range(len(arr)):
  WriteLine(&#39; array [{0,2}] = {1,2} &#39;, i, arr[i])

def printarraystring(arr as (string)) as void:
 print &#39;\nPrint Array Content &#39; + arr.GetType().Name.Replace(&#39;]&#39;, len

(arr).ToString() + &#39;]&#39;) 
 for i in range(len(arr)):
  WriteLine(&#39; array [{0,2}] = {1,2} &#39;, i, arr[i])

def printmatrix(m as (int, 2)) as void:
 print &#39;\nPrint Matrix Content &#39; + m.GetType().Name.Replace(&#39;[,]&#39;, &#39;&#39;) + &#39;[&#39; + len

(m,0).ToString() + &#39;,&#39; + len(m,1).ToString() + &#39;]&#39; 
 for i in range(len(m, 0)):
  for j in range(len(m, 1)):
   WriteLine(&#39; array [{0,2},{1,2}] = {2,2} &#39;, i, j, m[i, j])

def graphjaggedarray(arr as ((string))) as void:
 /* When using Arrays, we can use for(each) instead of for by index:        
  *   
  * for s as (string) in arr:
  *   for w as string in s:
  *   
 */
 print &quot;\nPrint Text Content ${arr.GetType().Name}&quot;
  for i as int in range(len(arr)):
   Write(&#39;Line{0,2}|&#39;, i+1)
   for j as int in range(len(arr[i])):
    Write(&#39;{0,3}&#39;, &#39;*&#39;)
   print &quot; (${len(arr[i]).ToString()})&quot;

def printjaggedarray(arr as ((string))) as void:
 line as StringBuilder    
 print &quot;\nPrint Jagged Array Content ${arr.GetType().Name}&quot;
 for i as int in range(len(arr)):  
  line = StringBuilder()
  for j in range(len(arr[i])):   
   line.Append(&#39; &#39; + arr[i][j])   
  if line.ToString() == line.ToString().ToUpper():
   line.Append(&#39; &amp;lt;-- [UPPERCASED]&#39;)
  print line

def printcommonarrayexceptions(arr as ((string))) as void:
 try: 
  arr[100][100] = &#39;hola&#39;  
 except ex as System.Exception:    
  print &quot;\nException: \n${ex.GetType().Name}\n${ex.Message}&quot;

def printtitle(message as string) as void: 
 print &#39;&#39;
 print(&#39;=&#39; * 54)
 print message
 print(&#39;=&#39; * 54)

[System.Reflection.DefaultMember(&quot;item&quot;)]
class Alphabet: 
 # Array Field
 private letters as (char)
 
 # Indexer Get/Set Property
 public item[index as int]:
  get:
   rawArrayIndexing:
    return letters[index]
  set:
   rawArrayIndexing:
    letters[index] = ToUpper(value)
 # Read-Only Property
 public Length as int:    
  get:
   return len(self.letters) 

 # Constructors
 public def constructor(size as int):
  self.letters = array(char, size)
 
 public def constructor(list as string):
  self.letters = list.ToUpper().ToCharArray()

 public def constructor(list as (char)):
  self.letters = list

 # Overridden Method 
 public override def ToString():
  return join(self.letters, &#39;,&#39;)

 # Method
 public def slice(start as int, length as int) as (char):
  # using Boo&#39;s slicing: 
  # container[&amp;lt;firstIndexWanted&amp;gt;:&amp;lt;firstIndexNotWanted&amp;gt;:&amp;lt;step&amp;gt;]
  return self.letters[start:start+length]
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq59V-FOLgu0dsWuWBGojUPj2bUeaAliWXfzw3t1KlMf27Ups3sQImtaA7jS9IBntUK-eBhyQDDLMZyEttNPiHdSH1iDQli2mFttHjeOQMZ7W9uMFs44pOVen1DyJ1swQVuBpZUTv4A_M/s1599/arrays_indexers_cs+-+Copie.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq59V-FOLgu0dsWuWBGojUPj2bUeaAliWXfzw3t1KlMf27Ups3sQImtaA7jS9IBntUK-eBhyQDDLMZyEttNPiHdSH1iDQli2mFttHjeOQMZ7W9uMFs44pOVen1DyJ1swQVuBpZUTv4A_M/s1600/arrays_indexers_cs+-+Copie.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/4260823498562335765/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2013/09/arrays-and-indexers-in-boo.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/4260823498562335765'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/4260823498562335765'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2013/09/arrays-and-indexers-in-boo.html' title='Arrays and Indexers in Boo'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq59V-FOLgu0dsWuWBGojUPj2bUeaAliWXfzw3t1KlMf27Ups3sQImtaA7jS9IBntUK-eBhyQDDLMZyEttNPiHdSH1iDQli2mFttHjeOQMZ7W9uMFs44pOVen1DyJ1swQVuBpZUTv4A_M/s72-c/arrays_indexers_cs+-+Copie.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-235808136187576609</id><published>2013-07-18T08:56:00.000-07:00</published><updated>2017-04-21T06:58:13.911-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="JScript.NET"/><title type='text'>Arrays and Indexers in JScript.NET</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in JScript.NET. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in JScript.NET, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my most recent post, &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in C# and C++ just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT!&lt;br /&gt;
JScript provides two different types of arrays, JScript array objects and typed arrays. In JScript array objects, which are sparse, a script can dynamically add and remove elements, and elements can be of any data type. In typed arrays, which are dense, the size is fixed, and elements must be the same type as the base type of the array.&lt;br /&gt;
&lt;br /&gt;
I chose to use the Typed Arrays (and all other variables as well) to keep it closer to the previous posts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: jscript&quot;&gt;//C:\Windows\Microsoft.NET\Framework64\v4.0.30319&amp;gt;jsc.exe JsArrays.js
import System;
import Microsoft.JScript; // to get the JScriptException  

function reverseChar(arr: char[]): char[]
{              
    var reversed: char[] = new char[arr.length];  
    for (var i: int = 0, j: int = arr.length - 1; j &amp;gt;= 0; i++, j--)  
        reversed[i] = arr[j];  
    return reversed;  
}  

function bubbleSortInt(arr: int[]): int[]  
{  
    var swap: int = 0;  
    for (var i: int = arr.length - 1; i &amp;gt; 0; i--)  
    {  
        for (var j: int = 0; j &amp;lt; i; j++)  
        {  
            if (arr[j] &amp;gt; arr[j + 1])  
            {  
                swap = arr[j];  
                arr[j] = arr[j + 1];  
                arr[j + 1] = swap;  
            }  
        }  
    }  
    return arr;  
}  

function bubbleSortString(arr: String[]): String[]  
{  
    var swap: String = &#39;&#39;;  
    for (var i: int = arr.length - 1; i &amp;gt; 0; i--)  
    {  
        for (var j: int = 0; j &amp;lt; i; j++)  
        {  
            if (arr[j][0] &amp;gt; arr[j + 1][0])  
            {  
                swap = arr[j];  
                arr[j] = arr[j + 1];  
                arr[j + 1] = swap;  
            }  
        }  
    }  
    return arr;  
}  

function transposeMatrix(m: int[,]): int[,]  
{  
    /* Transposing a Matrix 2,3  
     *  
     * A =  [6  4 24]T [ 6  1]  
     *      [1 -9  8]  [ 4 -9] 
     *                 [24  8] 
    */  
    var transposed: int[,] = new int[m.GetUpperBound(1) + 1,  
                             m.GetUpperBound(0) + 1];  
    for (var i: int = 0; i &amp;lt; m.GetUpperBound(0) + 1; i++)  
    {  
        for (var j: int = 0; j &amp;lt; m.GetUpperBound(1) + 1; j++)  
        {  
            transposed[j, i] = m[i, j];  
        }  
    }  
    return transposed;  
}  

function upperCaseRandomArray(arr: String[][])  
{  
    var r: Random = new Random();  
    var i: int = r.Next(0, arr.length - 1);  
    for (var j: int = 0; j &amp;lt;= arr[i].length - 1; j++)  
        arr[i][j] = arr[i][j].ToUpper();  
}  

function printArrayChar(arr: char[])  
{  
    print(&#39;\nPrint Array Content &#39;,  
        arr.GetType().Name.Replace(&#39;]&#39;, arr.length.ToString() + &#39;]&#39;));  

    for (var i: int = 0; i &amp;lt;= arr.length - 1; i++)  
        Console.WriteLine(&#39; array [{0,2}] = {1,2} &#39;, i, arr[i]);  
}  

function printArrayInt(arr: int[])  
{  
    print(&#39;\nPrint Array Content &#39;,  
        arr.GetType().Name.Replace(&#39;]&#39;, arr.length.ToString() + &#39;]&#39;));  

    for (var i: int = 0; i &amp;lt;= arr.length - 1; i++)  
        Console.WriteLine(&#39; array [{0,2}] = {1,2} &#39;, i, arr[i]);  
}  

function printArrayString(arr: String[])  
{  
    print(&#39;\nPrint Array Content &#39;,  
        arr.GetType().Name.Replace(&#39;]&#39;, arr.length.ToString() + &#39;]&#39;));  

    for (var i: int = 0; i &amp;lt;= arr.length - 1; i++)  
        Console.WriteLine(&#39; array [{0,2}] = {1,2} &#39;, i, arr[i]);  
}  

function printMatrix(m: int[,])  
{  
    print(&#39;\nPrint Matrix Content &#39;, 
        m.GetType().Name.Replace(&#39;[,]&#39;, &#39;&#39;), &#39;[&#39;,
        (m.GetUpperBound(0) + 1).ToString(),&#39;,&#39;,
        (m.GetUpperBound(1) + 1).ToString(),&#39;]&#39;);  

    for (var i: int = 0; i &amp;lt;= m.GetUpperBound(0); i++)  
        for (var j: int = 0; j &amp;lt;= m.GetUpperBound(1); j++)  
            Console.WriteLine(&#39; array [{0,2},{1,2}] = {2,2} &#39;, i, j, m[i, j]);  
}  

function graphJaggedArray(arr: String[][])  
{  
    /* When using Arrays, we can use for(each) instead of for:  
     * however, for some reason, JScript tries to convert the
     * elements of arr to System.Int32 instead of String[] 
     * so it fails.
     *  
     * for (var s: String[] in arr)  
     *   for (var w: String in s)                  
     *  
    */
    print(&#39;\nPrint Text Content &#39;, arr.GetType().Name);      
    for (var i: int = 0; i &amp;lt;= arr.length - 1; i++)
    {  
        Console.Write(&#39;Line{0,2}|&#39;, i+1);  
        for (var j: int = 0; j &amp;lt;= arr[i].length - 1; j++)
        {  
            Console.Write(&#39;{0,3}&#39;, &#39;*&#39;);  
        }              
        print(&#39; (&#39;, arr[i].length, &#39;)&#39;);          
    }  
}  
  
function printJaggedArray(arr: String[][])  
{  
    var line: System.Text.StringBuilder;  
    print(&#39;\nPrint Jagged Array Content &#39;, arr.GetType().Name);  
    for (var i: int = 0; i &amp;lt;= arr.length - 1; i++)  
    {  
        line = new System.Text.StringBuilder();  
        for (var j: int = 0; j &amp;lt;= arr[i].length - 1; j++)  
            line.Append(&#39; &#39; + arr[i][j]);  
        if (line.ToString() == line.ToString().ToUpper())  
            line.Append(&#39; &amp;lt;-- [UPPERCASED]&#39;);  
        print(line);  
    }  
}  
  
function printCommonArrayExceptions(arr: String[][])  
{  
    try  
    {  
        arr[100][100] = &#39;hola&#39;;  
    }      
    catch (ex: JScriptException)  
    {  
        print(&#39;\nException: \n&#39;, 
                ex.GetType().Name,&#39;\n&#39;, ex.Message);  
    }
    catch (ex: Exception)  
    {  
        print(&#39;\nException: \n&#39;, 
                ex.GetType().Name,&#39;\n&#39;, ex.Message);  
    }  
}  
  
function printTitle(message: String)  
{  
    print();  
    print(&#39;======================================================&#39;);  
    Console.WriteLine(&#39;{0,10}&#39;, message);  
    print(&#39;======================================================&#39;);  
}  

package JsArrays 
{  
    class Alphabet  
    {  
        // Array Field  
        private var letters: char[];  

        // No indexer support. 
        // Getter/Setter Method instead. 
        public function getItem(index: int): char 
        {    
            return this.letters[index];   
        } 
        
        public function setItem(index: int, value: char) 
        {
            this.letters[index] = Char.ToUpper(value);
        }        
  
        // Read-Only Property 
        public function get Length(): int {    
            return this.letters.length;   
        }            
  
        // Constructors  
        public function Alphabet(size: int)  
        {              
            this.letters = new char[size];  
        }  
  
        public function Alphabet(list: String)  
        {              
            this.letters = list.ToUpper().ToCharArray();  
        }  
  
        public function Alphabet(list: char[])  
        {              
            this.letters = list;  
        }  
  
        // Overridden Method  
        public function toString(): String  
        {              
            return String.Join(&#39;,&#39;, this.letters, &#39;&#39;);  
        }  
  
        // Method  
        public function slice(start: int, length: int): char[]
        {  
            var result: char[] = new char[length];  
            for (var i: int = 0, j: int = start; i &amp;lt; length; i++, j++)  
            {  
                result[i] = letters[j];  
            }  
            return result;  
        }   
    }  
};

import JsArrays;  
  
function Main() {  
    
    // Single-dimensional Array(s)  
    printTitle(&#39;Reverse Array Elements&#39;);  

    // Declare and Initialize Array of Chars  
    var letters: char[] = new char[5];  
    letters[0] = &#39;A&#39;;  
    letters[1] = &#39;E&#39;;  
    letters[2] = &#39;I&#39;;  
    letters[3] = &#39;O&#39;;  
    letters[4] = &#39;U&#39;;  

    printArrayChar(letters);  
    var inverse_letters: char[] = reverseChar(letters);  
    printArrayChar(inverse_letters);  

    printTitle(&#39;Sort Integer Array Elements&#39;);  

    // Declare and Initialize Array of Integers   
    var numbers: int[] = [ 10, 8, 3, 1, 5 ];  
    printArrayInt(numbers);  
    var ordered_numbers: int[] = bubbleSortInt(numbers);  
    printArrayInt(ordered_numbers);  

    printTitle(&#39;Sort String Array Elements&#39;);  

    // Declare and Initialize and Array of Strings  
    var names: String[] = [                       
            &#39;Damian&#39;,   
            &#39;Rogelio&#39;,  
            &#39;Carlos&#39;,   
            &#39;Luis&#39;,                       
            &#39;Daniel&#39;  
        ];  
    printArrayString(names);  
    var ordered_names: String[] = bubbleSortString(names);  
    printArrayString(ordered_names);  

    // Multi-dimensional Array (Matrix row,column)  

    printTitle(&#39;Transpose Matrix&#39;);  

    /* Matrix row=2,col=3 
     * A =  [6  4 24] 
     *      [1 -9  8] 
    */  
    var matrix: int[,] = new int[2,3];
    matrix[0,0] = 6; matrix[0,1] = 4; matrix[0,2] = 24;
    matrix[1,0] = 1; matrix[1,1] = -9; matrix[1,2] = 8;
    
    print(matrix.GetType().Name);
    printMatrix(matrix);  
    var transposed_matrix: int[,] = transposeMatrix(matrix);  
    printMatrix(transposed_matrix);  

    // Jagged Array (Array-of-Arrays)  

    printTitle(&#39;Upper Case Random Array &amp;amp; Graph Number of Elements&#39;);  

    /*              
     * Creating an array of string arrays using the String.Split method 
     * instead of initializing it manually as follows: 
     * 
     * var array1: new String[] = [ &#39;word1&#39;, &#39;word2&#39;, &#39;wordN&#39; ];
     * var array2: new string[] = [ &#39;word1&#39;, &#39;word2&#39;, &#39;wordM&#39; ];
     * ...
     * var text: String[][] = [   
     *      array1,  
     *      array2,  
     *      ... 
     *      ]; 
     *  
     * Text extract from: &#39;El ingenioso hidalgo don Quijote de la Mancha&#39; 
     *  
     */
    
    var text: String[][] = [   
    &#39;Hoy es el día más hermoso de nuestra vida, querido Sancho;&#39;.Split(&#39; &#39;),  
    &#39;los obstáculos más grandes, nuestras propias indecisiones;&#39;.Split(&#39; &#39;),  
    &#39;nuestro enemigo más fuerte, miedo al poderoso y nosotros mismos;&#39;.Split(&#39; &#39;),  
    &#39;la cosa más fácil, equivocarnos;&#39;.Split(&#39; &#39;),  
    &#39;la más destructiva, la mentira y el egoísmo;&#39;.Split(&#39; &#39;),  
    &#39;la peor derrota, el desaliento;&#39;.Split(&#39; &#39;),  
    &#39;los defectos más peligrosos, la soberbia y el rencor;&#39;.Split(&#39; &#39;),  
    &#39;las sensaciones más gratas, la buena conciencia...&#39;.Split(&#39; &#39;)   
    ];  
    printJaggedArray(text);    
    upperCaseRandomArray(text);    
    printJaggedArray(text);    
    graphJaggedArray(text);
    
    // Array Exceptions    
    
    printTitle(&#39;Common Array Exceptions&#39;);    
    
    printCommonArrayExceptions(null);    
    printCommonArrayExceptions(text);    
    
    // Accessing Class Array Elements through Getter/Setter    
    printTitle(&#39;Alphabets&#39;);  

    var vowels: Alphabet = new Alphabet(5);  
    vowels.setItem(0, &#39;a&#39;);  
    vowels.setItem(1, &#39;e&#39;);  
    vowels.setItem(2, &#39;i&#39;);  
    vowels.setItem(3, &#39;o&#39;);  
    vowels.setItem(4, &#39;u&#39;);  

    print(&#39;\nVowels = {&#39;,   
        String.Join(&#39;,&#39;, vowels.getItem(0), vowels.getItem(1),
                    vowels.getItem(2), vowels.getItem(3), 
                    vowels.getItem(4)), &#39;}&#39;);  

    var en: Alphabet = new Alphabet(&#39;abcdefghijklmnopqrstuvwxyz&#39;);  
    print(&#39;English Alphabet = {&#39;, en.toString(), &#39;}&#39;);  

    print(&#39;Alphabet Extract en[9..19] = {&#39;,
            new Alphabet(en.slice(9, 10)).toString(), &#39;}&#39;);  
  
    var word1: String = String.Join(&#39;&#39;, en.getItem(6), en.getItem(14), 
                                    en.getItem(14), en.getItem(3));
    var word2: String = String.Join(&#39;&#39;, en.getItem(1), en.getItem(24), 
                                    en.getItem(4), en.getItem(4));
    var word3: String = String.Join(&#39;&#39;, en.getItem(4), en.getItem(21), 
                                    en.getItem(4), en.getItem(17),
                                   en.getItem(24), en.getItem(14), 
                                   en.getItem(13), en.getItem(4));  

    print(&#39;\n&#39;, word1, &#39;, &#39;, word2, &#39;, &#39;, word3, &#39;!\n&#39;);  

    Console.Read();  
};  
  
Main();
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq59V-FOLgu0dsWuWBGojUPj2bUeaAliWXfzw3t1KlMf27Ups3sQImtaA7jS9IBntUK-eBhyQDDLMZyEttNPiHdSH1iDQli2mFttHjeOQMZ7W9uMFs44pOVen1DyJ1swQVuBpZUTv4A_M/s1599/arrays_indexers_cs+-+Copie.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq59V-FOLgu0dsWuWBGojUPj2bUeaAliWXfzw3t1KlMf27Ups3sQImtaA7jS9IBntUK-eBhyQDDLMZyEttNPiHdSH1iDQli2mFttHjeOQMZ7W9uMFs44pOVen1DyJ1swQVuBpZUTv4A_M/s1600/arrays_indexers_cs+-+Copie.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/235808136187576609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2013/07/arrays-and-indexers-in-jscriptnet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/235808136187576609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/235808136187576609'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2013/07/arrays-and-indexers-in-jscriptnet.html' title='Arrays and Indexers in JScript.NET'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq59V-FOLgu0dsWuWBGojUPj2bUeaAliWXfzw3t1KlMf27Ups3sQImtaA7jS9IBntUK-eBhyQDDLMZyEttNPiHdSH1iDQli2mFttHjeOQMZ7W9uMFs44pOVen1DyJ1swQVuBpZUTv4A_M/s72-c/arrays_indexers_cs+-+Copie.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-694679611587040520.post-6913253348469255928</id><published>2013-07-16T09:29:00.000-07:00</published><updated>2017-04-21T03:29:31.665-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><title type='text'>Arrays and Indexers in C++/CLI</title><content type='html'>&lt;a class=&quot;twitter-share-button&quot; data-count=&quot;horizontal&quot; data-via=&quot;carlosqt&quot; href=&quot;http://twitter.com/share&quot;&gt;Tweet&lt;/a&gt;


&lt;br /&gt;
&lt;br /&gt;
Today&#39;s post is about Arrays and Indexers in C++/CLI. Here below you will find a very easy to follow program, that demonstrate arrays and indexer, by implementing some simple tasks that will make you grasp the idea of those 2 features real quick. The main goal of this post, is not really teaching arrays because, come on, you probably already know &quot;all&quot; about them, in fact, it is more to show you how you do that in C++/CLI, in this case, compared to all other 22 languages on future posts, which essentially, is the real aim behind this blog.&lt;br /&gt;
&lt;br /&gt;
By the way, if you missed my most recent post, &quot;&lt;a href=&quot;http://carlosqt.blogspot.be/2013/06/new-series-arrays-and-indexers.html&quot; target=&quot;_blank&quot;&gt;New Series - Arrays and Indexers&lt;/a&gt;&quot;, check it out. It has more details about the following program, and a bunch of definitions for the concepts used on this, and the following, posts. Or you can check my previous posts about arrays in C#, VB.NET and Oxygene just to compare. &lt;br /&gt;
&lt;br /&gt;
I encourage you to copy the code below and try it yourself, normally, all programs you find in this blog are source code complete, just paste it on your IDE and run it.&lt;br /&gt;
&lt;br /&gt;
Last thing. There is room for improvement of the code, using generics is one example, but Generics, Collections, lambdas, etc. will have their own &quot;series&quot; of posts.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: cpp&quot;&gt;// CppArrays.cpp : main project file.

#include &quot;stdafx.h&quot;

using namespace System;

namespace CppArrays {

    static array&amp;lt;wchar_t&amp;gt;^ ReverseChar(array&amp;lt;wchar_t&amp;gt;^ arr) {
        array&amp;lt;wchar_t&amp;gt;^ reversed = gcnew array&amp;lt;wchar_t&amp;gt;(arr-&amp;gt;Length);
        for (int i = 0, j = arr-&amp;gt;Length - 1; j &amp;gt;= 0; i++, j--) {
            reversed[i] = arr[i];
        }
        return reversed;
    }

    static array&amp;lt;int&amp;gt;^ BubbleSortInt(array&amp;lt;int&amp;gt;^ arr)  {  
        int swap = 0;  
        for (int i = arr-&amp;gt;Length - 1; i &amp;gt; 0; i--) {  
            for (int j = 0; j &amp;lt; i; j++) {  
                if (arr[j] &amp;gt; arr[j + 1]) {  
                    swap = arr[j];  
                    arr[j] = arr[j + 1];  
                    arr[j + 1] = swap;  
                }  
            }  
        }  
        return arr;  
    }  

    static array&amp;lt;String^&amp;gt;^ BubbleSortString(array&amp;lt;String^&amp;gt;^ arr) {  
        String^ swap = L&quot;&quot;;  
        for (int i = arr-&amp;gt;Length - 1; i &amp;gt; 0; i--) {  
            for (int j = 0; j &amp;lt; i; j++) {  
                if (arr[j][0] &amp;gt; arr[j + 1][0]) {  
                    swap = arr[j];  
                    arr[j] = arr[j + 1];  
                    arr[j + 1] = swap;  
                }  
            }  
        }  
        return arr;  
    }  

    static array&amp;lt;int, 2&amp;gt;^ TransposeMatrix(array&amp;lt;int, 2&amp;gt;^ m) {  
        /* Transposing a Matrix 2,3  
            *  
            * A =  [6  4 24]T [ 6  1]  
            *      [1 -9  8]  [ 4 -9] 
            *                 [24  8] 
        */  
        array&amp;lt;int, 2&amp;gt;^ transposed = gcnew array&amp;lt;int, 2&amp;gt;(m-&amp;gt;GetUpperBound(1) + 1,  
                                                        m-&amp;gt;GetUpperBound(0) + 1);  
        for (int i = 0; i &amp;lt; m-&amp;gt;GetUpperBound(0) + 1; i++) {  
            for (int j = 0; j &amp;lt; m-&amp;gt;GetUpperBound(1) + 1; j++) {  
                transposed[j, i] = m[i, j];  
            }  
        }  
        return transposed;  
    }  

    static void UpperCaseRandomArray(array&amp;lt;array&amp;lt;String^&amp;gt;^&amp;gt;^ arr) {  
        Random^ r = gcnew Random();
        int i = r-&amp;gt;Next(0, arr-&amp;gt;Length - 1);  
        for (int j = 0; j &amp;lt;= arr[i]-&amp;gt;Length - 1; j++)  
            arr[i][j] = arr[i][j]-&amp;gt;ToUpper();  
    }  

    static void PrintArrayChar(array&amp;lt;wchar_t&amp;gt;^ arr) {  
        Console::WriteLine(L&quot;\nPrint Array Content {0}&quot;,  
            arr-&amp;gt;GetType()-&amp;gt;Name-&amp;gt;Replace(L&quot;]&quot;, arr-&amp;gt;Length.ToString() + L&quot;]&quot;));  
  
        for (int i = 0; i &amp;lt;= arr-&amp;gt;Length - 1; i++)  
            Console::WriteLine(L&quot; array [{0,2}] = {1,2} &quot;, i, arr[i]);  
    }  

    static void PrintArrayInt(array&amp;lt;int&amp;gt;^ arr) {  
        Console::WriteLine(L&quot;\nPrint Array Content {0}&quot;,  
            arr-&amp;gt;GetType()-&amp;gt;Name-&amp;gt;Replace(L&quot;]&quot;, arr-&amp;gt;Length.ToString() + L&quot;]&quot;));  
  
        for (int i = 0; i &amp;lt;= arr-&amp;gt;Length - 1; i++)  
            Console::WriteLine(L&quot; array [{0,2}] = {1,2} &quot;, i, arr[i]);  
    }  

    static void PrintArrayString(array&amp;lt;String^&amp;gt;^ arr) {  
        Console::WriteLine(L&quot;\nPrint Array Content {0}&quot;,  
            arr-&amp;gt;GetType()-&amp;gt;Name-&amp;gt;Replace(L&quot;]&quot;, arr-&amp;gt;Length.ToString() + L&quot;]&quot;));  
  
        for (int i = 0; i &amp;lt;= arr-&amp;gt;Length - 1; i++)  
            Console::WriteLine(L&quot; array [{0,2}] = {1,2} &quot;, i, arr[i]);  
    }  
  
    static void PrintMatrix(array&amp;lt;int, 2&amp;gt;^ m) {  
        Console::WriteLine(L&quot;\nPrint Matrix Content {0}[{1},{2}]&quot;,  
            m-&amp;gt;GetType()-&amp;gt;Name-&amp;gt;Replace(L&quot;[,]&quot;, L&quot;&quot;),  
            (m-&amp;gt;GetUpperBound(0) + 1).ToString(),  
            (m-&amp;gt;GetUpperBound(1) + 1).ToString());  
  
        for (int i = 0; i &amp;lt;= m-&amp;gt;GetUpperBound(0); i++)  
            for (int j = 0; j &amp;lt;= m-&amp;gt;GetUpperBound(1); j++)  
                Console::WriteLine(L&quot; array [{0,2},{1,2}] = {2,2} &quot;, i, j, m[i, j]);  
    }  

    static void GraphJaggedArray(array&amp;lt;array&amp;lt;String^&amp;gt;^&amp;gt;^ arr) {  
        /* When using Arrays, we can use foreach instead of for:  
            *  
            * for (int i = 0; i &amp;lt;= arr.Length - 1; i++) 
            *   for (int j = 0; j &amp;lt;= arr.Length - 1; j++)                 
            *  
        */  
        Console::WriteLine(L&quot;\nPrint Text Content {0}&quot;, arr-&amp;gt;GetType()-&amp;gt;Name);  
        int lineCount = 1;  
        for each (array&amp;lt;String^&amp;gt;^ s in arr) {  
            Console::Write(L&quot;Line{0,2}|&quot;, lineCount);  
            for each(String^ w in s) {  
                Console::Write(L&quot;{0,3}&quot;, L&#39;*&#39;);  
            }  
            Console::WriteLine(L&quot; ({0})&quot;, s-&amp;gt;Length);  
            lineCount++;  
        }  
    }  

    static void PrintJaggedArray(array&amp;lt;array&amp;lt;String^&amp;gt;^&amp;gt;^ arr) {  
        System::Text::StringBuilder^ line;  
        Console::WriteLine(L&quot;\nPrint Jagged Array Content {0}&quot;, arr-&amp;gt;GetType()-&amp;gt;Name);  
        for (int i = 0; i &amp;lt;= arr-&amp;gt;Length - 1; i++) {  
            line = gcnew System::Text::StringBuilder();  
            for (int j = 0; j &amp;lt;= arr[i]-&amp;gt;Length - 1; j++)  
                line-&amp;gt;Append(L&quot; &quot; + arr[i][j]);  
            if (line-&amp;gt;ToString() == line-&amp;gt;ToString()-&amp;gt;ToUpper())  
                line-&amp;gt;Append(L&quot; &amp;lt;-- [UPPERCASED]&quot;);  
            Console::WriteLine(line);  
        }  
    }  

    static void PrintCommonArrayExceptions(array&amp;lt;array&amp;lt;String^&amp;gt;^&amp;gt;^ arr) {  
        try {  
            arr[100][100] = L&quot;hola&quot;;  
        }  
        catch (Exception^ ex) {  
            Console::WriteLine(L&quot;\nException: \n{0}\n{1}&quot;, 
                               ex-&amp;gt;GetType()-&amp;gt;Name, ex-&amp;gt;Message);  
        }  
    }  

    static void PrintTitle(String ^message) {
        Console::WriteLine();
        Console::WriteLine(L&quot;======================================================&quot;);  
        Console::WriteLine(L&quot;{0,10}&quot;, message);  
        Console::WriteLine(L&quot;======================================================&quot;);  
    }

    ref class Alphabet {        
    private:
        // Array Field  
        array&amp;lt;wchar_t&amp;gt;^ letters;  
    public:
        // Indexer Get/Set Property   
        property wchar_t default[int] {
            wchar_t get(int index) { return letters[index]; }
            void set(int index, wchar_t value) { letters[index] = Char::ToUpper(value);}
        }
        // Read-Only Property
        property int Length {
            int get() { return this-&amp;gt;letters-&amp;gt;Length; }
        }        
        // Constructors  
        Alphabet(int size) {  
            this-&amp;gt;letters = gcnew array&amp;lt;wchar_t&amp;gt;(size);  
        }  
        Alphabet(String^ list) {  
            this-&amp;gt;letters = list-&amp;gt;ToUpper()-&amp;gt;ToCharArray();  
        }    
        Alphabet(array&amp;lt;wchar_t&amp;gt;^ list) {  
            this-&amp;gt;letters = list;  
        }  
        // Overridden Method
        virtual String^ ToString() override {
            return String::Join(L&quot;,&quot;, gcnew String(this-&amp;gt;letters));
        }
        // Method  
        array&amp;lt;wchar_t&amp;gt;^ Slice(int start, int length) {  
            array&amp;lt;wchar_t&amp;gt;^ result = gcnew array&amp;lt;wchar_t&amp;gt;(length);  
            for (int i = 0, j = start; i &amp;lt; length; i++, j++) {  
                result[i] = this[j];  
            }  
            return result;  
        }  
    };
};

using namespace CppArrays;

int main(array&amp;lt;System::String ^&amp;gt; ^args)
{
    // Single-dimensional Array(s)  
    PrintTitle(L&quot;Reverse Array Elements&quot;);  
  
    // Declare and Initialize Array of Chars  
    array&amp;lt;wchar_t&amp;gt;^ letters = gcnew array&amp;lt;wchar_t&amp;gt;(5);  
    letters[0] = L&#39;A&#39;;  
    letters[1] = L&#39;E&#39;;  
    letters[2] = L&#39;I&#39;;  
    letters[3] = L&#39;O&#39;;  
    letters[4] = L&#39;U&#39;;  
  
    PrintArrayChar(letters);  
    array&amp;lt;wchar_t&amp;gt;^ inverse_letters = ReverseChar(letters);  
    PrintArrayChar(inverse_letters);  
  
    PrintTitle(L&quot;Sort Integer Array Elements&quot;);  
  
    // Declare and Initialize Array of Integers   
    array&amp;lt;int&amp;gt;^ numbers = { 10, 8, 3, 1, 5 };  
    PrintArrayInt(numbers);  
    array&amp;lt;int&amp;gt;^ ordered_numbers = BubbleSortInt(numbers);  
    PrintArrayInt(ordered_numbers);  
  
    PrintTitle(L&quot;Sort String Array Elements&quot;);  

    // Declare and Initialize and Array of Strings  
    array&amp;lt;String^&amp;gt;^ names = gcnew array&amp;lt;String^&amp;gt; {                       
            L&quot;Damian&quot;,   
            L&quot;Rogelio&quot;,  
            L&quot;Carlos&quot;,   
            L&quot;Luis&quot;,                       
            L&quot;Daniel&quot;  
        };  
    PrintArrayString(names);  
    array&amp;lt;String^&amp;gt;^ ordered_names = BubbleSortString(names);  
    PrintArrayString(ordered_names);  
  
    // Multi-dimensional Array (Matrix row,column)  
  
    PrintTitle(L&quot;Transpose Matrix&quot;);  
  
    /* Matrix row=2,col=3 
        * A =  [6  4 24] 
        *      [1 -9  8] 
    */  
    array&amp;lt;int, 2&amp;gt;^ matrix = gcnew array&amp;lt;int, 2&amp;gt;(2, 3) {{ 6, 4, 24 },   
                                                       { 1, -9, 8 }};  
    PrintMatrix(matrix);  
    array&amp;lt;int, 2&amp;gt;^ transposed_matrix = TransposeMatrix(matrix);  
    PrintMatrix(transposed_matrix);  
  
    // Jagged Array (Array-of-Arrays)  
  
    PrintTitle(L&quot;Upper Case Random Array &amp;amp; Graph Number of Elements&quot;);  
      
    /*              
    * Creating an array of string arrays using the String.Split method 
    * instead of initializing it manually as follows: 
    *  
    * array&amp;lt;array&amp;lt;String^&amp;gt;^&amp;gt;^ text = gcnew array&amp;lt;array&amp;lt;String^&amp;gt;^&amp;gt; {  
    *      gcnew array&amp;lt;String^&amp;gt; { &quot;word1&quot;, &quot;word2&quot;, &quot;wordN&quot; },
    *      gcnew array&amp;lt;String^&amp;gt; { &quot;word1&quot;, &quot;word2&quot;, &quot;wordM&quot; },  
    *      ... 
    *      }; 
    *  
    * Text extract from: &quot;El ingenioso hidalgo don Quijote de la Mancha&quot; 
    *  
    */  
    array&amp;lt;array&amp;lt;String^&amp;gt;^&amp;gt;^ text = {   
    (gcnew String(L&quot;Hoy es el día más hermoso de nuestra vida, querido Sancho;&quot;))-&amp;gt;Split(L&#39; &#39;),  
    (gcnew String(L&quot;los obstáculos más grandes, nuestras propias indecisiones;&quot;))-&amp;gt;Split(L&#39; &#39;),  
    (gcnew String(L&quot;nuestro enemigo más fuerte, miedo al poderoso y nosotros mismos;&quot;))-&amp;gt;Split(&#39; &#39;),  
    (gcnew String(L&quot;la cosa más fácil, equivocarnos;&quot;))-&amp;gt;Split(&#39; &#39;),  
    (gcnew String(L&quot;la más destructiva, la mentira y el egoísmo;&quot;))-&amp;gt;Split(&#39; &#39;),  
    (gcnew String(L&quot;la peor derrota, el desaliento;&quot;))-&amp;gt;Split(&#39; &#39;),  
    (gcnew String(L&quot;los defectos más peligrosos, la soberbia y el rencor;&quot;))-&amp;gt;Split(&#39; &#39;),  
    (gcnew String(L&quot;las sensaciones más gratas, la buena conciencia...&quot;))-&amp;gt;Split(&#39; &#39;)   
    };  
    PrintJaggedArray(text);  
    UpperCaseRandomArray(text);  
    PrintJaggedArray(text);  
    GraphJaggedArray(text);  
  
    // Array Exceptions  
  
    PrintTitle(L&quot;Common Array Exceptions&quot;);  
  
    PrintCommonArrayExceptions(nullptr);  
    PrintCommonArrayExceptions(text);  
  
    // Accessing Class Array Elements through Indexer  
  
    PrintTitle(L&quot;Alphabets&quot;);  
  
    Alphabet^ vowels = gcnew Alphabet(5);
    vowels[0] = L&#39;a&#39;;  
    vowels[1] = L&#39;e&#39;;  
    vowels[2] = L&#39;i&#39;;  
    vowels[3] = L&#39;o&#39;;  
    vowels[4] = L&#39;u&#39;;  
    
    Console::WriteLine(L&quot;\nVowels = {{{0}}}&quot;,  
        String::Join(L&quot;,&quot;, vowels[0], vowels[1], vowels[2], vowels[3], vowels[4]));  
  
    Alphabet^ en = gcnew Alphabet(L&quot;abcdefghijklmnopqrstuvwxyz&quot;);  
    Console::WriteLine(L&quot;English Alphabet = {{{0}}}&quot;, en);  
  
    Console::WriteLine(L&quot;Alphabet Extract en[9..19] = {{{0}}}&quot;,   
                    gcnew Alphabet(en-&amp;gt;Slice(9, 10)));  
  
    String^ word1 = String::Join(L&quot;&quot;, en[6], en[14], en[14], en[3]);  
    String^ word2 = String::Join(L&quot;&quot;, en[1], en[24], en[4]);  
    String^ word3 = String::Join(L&quot;&quot;, en[4], en[21], en[4], en[17],  
                                    en[24], en[14], en[13], en[4]);  
  
    Console::WriteLine(L&quot;\n{0} {1}, {2}!\n&quot;, word1, word2, word3);  


    return 0;
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
The output: 
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq59V-FOLgu0dsWuWBGojUPj2bUeaAliWXfzw3t1KlMf27Ups3sQImtaA7jS9IBntUK-eBhyQDDLMZyEttNPiHdSH1iDQli2mFttHjeOQMZ7W9uMFs44pOVen1DyJ1swQVuBpZUTv4A_M/s1599/arrays_indexers_cs+-+Copie.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq59V-FOLgu0dsWuWBGojUPj2bUeaAliWXfzw3t1KlMf27Ups3sQImtaA7jS9IBntUK-eBhyQDDLMZyEttNPiHdSH1iDQli2mFttHjeOQMZ7W9uMFs44pOVen1DyJ1swQVuBpZUTv4A_M/s1600/arrays_indexers_cs+-+Copie.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà, that&#39;s it. Next post in the following days.
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://carlosqt.blogspot.com/feeds/6913253348469255928/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://carlosqt.blogspot.com/2013/07/arrays-and-indexers-in-ccli.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/6913253348469255928'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/694679611587040520/posts/default/6913253348469255928'/><link rel='alternate' type='text/html' href='http://carlosqt.blogspot.com/2013/07/arrays-and-indexers-in-ccli.html' title='Arrays and Indexers in C++/CLI'/><author><name>Carlos Quintanilla</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq59V-FOLgu0dsWuWBGojUPj2bUeaAliWXfzw3t1KlMf27Ups3sQImtaA7jS9IBntUK-eBhyQDDLMZyEttNPiHdSH1iDQli2mFttHjeOQMZ7W9uMFs44pOVen1DyJ1swQVuBpZUTv4A_M/s72-c/arrays_indexers_cs+-+Copie.png" height="72" width="72"/><thr:total>1</thr:total></entry></feed>