string=?(3scm)

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

πŸ’… string=?(3scm) β€” the Scheme Programmer's Manual, but make it cute

okay so bestie, welcome to the 3scm corner of the Scheme Programmer's Manual, where we're talking about string=?, string<?, string>?, string<=?, and string>=? β€” yes, all five, they're a package deal πŸ‘‘


✨ NAME ✨

string=?, string<?, string>?, string<=?, string>=? β€” the string comparison girlies πŸŽ€


πŸ“š LIBRARY πŸ“š

like, pick your import era, they all work:

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS

🌸 SYNOPSIS 🌸

(string=? string1 string2 string3 ...)
(string<? string1 string2 string3 ...)
(string>? string1 string2 string3 ...)
(string<=? string1 string2 string3 ...)
(string>=? string1 string2 string3 ...)

note that ... at the end babe β€” these take as many strings as you want, not just two πŸ’…


πŸ’– DESCRIPTION πŸ’–

the equality one (string=?)

string=? hits you with #t if all the strings are the same length AND contain exactly the same characters in the same positions. otherwise? #f. no notes, it's giving exact match only πŸ™ˆ

the ordering ones

the ordering procedures return #t if their arguments are, respectively:

  • monotonically increasing πŸ“ˆ
  • monotonically decreasing πŸ“‰
  • monotonically nondecreasing
  • monotonically nonincreasing

and here's the tea β€” the behavior of the ordering procedures is different in R6RS and R7RS. main character conflict fr fr:

R6RS

these procedures are the lexicographic extensions to strings of the corresponding orderings on characters. for example, string<? is the lexicographic ordering on strings induced by the ordering char<? on characters. and if two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string. so "z" < "zz", iconic behavior honestly ✨

R7RS

the ordering procedures compare strings in an implementation-defined way 😭 they may work the same as in R6RS, or they could use some other ordering. it's giving "your mileage may vary" energy.

these predicates are required to be transitive though, that part is non-negotiable. in all cases, a pair of strings must satisfy exactly one of string<?, string=?, and string>?, and must satisfy string<=? if and only if they do not satisfy string>? and string>=? if and only if they do not satisfy string<?. like the friend group is consistent, no drama 🌈


πŸ‘‘ RETURN VALUES πŸ‘‘

these procedures return a single value; a boolean. that's it. #t or #f, pick one bestie πŸ’œ


πŸ¦‹ EXAMPLES πŸ¦‹

look at her go:

(string=? "Straße" "Strasse")  =>  #f
(string<? "z" "ß")             =>  #t
(string<? "z" "zz")            =>  #t
(string<? "z" "Z")             =>  #f

yes the ß is doing heavy lifting in these examples, we love a multilingual icon 🌸


⭐ COMPATIBILITY ⭐

the basic idea of these procedures is the same in all RnRS revisions. however, there are some differences. buckle up:

  • R5RS and earlier reports only provided two-argument variants. two and only two, no plus-one πŸ₯²
  • R6RS implementations all work the same. consistency slay πŸ’…
  • R7RS implementations may lack support for some characters. the order is also implementation-defined, with lexicographical ordering only being one option. so don't come for me if your impl sorts weird, that's allowed 😭

πŸ’€ 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. yes, catastrophically. that's the actual word. do not test it πŸ™ˆ

πŸ”₯ SEE ALSO πŸ”₯

  • char<?(3scm)
  • string-ci=?(3scm)
  • equal?(3scm)

go read those next, i'm obsessed with cross-referencing 🫢


🧚 STANDARDS 🧚

R4RS, IEEE Scheme, R5RS, R6RS, R7RS β€” she's certified in five standards, ate and left no crumbs πŸ‘‘


πŸ“ HISTORY πŸ“

these procedures first appeared in R2RS. fun lore: MacLisp had the samepnamep and alphalessp procedures that took two arguments and worked on both symbols and strings. vintage behavior, we respect the ancestors πŸ’œ


🌈 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/.


okay that's the whole page bestie, go compare some strings and slay πŸ’…βœ¨

string=?(3scm) Β· Scheme Programmer's Manual Β· dated 2022-04-09 β€” mwah, catch you on the next manpage πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from