From b295767a26e25eed3025b85768104abb58040780 Mon Sep 17 00:00:00 2001 From: Vectornaut Date: Fri, 7 Mar 2025 21:43:23 +0000 Subject: [PATCH] Add thoughts about conditionals --- Other.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Other.md b/Other.md index b0c9227..9978707 100644 --- a/Other.md +++ b/Other.md @@ -3,6 +3,9 @@ Let's suppose you want to increment `x` if `right` is true and decrement it othe 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 is 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`. +- *I think that if `1 if right else -1` is good enough for Python, then `if right then 1 else -1` is good enough for Husht. — @Vectornaut* +- *I'm hesitant to give `?` a second meaning in Husht, since the [`?` operator](https://doc.rust-lang.org/rust-by-example/std/result/question_mark.html) appears often in some Rust code I've seen. — @Vectornaut* + ### truthy/falsy values Currently, even if a type `T` has an implementation of the `Into` trait -- i.e., a well-defined way to convert itself into a boolean function -- and `t` is an instance of `T`, you cannot write `if t {do_something()}`; you must write something like `if t.into::() {do_something()}`. [This Rust discussion](https://internals.rust-lang.org/t/use-into-bool-in-if-expressions-if-type-is-not-bool/5919) proposes allowing the former. Husht might well want to adopt such a convention.