by reycharles · 9y ago · 0 comments
result = if boolean_flag
then do_this()
else do_that();
then I'm sure no one would find it as bad as they do now. The way you formatted the ternary with line-breaks helps a lot, too, I think! let result = if boolean_flag {
do_this()
} else {
do_that()
};
Rust actually doesn’t have a ternary operator. z <- if (x > y) 5 else 7
And of course this is trivial in Lisp: (setf z (> x y) 5 7)What you meant is:
(setf z (if (> x y) 5 7))
A nicer thing that I like about Lisp's "everything is an expression" is something that is considered as code smell by some: (setf foo (or var (compute-default-value) +some-default-constant+))
This works in Common Lisp, where the only value considered logically false is NIL, because or will short-circuit (as expected), returning not T, but the value of the first logically true result.So e.g.
(let ((a nil) (b 2) (c :foo))
(or a b c))
returns 2. result = if boolean_flag do_this(); else do_that(); end
Though it does have the ternary ?: operator too. result = do_this() if boolean_flag else do_that()