Boo

Appeared in:
2003
Influenced by:
Paradigm:
Typing discipline:
File extensions:
.boo
Versions and implementations (Collapse all | Expand all):
Programming language

Boo is an object-oriented language for CLI.

Boo was created in 2003 by Rodrigo Barreto de Oliveira, in an attempt to combine Python syntax and capabilities of .NET framework. Some of the purposes stated in Boo Manifesto are:

  • clean and wrist-friendly syntax. It should be Python-like, provide some syntactic sugar for common programming patterns, automate variable declaration, type inference and type casting, and need no classes (at least for small programs).
  • expressiveness: functions as first-class objects, generators (language constructs that produce multiple values when used in loops) and duck typing should ensure this.
  • extensibility: syntactic attributes and macros, and extensible compilation pipeline.
  • support for Common Language Infrastructure.

Elements of syntax:

Inline comments //
Non-nestable comments /* ... */
Variable assignment variable = value
Variable declaration variable as type
Variable declaration with assignment variable as type = value
Block indentation
Comparison < > <= >=
Function definition def f(p1 as type1, p2 as type2, ...) as returntype:
Function call f(a, b, ...)
Function call with no parameters f()
Sequence end of line
If - then if condition: ...
If - then - else if condition: ... else: ...
For each value in a numeric range, 1 increment for i in range(1,11): ...

Examples:

Hello, World!:

Example for versions boo 0.8.2
print("Hello, World!")

Factorial:

Example for versions boo 0.8.2

This example uses recursive factorial definition. The function factorial is called recursively, so it needs an explicit declaration of its return type.

def factorial(n as long) as long:
    if n == 0:
        return 1
    else:    
        return n * factorial(n - 1)

for n in range(0, 17):
	print("${n}! = ${factorial(n)}")

Factorial:

Example for versions boo 0.8.2

This example uses iterative factorial definition. Variable fact needs an explicit type declaration, since otherwise it will be typed as int, and trying to calculate 13! will cause an overflow error.

fact as long = 1
for i in range(17):
    print("${i}! = ${fact}")
    fact = fact * (i+1)

Fibonacci numbers:

Example for versions boo 0.8.2

This example uses iterative definition of Fibonacci numbers. The array a is declared to have 16 elements right away, and the elements are calculated later.

a = array(int, 16)
a[0] = a[1] = 1
for i in range(2,16):
    a[i] = a[i-1] + a[i-2]
s=""
for i in range(16):
    s = s + a[i] + ", "
print(s + "...")

Fibonacci numbers:

Example for versions boo 0.8.2

This example shows the usage of generator fib: it initializes inner variables a and b, and after each call to generator it updates the variables and returns one of them. Function zip is a built-in which returns an IEnumerable that is a “mesh” of two IEnumerables — range and fib.

def fib():
    a, b = 0, 1
    while true:
        yield b
        a, b = b, a + b
 
s=""
for i, n in zip(range(16), fib()):
    s = s+n+", "
print(s+"...")

Quadratic equation:

Example for versions boo 0.8.2
A = int.Parse(prompt("A = "))
if A==0 :
    print "Not a quadratic equation."
    return
B = int.Parse(prompt("B = "))
C = int.Parse(prompt("C = "))
D = B*B-4*A*C
if D==0 :
    x = -0.5*B/A
    print "x = ${x}"
    return
if D>0 :
    x1 = 0.5*(-B-System.Math.Sqrt(D))/A
    x2 = 0.5*(-B+System.Math.Sqrt(D))/A
    print "x1 = ${x1}"
    print "x2 = ${x2}"
else :
    r = -0.5*B/A
    i = 0.5*System.Math.Sqrt(-D)/System.Math.Abs(A)
    print "x1 = (${r},${i})"
    print "x2 = (${r},-${i})"