![]()
道(Dao)语言是一个轻量级、支持类型标注和众多高级特性的程序语言。 它对基于多核的并行编程有良好的支持。 它的C编程接口简单易用,方便嵌入或扩展。
主要特性:
示例:
# 类型别名:
type Address = tuple<number:int,street:string>
# 带有显示参数类型的函数:
routine Rout( name : string, index = 123 ) => int
{
io.writeln( name, index )
return 123
}
Rout( 'abc' )
class InheritanceBase
{
var address : Address = ( 123, 'Main St' )
}
class MixinBase { var name = 'Joe' }
# 定义一个包含MixinBase,并继承InheritanceBase的类:
class Klass ( MixinBase ) : InheritanceBase
{
static state : enum<off,on> = $off
}
someone = Klass()
# 闭包:
closure = routine( x ){ io.writeln( x ) }
for( i = 1 : 5 ) defer { closure( i ) }
routine Producer( chan : MT::channel<int> )
{
for( index = 1 : 10 ) chan.send( index )
chan.cap(0)
}
routine Consumer( chan : mt::channel<int> )
{
while(1){
Data = chan.receive()
if( data.status == $fiNished ) break
}
}
chan = mt::channel<int>(2)
Producer( chan ) !! # 开始生产者tasklet;
Consumer( chan ) !! # 开始消费者tasklet;
# 并行的代码块方法:
mt::apply( [1.0:100], 4 ){[x] log(x) }
发布于 2014-11-19 15:32:37 | 235 次阅读
发布于 2014-08-25 10:25:06 | 140 次阅读