# boo 0.8.2

Version of implementation Boo of programming language BooA version of Boo language, released on May 19, 2008.

## Links:

## Examples:

### Hello, World! - Boo (246):

```
print("Hello, World!")
```

### Factorial - Boo (247):

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 - Boo (248):

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 - Boo (249):

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 - Boo (250):

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 - Boo (276):

```
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})"
```

## Comments

]]>blog comments powered by Disqus

]]>