On Thu, 8 Mar 2018, Allin Cottrell wrote:
On Thu, 8 Mar 2018, Sven Schreiber wrote:
> Am 08.03.2018 um 10:23 schrieb oleg_komashko(a)ukr.net:
>> It seems, there is nothing special
>> about strstr:
> ...
>> It looks like 'if' can evaluate non-empty string
>> alone as 1 but can't evaluate logical expressions
>> with string input
>
> OK, thanks for pointing that out. I tend to think --apart from
> backward-compatibility reasons-- that either stuff like 'if "a"'
should be
> banned, or the full logical implications should work as well.
Yep, either we ensure that the result of "if s", for s a string (literal,
variable or expression), is consistently equivalent to "if strlen(s) != 0",
or else we ban this usage as too obscure.
I think my preference would be for the latter, unless there's a significant
compatibility issue.
I'm sorry I'm chiming in only at this stage, but I find the whole issue
quite confusing. In my view, Hansl should not aim at being too clever with
strings. There already are many tools that are much better at that than
Hansl will ever be (Python of course springs to mind). Maybe I'm being a
little too conservative here, but in my eyes a Boolean expression is
something that should unambiguously map to 0 or non-zero. True, "if foo"
(foo being a string) can be interpreted as shorthand for "if strlen(foo)",
but then the problem arises on cases like
if foo || bar
if foo && bar
if foo * bar
if foo + bar
if !foo
("bar" being some arbitrary variable, such as a string but also possibly a
scalar, a matrix etc), etcetera, in which we would have first to guess
whether the intended outcome is Boolean or not and then act accordingly.
Too complicated IMO. If it weren't for backward compatibility, I'd ban "if
<string>" altogether, but at this point I would guess we could allow "if
foo" (where "foo" is a named string, but not something that evaluates to a
string) for historical reasons, but no more than that.
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------