Io

起步

"hello world" print # 打印Vehicle := Object clone # 复制现有对象创建新对象Vehicle printVehicle desc := "a vehicle" # 给一个槽赋值Vehicle desc print # 输出槽Vehicle slotNames print # 获取所有槽

原型与对象

Vehicle := Object clonecar := Vehicle clone # Vehicle的实例Bike := Vehicle clone # 创建一个继承于Vehicle的Bikecar name := "terrbyte"car name print

方法

obj := Object cloneobj say := method("go out" println) # 定义一个方法obj sayobj proto print # 打印原型

list 和 map

list := list(1,2,3)list average printlnlist sum printlnlist at(1) printlnlist append(1)list pop printlnlist isEmpty printlnmap := Map clonemap atPut("name","cxk")map at("name") println

true false

true and false printlnfalse or true println

注意:0代表true

单例

true clone println // itselfVehicle := Object cloneVehicle clone := Vehicle # 创建自己的单例(Vehicle clone == Vehicle clone) println

循环与条件

#loop("cxk" println) # 死循环i := 1;while(i <= 10,i print;i = i+1)for(j,1,11,j print)for(j, 1, 10, 2, j print) # 自定义步长为2if(1 == 1,"true" print, "false" print)

运算符

OperatorTable addOperator("xor", 11)true xor := method(bool, if(bool, true, false)) # 定义xor结果为true的运算函数false xor := method(bool, if(bool, false, true)) # 定义xor结果为false的运算函数true xor false println

消息

反射

DSL

通过IO的运算符定义 可以实现DSL

forward

类似于ruby中的method_missiing

object := Object cloneobject forward := method(call message name println)object unknow

并发

thread1 := Object clonethread2 := Object clonethread1 run := method(  for(i,1,10, i println;yield))thread2 run := method(  for(i,11,20, i println;yield))thread1 @@run; thread2 @@runCoroutine currentCoroutine pause

核心优势

不足