[m-rev.] for review: add int32.clamp/3

Julien Fischer jfischer at opturion.com
Wed Mar 4 13:12:00 AEDT 2026


On Wed, 4 Mar 2026 at 13:06, Peter Wang <novalazy at gmail.com> wrote:
>
> On Wed, 04 Mar 2026 12:13:37 +1100 Julien Fischer <jfischer at opturion.com> wrote:
> > For review by anyone.
> >
> >  I intend to add the clamp/3 to all of the integer modules. I will add
> > it for the others
> > after this change is reviewed.
> >
> > -----------------------
> >
> > Add int32.clamp/3.
> >
> > library/int32.m:
> >     Add the new function.
>
> > diff --git a/library/int32.m b/library/int32.m
> > index bc8f526fa..6f4d6b73c 100644
> > --- a/library/int32.m
> > +++ b/library/int32.m
> > @@ -189,6 +189,14 @@
> >      %
> >  :- func min(int32, int32) = int32.
> >
> > +    % clamp(Min, Max, N):
> > +    %
> > +    % Clamp N to the range [Min, Max] (inclusive).
> > +    % Returns Min if N < Min, Max if N > Max, and N otherwise.
> > +    % Throws an exception if Max < Min.
> > +    %
> > +:- func clamp(int32, int32, int32) = int32.
> > +
>
> I suppose this is the obvious order for partial application.
>
> Labelled arguments?
>
>     :- type range ---> range.
>     :- type value ---> value.
>     :- func clamp(range, int32, int32, value, int32) = int32.
>
> ;)
>
> The diff looks fine.
>
> Peter
> _______________________________________________
> reviews mailing list
> reviews at lists.mercurylang.org
> https://lists.mercurylang.org/listinfo/reviews


More information about the reviews mailing list