From 8a02b2c9c191015d8f1e5e27404e2682d76b6a91 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Wed, 20 Feb 2019 19:53:39 -0600 Subject: [PATCH] Document optional `else` clause of `if` --- docs/content/3.manual/manual.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml index e6d4e57..011218f 100644 --- a/docs/content/3.manual/manual.yml +++ b/docs/content/3.manual/manual.yml @@ -2044,13 +2044,16 @@ sections: produces a value other than false or null, but act the same as `C` otherwise. + `if A then B end` is the same as `if A then B else . end`. + That is, the `else` branch is optional, and if absent is the + same as `.`. + Checking for false or null is a simpler notion of "truthiness" than is found in Javascript or Python, but it means that you'll sometimes have to be more explicit about - the condition you want: you can't test whether, e.g. a + the condition you want. You can't test whether, e.g. a string is empty using `if .name then A else B end`, you'll - need something more like `if (.name | length) > 0 then A else - B end` instead. + need something more like `if .name then A else B end` instead. If the condition `A` produces multiple results, then `B` is evaluated once for each result that is not false or null, and `C` is evaluated -- 2.40.0