zero?(3scm)
π 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 onlyfxzero?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
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2021 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms