V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Moonbit
V2EX  ›  编程

国产编程语言 MoonBit 最新动态来啦!目前本地 VS Code 插件可以自动执行 `moon check --watch`

  •  
  •   Moonbit · 130 天前 · 578 次点击
    这是一个创建于 130 天前的主题,其中的信息可能已经有所发展或是发生改变。

    MoonBit 更新

    1. 添加 Debug 接口

    interface Debug {
      debug_write(Self, Buffer)
    }
    

    以及debug[X: Debug](X) 函数。并且给内建类型实现了 Debug 接口。和之前的 Show 接口相比,Debug 的性能更好,而且会正确地在类型为 String 的值的两侧加上双引号。在输出调试信息时,我们鼓励用户用 Debug 代替 Show,用 debug 代替 println。未来 Showprintln 可能会被废弃或发生 API 上的不兼容变化。

    Debug 的使用示例:

    struct T[X} {
      s: String
      x: X
    } derive (Debug)
    
    fn init {
      let t = { s : "hello", x: "world" }
      debug(t) // Output: {s: "hello", x: "world"}
    }
    

    2. while 中添加迭代表达式,在循环的每次迭代之后执行

    var i = 0
    while i < len, i = i + 1 {
      do_something_with(i)
    }
    

    上面的例子粗略地等价于:

    var i = 0
    while i < len {
      do_something_with(i)  
      i = i + 1
    }
    

    continue 语句不会跳过迭代表达式。因此迭代表达式尤其适合用于写类似 for的循环。例如,下面的程序会对所有小于 10 的奇数进行一些操作(而非死循环):

    var i = 0
    while i < 10, i = i + 1 {
      if i % 2 == 0 {
        continue
      }
      do_something_with(i)
    }
    

    3. 移除id := expr语法。

    现在只能使用let id = expr声明不可变变量。

    修改前

    修改后

    4. 使用内置类型 Bytes 重新实现速度更快的to_string 方法,

    使用内置类型 Bytes 重新实现速度更快的 IntInt64to_string 方法,替代之前使用字符串拼接的实现

    5. 添加 String::default

    fn init {
      let s = String::default()
      debug(s) // Output: ""
    }
    

    IDE 更新

    1. 本地 VS Code 插件可以自动执行 moon check --watch

    本地 VS Code 插件可以自动执行 moon check --watch ,现在不再需要手动执行。

    2. 添加对方法的提示

    修改前

    修改后

    3. 优化诸多类型报错信息

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2917 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 07:34 · PVG 15:34 · LAX 00:34 · JFK 03:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.