swipl-devel icon indicating copy to clipboard operation
swipl-devel copied to clipboard

Make `foldl/4` error outside its domain

Open mb64 opened this issue 3 years ago • 1 comments

Use single-sided unification rules for foldl/4 so that something like foldl(not_a_list, Goal, In, Out) is an exception instead of silently failing. This would be a breaking change.

Some unresolved questions:

  • Is it a good change? I had to debug some code today where this would have told me the problem right away. However, it is a breaking change, so there is a chance that someone relies on this behavior.
  • foldl/N where N > 4? I originally also wanted to change the other foldls, but decided against it, since it would break all the code that uses foldl like a kind of "maplist with state".
  • scanl? I think this change might be significantly more breaking for scanl than for foldl, so I didn't change scanl.
  • Unit tests: I didn't add any, since I'm not familiar with the test setup, but with guidance I would be happy to add one.

mb64 avatar Apr 24 '21 22:04 mb64

Thanks. This breaks test src/Tests/library/test_apply.pl:117 :cry: We could argue this to be a buggy test. We could also argue that non-equal length lists for foldl/5+ should return an error. I'm not sure. Maybe you would like to discuss this on Discourse?

JanWielemaker avatar Apr 26 '21 08:04 JanWielemaker