shelly-shell 0.5.4

A Rust based Unix style shell with a typed and structured language syntax.
# Conditional imports and declarations

A `when` condition decides whether a dependency or declaration participates in a
module. It is evaluated against the environment available **before that module
loads**. Code defined inside the module cannot supply the condition.

A false import condition skips lookup entirely, which makes platform-specific
dependencies practical even when their files are absent.

<!-- example: WHEN-IMPORT -->
```shy
import deliberately_absent when false
echo "portable branch loaded"
```

```text
portable branch loaded
```


Bracketed exclusions can guard a function or a declaration block:

<!-- example: WHEN-BLOCK -->
```shy
[when true]
{
    let $label = "included"
    fn selected(): String { $label }
}
[when false]
fn selected_elsewhere(): String { "excluded" }
echo (selected)
```

```text
included
```


An included block contributes declarations to the surrounding scope; it does not
create a new runtime scope. Excluded declarations are not evaluated.

A condition that cannot be evaluated is an error, rather than a false condition.
For example, misspelling `$os` should not silently remove an implementation.
Use conditions such as `$os == "linux"` or `$os == "macos"` for platform selection.

This is declaration selection, not textual substitution. The source still needs
to be syntactically valid. Ordinary `if` handles runtime decisions after the
module has loaded.

---

Related: [Modules](Modules) · [Control flow](Control-Flow) · [Environment](Environment)