min(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

πŸ’… min(3scm) β€” the Scheme Programmer's Manual, but make it group chat πŸ’…

Okay so bestie, welcome to min(3scm) from the Scheme Programmer's Manual β€” yes the whole manual, and yes we're doing the max/min page together because they're literally inseparable, iykyk. 🫢


✨ NAME ✨

max, min β€” find the maximum or minimum argument. That's it. That's the whole job. Iconic behaviour, no notes. πŸ‘‘


πŸ“š LIBRARY πŸ“š

Here's where you import these babies from, depending on which Scheme flavour you're living in:

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS
(import (rnrs arithmetic fixnums))  ;R6RS
(import (rnrs arithmetic flonums))  ;R6RS

Like, pick your era, bestie. All valid. πŸ’–


🌸 SYNOPSIS 🌸

(max x1 x2 ...)
(fxmax fx1 fx2 ...)                 ;R6RS
(flmax fl1 fl2 ...)                 ;R6RS
(min x1 x2 ...)
(fxmin fx1 fx2 ...)                 ;R6RS
(flmin fl1 fl2 ...)                 ;R6RS

Six procedures. Two jobs. Maximum chaos (affectionate). ✨


πŸ’« DESCRIPTION πŸ’«

These procedures return the maximum or minimum of their arguments. Lowkey the simplest thing ever, but there's lore, so let's get into it. 🧚

πŸŽ€ Generic versions πŸŽ€

For any real number object x that is not a NaN:

(max +inf.0 x)  =>  +inf.0
(min -inf.0 x)  =>  -inf.0

Also! If any argument is inexact, then the result is also inexact β€” unless the procedure can prove that the inaccuracy is not large enough to affect the result, which (ngl) is only possible in unusual implementations. So don't count on it, bestie. 😭

πŸ¦‹ Fixnum versions πŸ¦‹

The arguments and the return value are fixnums. There are no special cases. Clean, simple, no drama β€” the way I wish my life was. πŸ’…

🌈 Flonum versions 🌈

The arguments are the return value are flonums. (Yes, that's exactly how the original says it, we're keeping it.) And heads up: if one or more of the arguments is a NaN then a NaN is returned. 🫢


πŸ“ RETURN VALUES πŸ“

Returns a single number object. One number. That's it. Slay. ✨


πŸ”₯ EXAMPLES πŸ”₯

(max 3 4)        =>  4
(max 3.9 4)      =>  4.0

(max 42 +nan.0)  => +nan.0

Look at (max 3.9 4) giving 4.0 and not 4 β€” that's the inexactness thing from before doing its little dance. πŸ’ƒ


⭐ COMPATIBILITY ⭐

The generic versions of these procedures work the same in all Scheme revisions. Fr fr, no cap, portable across every report. πŸŽ€


πŸ’€ ERRORS πŸ’€

This procedure can raise exceptions with the following condition types β€” pay attention bestie, this is the part where things get real:

  • &assertion (R6RS) β€” the wrong number of arguments was passed, or an argument was outside its domain. πŸ™ˆ
  • &implementation-restriction (R6RS) β€” may be raised if min or max is used to compare number objects of mixed exactness, and the numerical value of the result cannot be represented as an inexact number object without loss of accuracy. So like, it might yell at you, might not. Vibe check pending. 😭
  • R7RS β€” the reasons for &assertion described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically. Fail catastrophically. Not me hyping up a footnote. πŸ’€ It is not specified how implementations should handle the &implementation-restriction case described above, but the program may be stopped. So yeah. It might just. Stop. πŸ™ƒ

πŸ‘€ SEE ALSO πŸ‘€

<(3scm) β€” go read that one too, bestie, it's the sibling page. 🫢


πŸ‘‘ STANDARDS πŸ‘‘

R4RS, IEEE Scheme, R5RS, R6RS, R7RS. The whole squad. 🌈


πŸ•°οΈ HISTORY πŸ•°οΈ

The generic versions of these procedures are in all Scheme reports since R2RS. Early Scheme built on top of MacLISP also provided them β€” so they're genuinely vintage, like find-your-grandma's-records vintage. πŸŽ€

The fixnum and flonum versions are new in R6RS. Fresh drop. ✨


πŸ’œ AUTHORS πŸ’œ

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/. Shoutout to the maintainers, absolute icons. 🫢


πŸ› BUGS πŸ›

IEEE Scheme accidentally omitted min. That's it. That's the bug. A whole procedure just… not invited to the function list. Not me feeling genuinely bad for min like it's a group-chat exclusion. πŸ˜­πŸ’”


Okay so that's the whole page, and yes, every single option, value, condition type, example and reference made it in β€” the vibe changed, the facts did not. πŸ’…

Signing off from min(3scm), dated 2022-03-26, part of the scheme-manpages project (the one that lives at https://github.com/schemedoc/manpages/) β€” mwah, go find the max of your day, bestie. πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from