mio Tutorial

Expressions

mio> 1 + 2
===> 3
mio> 1 + 2 * 3
===> 9
mio> 1 + (2 * 3)
===> 7

Note

mio has no operator precedence (in fact no operators). You must use explicit grouping with parenthesis where appropriate in expressions.

Variables

mio> a = 1
===> 1
mio> a
===> 1
mio> b = 2 * 3
===> 6
mio> a + b
===> 7

Conditionals

mio> a = 2
===> 2
mio> (a == 1) ifTrue(print("a is one")) ifFalse(print("a is not one"))
a is not one

Lists

mio> xs = [30, 10, 5, 20]
===> [30, 10, 5, 20]
mio> len(xs)
===> 4
mio> print(xs)
[30, 10, 5, 20]
mio> xs sort()
===> [5, 10, 20, 30]
mio> xs[0]
===> 5
mio> xs[-1]
===> 30
mio> xs[2]
===> 20
mio> xs remove(30)
===> [5, 10, 20]
mio> xs insert(1, 123)
===> [5, 123, 10, 20]

Iteration

mio> xs = [1, 2, 3]
===> [1, 2, 3]
mio> xs foreach(x, print(x))
1
2
3
mio> it = iter(xs)
===> it(Object) at 0x7f1f79af09a8:
       N               = 2
       i               = -1
       iterable        = [1, 2, 3]
mio> next(it)
===> 1
mio> next(it)
===> 2
mio> next(it)
===> 3
mio> next(it)

  StopIteration: 
  --------------
  raise(StopIteration) 

  ifFalse(
 raise(StopIteration) 
) 

  __next__ 

  next(it)

Strings

mio> a = "foo"
===> u"foo"
mio> b = "bar"
===> u"bar"
mio> c = a + b
===> u"foobar"
mio> c[0]
===> u'f'
mio> s = "this is a test"
===> u"this is a test"
mio> words = s split()
===> [u"this", u"is", u"a", u"test"]
mio> s find("is")
===> 2
mio> s find("test")
===> 10

Functions

mio> foo = block(
....     print"foo"
.... )
===> block():
       args            = args()
       body            = body()
       kwargs          = kwargs()
mio> foo()
===> u"foo"
mio> add = block(x, y,
....     x + y
.... )
===> block(x, y):
       args            = args()
       body            = body()
       kwargs          = kwargs()
mio> add(1, 2)
===> 3

Note

Functions in mio do not have access to any outside state or globals (there are no globals in mio) with the only exception to the rule being closures.

Objects

mio> World = Object clone()
===> World(Object) at 0x7fc0bbe7b9a8
mio> World
===> World(Object) at 0x7fc0bbe7b9a8

Attributes

mio> World = Object clone()
===> World(Object) at 0x7fea4d2539a8
mio> World
===> World(Object) at 0x7fea4d2539a8
mio> World name = "World!"
===> u"World!"
mio> World name
===> u"World!"

Methods

mio> World = Object clone()
===> World(Object) at 0x7f6a2e2949a8
mio> World
===> World(Object) at 0x7f6a2e2949a8
mio> World name = "World!"
===> u"World!"
mio> World name
===> u"World!"
mio> World hello = method(
....     print("Hello", self name)
.... )
===> method():
       args            = args()
       body            = body()
       kwargs          = kwargs()
mio> World hello()
Hello World!

Note

Methods implicitly get the receiving object as the first argument self passed.

Traits

mio> TGreetable = Object clone() do (
....     hello = method(
....         print("Hello", self name)
....     )
.... )
===> TGreetable(Object) at 0x7f7ced2859a8:
       hello           = method()
mio> World = Object clone() do (
....     uses(TGreetable)
.... 
....     name = "World!"
.... )

  AttributeError: Object has no attribute 'uses'
  ---------------
  uses(TGreetable) 
 
 set(name, World!) 

  do(
 uses(TGreetable) 
 
 set(name, World!) 
)
  set(World, Object clone do(
 uses(TGreetable) 
 
 set(name, World!) 
))

mio> World

  AttributeError: Object has no attribute 'World'
  ---------------
  World

mio> World traits

  AttributeError: Object has no attribute 'World'
  ---------------
  World traits

mio> World behaviors

  AttributeError: Object has no attribute 'World'
  ---------------
  World behaviors

mio> World hello()

  AttributeError: Object has no attribute 'World'
  ---------------
  World hello