Am 08.03.2018 um 23:37 schrieb Allin Cottrell:
On Thu, 8 Mar 2018, Sven Schreiber wrote:
> Am 08.03.2018 um 22:07 schrieb Allin Cottrell:
>> Actually I'm quite happy with the strstr() case,
>> It's the 'if "a"' case that makes me a
bit uneasy, but maybe I should
>> just get over it!
It may be interesting to note that Python allows this (and it's True),
whereas Julia doesn't. What does C do? As far as I understand an empty
string literal is something different than what a function like strstr
would return? (NULL pointer?)
If gretl wants to go the Python way, one special ramification might be
string-valued series, what to do about those?
Well, wait a minute. "TRUE" and "FALSE" are pure
synactic sugar for
non-zero and zero, at least in all the languages I have used to any
extent.
Granted.
> Strictly speaking that would mean I could claim to rewrite
'mwrite(m,
> fname, 1)' as 'mwrite(m, fname, "yep put it in the dotdir")',
since a
> non-empty string would be considered 'true'.
True in the limit, I suppose. Though that wouldn't work at present and I
wouldn't wish to make it work.
I understand, but I tend to think the aim should also be consistency.
All the languages above are consistent in what they do (in the C case
after having learned the complicated string representation business as
the base).
> If we had some shorter syntactic sugar for
'strlen(strstr(...))' (or
> almost equivalently 'strstr(...) != ""' we all could be happy I
guess.
> Back in 2016 I suggested 'strfind'.
Maybe. Personally, it just rankles a bit to define a new function that
returns a "collapsed" variant of what an existing function already
returns. But perhaps that's just me.
By "already returns" do you mean the current strstr behavior, or the
entire expression 'ststr(...) != ""' ?
Here are some alternative options if strstr is reverted to the 2016 state:
- Add an optional parameter that explicitly requests a 0-1 return value
instead of a string. Like strstr(a, b, "bool") or something.
- Add a trivial hansl function strfind or instring to the extra package.
thanks,
sven