#+TITLE: Learning Io
- tags :: 7_languages_in_7_weeks Does this language impact the way I think?
What you did and did not understand
- I liked the syntax - it felt like cheating in some ways it was so straightforward
- I liked the concurrency - yielding in predictable places. sync/async bugs are horrible and this seems like a much more sensible and safe approach to it.
- I liked how small it was
- I struggled with the 'everything is a message' - I'm not sure I fully understand what a message is in Io -##What they thoought the key points were
- A light-weight language that is useful in building up very specific DSL
####What they did not agree with
What ideas related to other writings
- Interesting to think of JS as a prototyping language. There is inheritance, there is the ability to override default methods, there is a lot of similarity. ##How the work could be improved
1 + 1
```
I did a lot of literate programming here but then did an example of an infinite loop. I couldn't quit the loop and lost the entire buffer. Whoops!
Nth Fibonacci Number using recursion
``` io
Fib := Object clone
Fib gen := method(n, if(n == 1 or n ==2, 1, gen(n-1) + gen(n-2)))
Fib gen(13)
```
#+RESULTS:
: 233
Overload / to return 0 if the denominator is 0
``` io
origDiv := Number getSlot("/")
Number / = method(i, if(i != 0, origDiv(i), 0))
123/0
```
#+RESULTS:
: 0
Sum a 2D array
``` io
a := list()
a append(list(2,3,2,4))
a append(list(5,53,5,5))
a map(i, v, v sum) sum
```
#+RESULTS:
: 79
``` io
a := list()
a append(list(2,3,2,4))
a append(list(5,53,5,5))
a reduce(x, y, x sum + y sum)
```
#+RESULTS:
: 79
Add a myAverage
``` io
myList := list()
myList myAverage := method(sum / self size)
myList append(1,3,4,2,4,2,3) myAverage
```
#+RESULTS:
: 2.7142857142857144
2D array
``` io
TwoDimArray := List clone
TwoDimArray dim := method(x, y,
for(p, 1 , y, append(y)))
TwoDimArray dim(3, 4)
```
#+RESULTS:
: list(4, 4, 4, 4)
Write a programming
``` io
guess := 0
number := 7
while (guess < 10,
"Guess the number: " println
x := File standardInput readLine fo
if(x == number, "You got it" println, guess = guess + 1)
)
```
#+RESULTS:
#+begin_example
Guess the number:
Guess the number:
Guess the number:
Guess the number:
Guess the number:
Gus the number:
Guess the number:
Guess the number:
Guess the number:
Guess the number:
10
#+end_example