BrainDump
  Home arrow BrainDump arrow Page 3 - A Quick Tour of Boo
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

A Quick Tour of Boo
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-08-06

    Table of Contents:
  • A Quick Tour of Boo
  • Program Structure and Variables
  • Arrays and Collections
  • Conditionals and Loops
  • Functions and Types

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Ziff Davis Enterprise Virtual Tradeshows: Hot Topics, Cutting Edge Technology, Real-time Interaction with IT Professionals. Learn more at ziffdavisvts.com

    A Quick Tour of Boo - Arrays and Collections
    (Page 3 of 5 )

    In Boo, arrays are defined a little differently from the way they are defined in other languages. Here, we create an array of integers and an array of strings:

    ints = array(int,4)

    ints[0] = 3

    ints[1] = 6

    ints[2] = 8

    ints[3] = 90

    strings = array(string, ["one", "two", "three"])

    Note how the type of the array's elements is passed, followed by either the size of the array or the array's elements.

    One very useful feature of arrays is slicing, which Python users will recognize. Slicing provides an easy way to extract a portion of an array:

    theArray = [1, 2, 3, 4, 5]

    print theArray[1:]

    print theArray[1:3]

    print theArray[2:]

    [2, 3, 4, 5]

    [2, 3]

    [3, 4, 5]

    Boo has support for two built-in collections, lists (for which slicing also works) and hashtables:

    a = [4, 8, 15, 16, 23, 42]

    a[0] = 8

    a[1] = 15

    a.Add(16)

    b = {"jdoe": "John Doe", "jsmith": "John Smith"}

    b["msmith"] = "Mary Smith"

    However, the two collections are not type-safe:

    c = [1,2]

    c.Add("three")

    d = {1: "one", "two": 2}

    Fortunately, Boo has recently added support for generics, so one can create a type-safe collection using the collections in System.Collections.Generic:

    import System.Collections.Generic

     

    names = List of string()

    names.Add("John")

    names.Add("Sam")

    names.Add("Mary")

     

    rooms = Dictionary[of int,string]()

    rooms.Add(100, names[0])

    rooms.Add(200, names[1])

    rooms.Add(300, names[2])

    More BrainDump Articles
    More By Peyton McCullough


       · Hello, all,I've always found Python's syntax particularly pleasing, but, at the...
     

       

    BRAINDUMP ARTICLES

    - Outsourcing: the Hoopla, the Reality
    - MySQL Plays in the Sun
    - All About SQL Functions
    - SQL: Functioning in the Real World
    - More Advanced SQL Statements
    - Beginning SQL the SEQUEL: Working with Advan...
    - Beginning SQL
    - A Look at the VI Editor
    - A Quick Tour of Boo
    - Book Review: Open Source Licensing
    - PGP and GPG: Email for the Practical Parano...
    - Microsoft Continues War on Open Source
    - Secure Remote Desktop Sharing with VNC on Li...
    - A Look at Google Project Hosting
    - What we can Learn from Two Linux vs. Microso...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway