[Gretl-devel] Suggestion for new string-checking built-in function

Allin Cottrell cottrell at wfu.edu
Fri Aug 19 11:36:47 EDT 2016

On Fri, 19 Aug 2016, Sven Schreiber wrote:

> Am 19.08.2016 um 16:27 schrieb Allin Cottrell:
>> On Fri, 19 Aug 2016, Sven Schreiber wrote:
>> How about if we emulated C (sort of) and allowed empty and non-empty
>> strings to evaluate as 0 and 1 where the context requires a Boolean
>> result? Then you could just say
>> if strstr(s1, "USA")
>>   # something
>> else
>>   # something else
>> endif
> Looks good at first sight. But I certainly don't want to slow down the 
> parser.

Now enabled (at essentially zero cost). It can easily be reversed if 
we find anything amiss with this behaviour.

> BTW, the name of the 'strstr()' itself strikes me as unintuitive. I often 
> find myself mistaking 'strsub()' for 'strstr()', because the "sub" reminds me 
> of "substring" whereas in reality it comes from "substitute". So if you allow 
> me to dream on for a second, 'strsubst()' instead of 'strsub()' would be 
> good, and 'strstr()' could become 'strfind()'.
> So then the above would become:
> if strfind(s1, "USA")
>  # something
> ...
> Now wouldn't that be nice, hehe?

Hehe, indeed! I agree that strfind might be more intuitive, but we 
chose strstr because it's the classic C name for this function. As for 
strsub, I think that most languages that have a "find a sub-string" 
function with "sub" in its name put the "sub" first and call it 
"substr" or similar.


More information about the Gretl-devel mailing list