# MoonBit每周工作动态——1218

**URL:** <https://taolun.moonbitlang.com/t/topic/455>\
**Category:** MoonBit 月报\
**Tags:** moonbit-ide, moonbit-lang\
**Created:** [2023 年12 月 18 日 09:16 UTC](https://taolun.moonbitlang.com/t/topic/455 "2023-12-18T09:16:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![jodie](https://taolun.moonbitlang.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jodie](https://taolun.moonbitlang.com/u/jodie)\
发布日期： [2023 年12 月 18 日 09:16 UTC](https://taolun.moonbitlang.com/t/topic/455/1 "2023-12-18T09:16:31Z")

</div>

## MoonBit更新

### 1. 添加 `Debug` 接口

```auto
interface Debug {
  debug_write(Self, Buffer)
}

```

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

`Debug` 的使用示例：

```auto
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` 中添加迭代表达式，在循环的每次迭代之后执行

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

```

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

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

```

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

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

```

### 3. 移除`id := expr`语法。

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

修改前

 ![](https://taolun.moonbitlang.com/uploads/default/original/1X/c13dd2866322642d000d3416da6784d63d54f54f.png)

修改后

 ![](https://taolun.moonbitlang.com/uploads/default/original/1X/0235ce6008726047d6b8a0d8d860961c9b9f0502.png)

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

使用内置类型 `Bytes` 重新实现速度更快的 `Int` 和 `Int64`的`to_string` 方法，替代之前使用字符串拼接的实现

### 5. 添加 `String::default`

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

```

## IDE更新

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

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

### 2. 添加对方法的提示

修改前

 ![](https://taolun.moonbitlang.com/uploads/default/original/1X/56c041805999ae922b7936411a0fa4a89da5d366.png)

修改后

 ![](https://taolun.moonbitlang.com/uploads/default/original/1X/0530f9810927e7d1b76f3d5575fdf7de8fa978cc.png)

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