Whereas the count of characters in a string is well-defined, and may be zero,
the count of lines in a string has no natural definition, and requires the adoption of some arbitrary convention.
A list of strings can be empty [ ], and contain no strings at all, but even an empty string is still a string, and we could either think of it, in list terms, as [""] with a line count of 1, or as somehow auto-magically equivalent to [ ], with a line count of 0.
More generally, we can decide to either count, or ignore, blank lines of three kinds:
Those before the first non-empty ('printing') lines,
those between printing lines, and
those trailing after the last printing line.
Here is an illustration of using a subroutine to define whichever line counting convention you want to use.
In this case, we are choosing to:
give a line count of 0 to an empty string, and
count all other strings as the length of the list created by splitting on the line-delimiter.
Yep, I replied here before getting to the thread that spawned this one.
This still makes me itch in that you're always making two function calls, yet LINES() is unnecessary if CHARACTERS() is zero. But I think the KM ternary does the same, since
1 = 1 ? 1 : ( 1/0 )
...throws a "failed to evaluate" because of the divide-by-zero error -- the "else" being evaluated even though it isn't used. Compare that with the full "If... Then... Else..." version:
Your itches are our gain, @Nige_S. You always do a great job explaining concepts.
BTW, in the other thread, @Airy suggested the ternary operator method. I like it better; I’ve used that operator many times before, but sometimes I forget.
I think it's the same answer, except I use the reverse logic to yours. Again, force of habit -- I find = 0 ? 0 easier to mentally parse than > 0 ? LINES().