swipl-devel
swipl-devel copied to clipboard
Make `foldl/4` error outside its domain
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
whereN > 4
? I originally also wanted to change the otherfoldl
s, but decided against it, since it would break all the code that usesfoldl
like a kind of "maplist
with state". -
scanl
? I think this change might be significantly more breaking forscanl
than forfoldl
, so I didn't changescanl
. - 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.
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?