weekly 2023-09-18
MoonBit更新
1. 新增 Int64 内置类型
MoonBit新增Int64内置类型,Int64类型的整数必须以L作为后缀,比如
func init {
let a = 9_223_372_036_854_775_807L
print(a)
}
上述程序输出:
9223372036854775807
2. 移除了内置方法t.print(), 改为函数print[T : Show](t : T)
只要实现了to_string方法的类型都可以被print输出,比如
enum Tree[T]{
Node(Tree[T],Tree[T])
Leaf(T)
}
func to_string[T : Show](self : Tree[T]) -> String {
match self {
Node(l,r) => "Tree(\(l), \(r))"
Leaf(v) => "Leaf(\(v))"
}
}
func init {
let tree = Tree::Node(Leaf(1),Node(Leaf(2),Leaf(3)))
// tree.print() // old method
print(tree) // new method
}
上述程序输出:
Tree(Leaf(1), Tree(Leaf(2), Leaf(3)))