include std:control

: min ( Int Int -- Int )
    2dup i.> [ swap ] when drop
;

: max ( Int Int -- Int )
    2dup i.< [ swap ] when drop
;

: clamp ( Int Int Int -- Int )
    # value min max -- clamped
    # Beautiful! With good helpers, the intent is clear.
    rot swap min max
;

: test-documentation ( -- )
    15 0 10 clamp
    10 test.assert-eq

    5 0 10 clamp
    5 test.assert-eq

    -3 0 10 clamp
    0 test.assert-eq
;
