command `if`: Introduce `LISTLENGTH` and `STRLENGTH` predicates
Also, there are a bunch of improvements and optimizations applied before (and a bit after) the feature implemented. It might be hard to review as a whole, but I tried minimal changes on every refactoring (and commit) -- reviewing individual commits might be easier.
See also #22469.