zero?(3scm)

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

πŸ’… zero? β€” the Scheme Programmer's Manual, but make it cute πŸŽ€

okay bestie, welcome to zero?(3scm) β€” yes that's three different procedures in one page, don't panic, it's literally just "is this number zero" energy and we're gonna slay it πŸ’–


✨ NAME ✨

zero?, flzero?, fxzero? β€” the little trio that tests if a number is zero 🎯

πŸ“š LIBRARY πŸ“š

bestie you gotta import these first, and the comments are telling you which report each one belongs to (iykyk):

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

πŸ¦‹ SYNOPSIS πŸ¦‹

the whole vibe, three lines, no notes:

(zero? z)
(flzero? fl)
(fxzero? fx)

🌸 DESCRIPTION 🌸

okay so zero? tests whether the number object z is zero. and the way it works on all number objects β€” up to and including complex numbers?? iconic. it does not discriminate, it checks everybody πŸ’…

then there's the ✨restricted✨ variants, and they're picky on purpose:

  • flzero? is restricted to flonums only
  • fxzero? is restricted to fixnums only

🫢 RETURN VALUES 🫢

it hands you back #t if the number is zero, and #f otherwise. that's it. that's the whole personality. simple, clean, no cap ✨

πŸ”₯ EXAMPLES πŸ”₯

look at these, they ate:

(zero? 0)         => #t
(zero? 0.0)       => #t
(zero? 0.0+0.0i)  => #t

(zero? -1)        => #f
(zero? 1/2)       => #f

(fxzero? 0)       => #t
(flzero? 0.0)     => #t

(fxzero? 1/2)     => &assertion
(flzero? 1/2)     => &assertion

see that last bit? yeah, 1/2 is not a fixnum and not a flonum, so the restricted ones are like "absolutely not" and hit you with &assertion πŸ’€

🌈 APPLICATION USAGE 🌈

it's basically a shorthand for (= x 0) β€” like the low-effort, high-reward version. and ngl, using it with higher-order functions is rare. like it happens, but it's not the main character here πŸ™ˆ

⭐ COMPATIBILITY ⭐

the description is literally the same in all Scheme reports, so no drama there. but compatibility will depend on general factors that affect the number system β€” stuff like implementation support for complex numbers and IEEE 754 floating point. so like, check your implementation bestie 🌸

also: the restricted procedures are only specified in R6RS. so if you're not in R6RS land, those two aren't guaranteed to exist for you 🫢

😭 ERRORS 😭

this procedure can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” the wrong number of arguments was passed, or an argument was outside its domain.
  • R7RS β€” the assertions described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.
bestie "fail catastrophically" is right there in the text, i'm not being dramatic, that's a direct quote πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

  • =(3scm)
  • >(3scm)

🧚 STANDARDS 🧚

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

πŸ’œ AUTHORS πŸ’œ

this page is part of the scheme-manpages project 🫢 it includes materials from the RnRS documents. more info lives at https://github.com/schemedoc/manpages/ β€” go look, it's giving lore ✨

πŸ’€ BUGS πŸ’€

okay real talk: this procedure should normally not be used on inexact numbers, because inaccuracies in computations make its use unreliable. so like, 0.0 looking zero to you and being zero mathematically are two different conversations 😭 be careful out there πŸ“


and that's the page, bestie πŸ’– this was zero?(3scm) from the Scheme Programmer's Manual, dated 2021-01-06 β€” go forth and check your zeros, periodt βœ¨πŸŽ€

πŸ“¦ where this page comes from