Home Explore Blog CI



nushell

5th chunk of `blog/2022-03-22-nushell_0_60.md`
aa480fe164ebdcac3c7e25d37d02c0747f26eecd2e7c4e740000000100001074
value is:\n100
```

## New value forms

The 0.60 release also brings with it a number of new value forms.

### Records

You now can write a record, or a list of key/value pairs, as a native data type in Nushell:

```
> {name: "Bob", age: 10}
╭──────┬─────╮
│ name │ Bob │
│ age  │ 10  │
╰──────┴─────╯
```

### Table as a list of records

With the introduction of records, a second way to define a table is a list (or stream) of records:

```
> seq 3 | each { |x| { name: Bob, x: $x } }
  #   name   x
────────────────
  0   Bob    1
  1   Bob    2
  2   Bob    3
```

### Integers are now signed 64-bit integers

We're moving away from the 'bigint' style of integers, so now integers are always signed 64-bit ints.

### Decimals are now signed 64-bit floats

Likewise, we're moving away from 'bigdecimal' to signed 64-bit float values.

### Dates

Earlier versions of Nushell supported dates as a value type, but they lacked a way to write them. You can now write a date literal in one of three ways:

```
# A date
> 2022-02-02

# A date and time, assuming UTC
> 2022-02-23T19:47:47

# A date and time, with a timezone
2022-02-23T19:47:47.888239621-05:00
```

These come from the [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) standard for datetime formats.

### Binary data

Like dates, earlier versions of Nushell also supported binary data but there was no way to write a binary data literal. You're now able to write them using the `0x[...]` form:

```
> 0x[11 ff]
Length: 2 (0x2) bytes | printable whitespace ascii_other non_ascii
00000000:   11 ff                                                •×
```

Spaces and commas are optional in this form, letting you separate write them however is best for readability.

### Custom values

Another form we'll be talking about more as it grows is the "custom value" form. These are value types that you can extend the current set with by implementing a trait in Rust and registering the type.

The dataframe support in 0.60 uses this feature.

## if, meet else

We've improved the syntax of Nushell in a few key places. Previously, in 0.44 you'd write:

```
> if $x < 3 { echo "true!" } { echo "false" }
```

This not only felt inelegant, but was prone to errors as people would want to leave off the second block when they didn't need it or just naturally want to type `else`.

This led to a new concept in Nushell: the keyword shape. Shapes in Nushell are a way for commands to tell the parser what the shape of their parameters are. In turn, the parser will use this knowledge to parse the arguments before they're given to the command (and also to do completions and early errors). With this, `else` is now one of the new keyword shapes, allowing it to take an expression that follows.

Taken together, in 0.60 we can now not only write the above like this:

```
if $x < 3 {
  echo "true!"
} else {
  echo "false"
}
```

We can also string together multiple if/else:

```
if $x < 3 {
  echo "less than three"
} else if $x < 10 {
  echo "less than ten
} else {
  echo "something else!"
}
```

## Shortcircuiting conditions

Boolean operators `&&` and `||` now will properly shortcircuit, only evaluating the right hand side if necessary.

## New built-in values

We're introducing `true` and `false` as builtin values. These represent their boolean values true and false respectively.

## Better binary data support

You can now use `get`, `skip`, and `first` on binary data to reach the bytes you'd like to work with. We're exploring extending this further so that it becomes easier to explore your binary data just like your text data.

## Structured environment

Inside of Nu, the environment can now hold any kind of structured value. For example, opening the `PATH` environment variable now might look like this in macOS:

```
> $env.PATH
╭───┬─────────────────────────────────╮
│ 0 │ /opt/homebrew/opt/openssl@3/bin │
│ 1 │ /opt/homebrew/bin               │
│ 2 │ /opt/homebrew/sbin              │
│ 3 │ /usr/local/bin                  │

Title: Nushell 0.60: Data Types, 'if/else', and Structured Environment Improvements
Summary
This section details new data types in Nushell 0.60, including records, tables as lists of records, binary data literals, and custom values, as well as the implementation of the 'if/else' keyword shape and short-circuiting conditions. It introduces 'true' and 'false' as built-in values, improves binary data support, and allows the environment to hold structured data. Example code illustrates each new feature.