On Wed, 8 May 2024 at 17:57, Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum 10353@lyskom.lysator.liu.se wrote:
Yes, although I'm still not sure this follows the principle of least astonishment:
If no matches results in "", and the result is the sum of the matches, wouldn't you expect the result in this case to be ""+4+7, i.e. the string "47"? If an arithmetic sum is expected then you should get 0 from a non-match IMO...
Well, you do get zero for a non-match, so ... I guess so? :)
object buf = Stdio.Buffer("asdf"); buf->match("qwer");
(1) Result: 0
But I don't think that's quite the same as a null sum.
ChrisA
Yes, but:
Pike v9.0 release 2 running Hilfe v3.5 (Incremental Pike Frontend)
object buf = Stdio.Buffer("#"); buf->match("x");
(1) Result: 0
buf = Stdio.Buffer("#");
(2) Result: _static_modules._Stdio()->Buffer(1 bytes, read=[..-1] data=[0..0] free=[1..0] string)
buf->match("#");
(3) Result: ""
buf = Stdio.Buffer("#");
(4) Result: _static_modules._Stdio()->Buffer(1 bytes, read=[..-1] data=[0..0] free=[1..0] string)
buf->match("#%d");
(5) Result: ""
buf = Stdio.Buffer("#44");
(6) Result: _static_modules._Stdio()->Buffer(3 bytes, read=[..-1] data=[0..2] free=[3..0] string)
buf->match("#%d");
(7) Result: 44
This seems mildly inconsistent. If a fixed string in the pattern counts as a "match" with a value of "", then definitely I would expect it to be included in the sum.
pike-devel@lists.lysator.liu.se