From 9e4b317101febbe2537bf8434f9eb694cb8bc5f3 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Mon, 26 Aug 2024 16:10:26 +0000 Subject: [PATCH] Add Other --- Other.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Other.md diff --git a/Other.md b/Other.md new file mode 100644 index 0000000..f796e82 --- /dev/null +++ b/Other.md @@ -0,0 +1,4 @@ +### In-line conditionals +Let's suppose you want to increment `x` if `right` is true and decrement it otherwise. In C you might write `x += right ? 1 : -1;`. + +In the Husht examples, the only in-line two-way conditionals that come up would render this as `x += if right then 1 else -1` or (inherited from Rust) `x += if right {1} else {-1}`. Both of these have a lot of syntax for the semantic payoff. Is there a need for a more compact inline choice for a binary? There a [stackOverflow answer](https://stackoverflow.com/a/73965190) on this topic that suggests adding an `IfElse` trait to the boolean type so that you can write `(a < b).ifelse(1, -1)`. So in Husht we could take this just a step further (and in a nod to C) allow `x += right.? 1, -1` and `a < b .? 1, -1`.