# Open Euphoria Introduction

## Who uses Open Euphoria?

• Haven't found any -:(.

## Basic Concepts

### Well...there's also object but that's the father of atom and sequence...

```				```
atom myatom

sequence mysequence

sequence anothersequence

myatom = 2016

mysequence = "This is the year "

anothersequence = {'H','e','l','l','o'}

puts(1,mysequence)

print(1, myatom)

puts(1,"\n")

puts(1,myatom)

puts(1,"\n")

puts(1,anothersequence)
``````

## Maps

### Open Euphoria doesn't have arrays, but we can use maps

```				```
include std/map.e

sequence myvalue

map myMap = new()

put(myMap, 0, "A")

put(myMap, 1, "B")

put(myMap, 2, "C")

for i = 0 to 2 do

myvalue = map:get(myMap,i)

puts(1,myvalue)

puts(1,"\n")

end for
``````

## Functions and Procedures

### Procedures doesn't return a value...

```				```
atom result

function sum(atom a, atom b)

atom sum

sum = a + b

return sum

end function

result = sum(4,8)

print(1,result)
``````
```				```
procedure test()

puts(1,"\nHello World!")

end procedure

test()
``````

## Callable Functions

### We can call a function as a parameter of another function

```				```
function sum(atom a, atom b)

return a + b

end function

function multi(atom a, atom b)

return a * b

end function

function operation(integer f, atom a, atom b)

return call_func(f ,{a,b})

end function

print(1,operation(routine_id("sum"),4,8)) puts(1,"\n")

print(1,operation(routine_id("multi"),4,8))
``````

## Fibonacci List

### Finally...we're going to make our first application...

```				```
include std/convert.e

include get.e

atom num

sequence result = ""
``````
```				```
function fib(atom num, atom a, atom b)

sequence result = ""

if a > 0 and num > 1 then

result = result & to_string(a+b) &

" " & fib(num-1, a+b, a)

end if

if a = 0 then

result = to_string(a) & " " &

to_string(b) & " " &

to_string(a+b) & " " &

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

end if

return result

end function
``````
```				```
num = prompt_number("Enter a number: ",{})

result = fib(num,0,1)

puts(1,result)
``````

## Making an LED Number App

### This is one of my favorite codes of all time...

```				```
include get.e

include std/map.e

include std/convert.e

include std/sequence.e

sequence num

sequence snum

object onum

atom anum
``````
```				```
map leds = new()

put(leds, 0, {" _  ","| | ","|_| "})

put(leds, 1, {"  ","| ","| "})

put(leds, 2, {" _  "," _| ","|_  "})

put(leds, 3, {"_  ","_| ","_| "})

put(leds, 4, {"    ","|_| ","  | "})

put(leds, 5, {" _  ","|_  "," _| "})

put(leds, 6, {" _  ","|_  ","|_| "})

put(leds, 7, {"_   "," |  "," |  "})

put(leds, 8, {" _  ","|_| ","|_| "})

put(leds, 9, {" _  ","|_| "," _| "})
``````
```				```
num = prompt_string("Enter a number: ")

snum = breakup(num,1)

for i = 1 to 3 do

for j = 1 to length(num) do

anum = to_number(snum[j])

onum = map:get(leds,anum)

puts(1,onum[i])

end for

puts(1,"\n")

end for

puts(1,"\n")
``````

## Random Names

### We will measure the runtime

```				```
sequence full_name = {}

sequence full_names = {}

full_name = ""

full_names = repeat(" ", 100000)

sequence names = {{"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"},{"Flint"},

{"Taylor"},{"Tan"}}

for i = 1 to 100000 do

full_name = names[rand(16)] &

" " & last_names[rand(16)]

full_names[i] = full_name

end for
``````

## Decimal to Romans

### This will include some nice commands...

```				```
include get.e include std/map.e include std/sort.e

atom num

sequence onum sequence key

sequence result = ""

map romans = new()

put(romans, 1000, "M") put(romans, 900, "CM")

put(romans, 500, "D") put(romans, 400, "CD")

put(romans, 100, "C") put(romans, 90, "CX")

put(romans, 50, "L") put(romans, 40, "XL")

put(romans, 10, "X") put(romans, 9, "IX")

put(romans, 5, "V") put(romans, 4, "IV")

put(romans, 1, "I")
``````
```				```
function Roman_Number(atom num,sequence key,map romans)

sequence result = ""

while num > 0 do

for i = 1 to 13 do

if num >= key[i] then

result = result & map:get(romans,key[i])

num = num - key[i]

exit

end if

end for

end while

return result

end function
``````
```				```
print("Enter a number: ")

num = int( input() )

print(Roman_Number(num))

printl("")
``````

## Count Letters

### "This is a text file that we're going to read it using Open Euphoria"

```				```
include std/sequence.e

include std/map.e

include std/io.e

integer file_num

sequence file

sequence letters

object letter

function PrintValues(object k, object v,

object d, integer pc)

writefln("[] = []", {k, v})

return 0

end function
``````
```				```

file = gets(file_num)

letters = breakup(file,1)

map list_letters = new()

for i = 1 to length(letters) do

if(map:has(list_letters,letters[i]) = 0) then

put(list_letters,letters[i],1)

else

letter = map:get(list_letters,letters[i])

put(list_letters,letters[i],letter + 1)

end if

end for

map:for_each(list_letters,routine_id("PrintValues"))

``````