[m-rev.] for review: replace_nth_element[01]
Julien Fischer
jfischer at opturion.com
Sat Aug 15 12:48:26 AEST 2026
On Sat, 15 Aug 2026 at 10:52, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:
>
> Unless you object, I intend to add the same predicates
> to one_or_more.m as well, in a separate diff.
No objection..
> Move {det_,}replace_nth_elemente[01] to list.m.
>
> library/list.m:
> As above.
>
> NEWS.md:
> Announce the additions to list.m.
>
> compiler/input_specialization.m:
> Delete the moved code.
...
> diff --git a/library/list.m b/library/list.m
> index 8ccec97f5..703802c5e 100644
> --- a/library/list.m
> +++ b/library/list.m
> @@ -429,6 +429,12 @@
> % Fails if N < 1 or if length of List0 < N.
> % (Position numbers start from 1.)
> %
> + % NOTE: please consider using one of replace_nth_element[01] below,
> + % since these
> + %
> + % - clearly specify how they number the list's elements, and
> + % - their argument order is suitable for the use of state variables.
> + %
> :- pred replace_nth(list(T)::in, int::in, T::in, list(T)::out) is semidet.
>
> % det_replace_nth(List0, N, R) = List:
> @@ -438,9 +444,49 @@
> % Throw an exception if either N < 1, or if length of List0 < N.
> % (Position numbers start from 1.)
> %
> + % NOTE: please consider using one of det_replace_nth_element[01] below,
> + % since these
> + %
> + % - clearly specify how they number the list's elements, and
> + % - their argument order is suitable for the use of state variables.
> + %
> :- func det_replace_nth(list(T), int, T) = list(T).
> :- pred det_replace_nth(list(T)::in, int::in, T::in, list(T)::out) is det.
>
> + % replace_nth_element1(N, R, List0, List):
> + % det_replace_nth_element1(N, R, List0, List):
> + %
> + % Succeed if-and-only-if List is List0 with its element #N
> + % replaced with R. (The first element is element #1.)
> + %
> + % If List0 has no element #N, either N < 1, or because
> + % the length of List0 is less than N, then
> + %
> + % - replace_nth_element0 fails, while
> + % - det_replace_nth_element0 fails throws an exception.
Delete the word "fails" in the second dot point.
> +:- pred replace_nth_element1(int::in, T::in, list(T)::in, list(T)::out)
> + is semidet.
> +:- pred det_replace_nth_element1(int::in, T::in, list(T)::in, list(T)::out)
> + is det.
> +
> + % replace_nth_element0(N, R, List0, List):
> + % det_replace_nth_element0(N, R, List0, List):
> + %
> + % Succeed if-and-only-if List is List0 with its element #N
> + % replaced with R. (The first element is element #0.)
> + %
> + % If List0 has no element #N, either N < 0, or because
> + % the length of List0 is less than N-1, then
> + %
> + % - replace_nth_element0 fails, while
> + % - det_replace_nth_element0 fails throws an exception.
And again there.
The rest looks fine.
Julien.
More information about the reviews
mailing list