# The MoonBit Update——0729

**URL:** <https://discuss.moonbitlang.com/t/the-moonbit-update-0729/272>\
**Category:** Announcement\
**Tags:** weekly-update\
**Created:** [July 29, 2024, 10:43am UTC](https://discuss.moonbitlang.com/t/the-moonbit-update-0729/272 "2024-07-29T10:43:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kuki](https://discuss.moonbitlang.com/user_avatar/discuss.moonbitlang.com/kuki/32/160_2.png) [@Kuki](https://discuss.moonbitlang.com/u/Kuki)\
**Post date:** [July 29, 2024, 10:43am UTC](https://discuss.moonbitlang.com/t/the-moonbit-update-0729/272/1 "2024-07-29T10:43:17Z")

</div>

# weekly 2024-07-29

## Language Updates

- **Simplified Error Handling Syntax** : The syntax for capturing potential errors in function calls has been updated from `f(x)!!` to `f?(x)`, which returns a `Result` type.

```rust
fn div(x: Int, y: Int) -> Int!String {
  if y == 0 {
    raise "division by zero"
  }
  x / y
}

fn main {
  let a = div?(10, 2)
  println(a) // Ok(5)
}

```

- **JSON Literal Support** : Added support for JSON literals. Numbers, strings, arrays, and dictionary literals are now overloaded to provide a JSON type, which can be used for constructing/matching JSON when the type is expected.

```rust
fn json_process(x: @json.JsonValue) -> Double {
  match x {
    {
      "outer": {
        "middle": {
          "inner": [
            { "x": Number(x) },
            { "y": Number(y) }
          ]
        }
      }
    } => x + y
    _ => 0
  }
}

fn main {
  let x: @json.JsonValue = {
    "outer": { "middle": { "inner": [{ "x": 42 }, { "y": 24 }] } },
    "another_field": "string value",
  }
  json_process(x) |> println
}

```

- **Derive Hash Support** : Added `derive(Hash)` to automatically generate implementations of the `Hash` trait for types.

```rust
enum MyType {
  C1
  C2(Int)
} derive(Eq, Hash)

fn main {
  let m = {}..set(C1, 1)..set(C2(1), 2)..set(C2(2), 3)
  println(m[C1]) // Some(1)
  println(m[C2(1)]) // Some(2)
  println(m[C2(3)]) // None
}

```

- **JavaScript Backend Update** : Removed dependency on `TextDecoder` in generated code.

## Core Updates

- **Function Signature Changes** :

- **Removed `Debug` Trait**

## Build System Updates

- **Single .mbt File Support** : Now supports running a single `.mbt` file (not within a package). Usage: `moon run xx.mbt` (links to the standard library by default, requires a `main` function in `xx.mbt`).

- **Shell Completion** : Moon now supports shell completion.

![](https://discuss.moonbitlang.com/uploads/default/original/1X/5637bbb3cef0109605a18d2450de5767e7783403.gif)  
For the effect shown in the pic, you also need to install the `zsh-autocomplete` and `zsh-autosuggestions` plugins.

## Toolchain Updates

- **moonfmt Fixes** :

- **VS Code Auto-test Support** : Now supports automatic test generation for functions, including black-box tests (ending in `_test.mbt`) and white-box tests (unit tests).

- **Run | Debug Buttons for .mbt** : Added support for single `.mbt` file Run | Debug buttons.
