Welcome to SpellCoder Sign in | Join | Help

Boo a new language for CLI family


Boo is a new programming language under development, you can consider it a static type Python Big Smile [:D] because the syntax looks very much like Python, but it is still static type language

first let's start with HelloWorld application

print "Hello World"

pretty simple and pretty much like Python,
let's see something more, what about fibonacci searies with boo generators

def fib(limit as long):
    a, b = 0L, 1L
    while b < limit:
        yield b
        a, b = b, a + b
       
x = [i for i in fib(100)]
print x


and the result will be a list
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
as you see it is very much like python but with type checking

and now let's see a Boo Windows Forms application Wink [;)]
import System.Windows.Forms
import System.Drawing

class MyForm(Form):
def constructor(message as string):
b = Button(Text: "Click Me")
b.Location = Point(100, 50)
b.Click += do():
MessageBox.Show(message)

self.Controls.Add(b)

f = MyForm("you clicked the button!")
Application.Run(f)
and the result will be just like that


and it comes with some new things like Carrying
plusX = { a as int | return { b as int | return a + b }}
print plusX(3)(4)
In English: "plusX is a function taking integer a, which returns another function taking integer b that returns a+b."

Duck Typing
This is one of the coolest things in Boo, that even it is a static typed language that written like python, but sometimes it acts like dynamic language if you want, just use the duck type like this
static1 as int  //type is fixed to be an integer
dynamic1 as duck //can be anything

static1 = 0
dynamic1 = 0
print static1 + 1 //-> 1
print dynamic1 + 1 //-> 1

#static1 = "Some string" //error, cannot cast string to int
dynamic1 = "Some string" //dynamic1 can be "any" type of thing

#print static1.ToUpper() //error, a1 is an int, not a string
print dynamic1.ToUpper() //-> SOME STRING

//You can convert a static type to a dynamic duck type:
dynamic2 as duck = static1
print dynamic2 //-> 0
dynamic2 = "Some string"
print dynamic2.ToUpper() //-> SOME STRING

//or convert a dynamic type to a static type
static2 as string = dynamic1
print static2.ToUpper()

#static3 as int = dynamic1 //error, cannot cast string to int
#print static3 + 2
booish.exe
booish.exe is interactive interpreter tool, just like python console that you can run code against it and get the results immediately
>>> 3 + 4
7
>>> _ * 2
14
so, as a concolusion for this, Boo is a good competitor for Iron Python, as it can act like a dynamic language as well as being a static language that gets more features from dotnet,

my next article I think, it will be about Boo and WWF, just to see if it will run right or it will have the same problem as Iron Python

at last, you can start write codes for Boo with SharpDevelop and you'll get all the IDE features like Intellisence, Coloring and Debugging

Regards

Published Thursday, May 11, 2006 3:11 AM by Mohammed Hossam
Filed Under: ,

Comments

No Comments

Anonymous comments are disabled