# Pony Introduction

### by "Blag" - Senior Developer Evangelist ## Who uses Pony?

• Too young and still in development...

## Basic Concepts

### Precedence must be enforced by parenthesis...otherwise you will get an error...

```				```
actor Main

new create(env: Env) =>

var number:I8 = (2 * 3) + 5

env.out.print("" + number.string())
``````

## Variables

### Arrays are easy...

```				```
actor Main

new create(env: Env) =>

var array: Array[String] = ["A","B","C"]

var elem: String = try array(0) else "" end

env.out.print(elem)
``````
```				```
for elem in array.values() do

env.out.print(elem)

end
``````

### We can create an array of arrays...

```				```
actor Main

new create(env: Env) =>

var array: Array[Array[String]] =

[["A","B","C"],["1","2","3"]]

for i in ["0","1"].values() do

for j in ["0","1","2"].values() do

var elem: String =

try array(i.u64())(j.u64())

else "" end

env.out.print(elem)

end

end
``````

### In Pony, everything is an expression...that's why we can do something like this...

```				```
actor Main

new create(env: Env) =>

var myNumber:I8 = 10

myNumber = myNumber + if myAdd == 5

then 15 else 1 end

env.out.print(myNumber.string())
``````

### One weird thing aboout Pony...in order to create functions...you must create a class...

```				```

a + b

actor Main

new create(env: Env) =>

env.out.print(num.string())
``````

## Fibonacci List

### Name your file "main.pony" inside a folder called "fibonacci"

```				```
class Fibo

fun get_fibo(num:I32,a:I32,b:I32):String =>

var result:String = ""

if (a > 0) and (num > 1) then

result = result + (a+b).string() + " " +

get_fibo(num-1,a+b,a)

elseif (a == 0) then

result = a.string() + " " + b.string() +

" " + (a+b).string() + " " +

get_fibo(num-1,a+b,b)

end

result
``````
```				```
actor Main

new create(env: Env) =>

var sNum:String = try env.args(1) else "" end

var num:I32 = try sNum.i32() else 0 end

var line:String = Fibo.get_fibo(num,0,1)

env.out.print(line)
``````

## Making an LED Number App

### Name your file "main.pony" inside a folder called "lednumbers"

```				```
actor Main

new create(env: Env) =>

let leds: Array[Array[String]] =

[[" _  ","| | ","|_| "],

["  ","| ","| "],

[" _  "," _| ","|_  "],

["_  ","_| ","_| "],

["    ","|_| ","  | "],

[" _  ","|_  "," _| "],

[" _  ","|_  ","|_| "],

["_   "," |  "," |  "],

[" _  ","|_| ","|_| "],

[" _  ","|_| "," _| "]]
``````
```				```
var num: String = try env.args(1) else "" end

var i: I64 = 0

var j: I64 = 0

var line: String = ""

var sizec: I64 = try num.size().string().i64()

else 0 end
``````
```				```
while i < 3 do

while j < sizec do

try line =

line.insert(line.size().string().i64(),

leds(num.substring(j,j).u64())

(i.string().u64())) else "" end

j = j + 1

end

i = i + 1

j = 0

env.out.print(line)

line = ""

end

env.out.print("")
``````

## Random Names

### Name your file "main.pony" inside a folder called "random_names"

```				```
use "collections"

use "random"

actor Main

new create(env: Env) =>

let names:Array[String] = ["Anne","Gigi","Blag",

"Juergen","Marek",

"Ingo","Lars","Julia",

"Danielle","Rocky",

"Julien","Uwe","Myles",

"Mike","Steven","Fanny"]
``````
```				```

"Schmerder",

"Kowalkiewicz",

"Sauerzapf",

"Karg","Satsuta",

"Keene",

"Ongkowidjojo",

"Vayssiere",

"Kylau","Fenlon",

"Flynn","Taylor",

"Tan"]
``````
```				```
var elem1: String = ""

var elem2: String = ""

var full_names: Array[String] = [""]

let dice = Dice(MT)

for i in Range(0, 100000) do

elem1 = try names(dice(1,16) - 1)

else "" end

elem2 = try last_names(dice(1,16) - 1)

else "" end

try full_names.insert(0,elem1 + " " + elem2)

else "" end

end
``````

## Decimal to Romans

### Name your file "main.pony" inside a folder called "decimal_to_romans"

```				```
class Romans

fun get_romans(num:I32,ctr:U64,

result:String):String =>

var response:String = ""

let roman_nums: Array[Array[String]] =

[["1000","M"],["900","CM"],

["500","D"],["400","CD"],

["100","C"],["90","XC"],

["50","L"],["40","XL"],

["10","X"],["9","IX"],

["5","V"],["4","IV"],

["1","I"]]
``````
```				```
var line:String = try roman_nums(ctr)(0)

else "" end

var iline = try line.i32() else 0 end

if(num >= iline) then

var value:String = try roman_nums(ctr)(1)

else "" end

response = value +

get_romans((num - iline), ctr,

result)

elseif (num < iline) and (num > 0) then

response = get_romans(num, (ctr + 1),

result)

end

response
``````
```				```
actor Main

new create(env: Env) =>

var sNum:String = try env.args(1) else "" end

var num:I32 = try sNum.i32() else 0 end

var result:String = ""

result = Romans.get_romans(num,0,"")

env.out.print(result)
``````