find(3scm)

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

✨ find(3scm) ✨

okay bestie, so this is find from the Scheme Programmer's Manual β€” and honestly it's giving "where's my thing" energy in the best way possible πŸ’…

πŸ’– NAME πŸ’–

find β€” search a list for an element that satisfies a predicate, and when it finds it? slay. returns it. periodt πŸŽ€

πŸ¦‹ LIBRARY πŸ¦‹

(import (rnrs))                     ;R6RS
(import (rnrs lists))               ;R6RS

🌸 SYNOPSIS 🌸

(find proc list)

⭐ DESCRIPTION ⭐

so here's the vibe: find takes proc and applies it to the elements of list in order β€” like, one at a time, no skipping, no chaos, very methodical queen behavior πŸ‘‘

the moment proc returns a true value for an element, find immediately returns that element. no further searching. she's done. bye 🫢

but if proc returns #f for all the elements of the list? then find returns #f. tragic, but that's the rules 😭

one thing though: proc is always called in the same dynamic environment as find itself. no sneaky environment switching, iykyk.

and proc should accept one argument and return a single value. also β€” proc should not mutate list. hands off the list, bestie πŸ™ˆ

🧚 IMPLEMENTATION NOTES 🧚

okay this part is for the people building it, but it's literally so important so listen up:

  • the implementation must check that list is a chain of pairs up to the found element, or that it is indeed a list if no element is found.
  • it should not check that it's a chain of pairs beyond the found element. like, mind your business past that point πŸ’€
  • the implementation must check the restrictions on proc to the extent performed by applying it as described.
  • an implementation may check whether proc is an appropriate argument before applying it. optional flex, basically πŸ’…

🌈 RETURN VALUES 🌈

returns a single value, which is either one of the elements of list, or #f. two possibilities, that's it, no plot twists πŸ“

πŸ”₯ EXAMPLES πŸ”₯

(find even? '(3 1 4 1 5 9))  =>  4
(find even? '(3 1 5 1 5 9))  =>  #f

see how the first one found that 4 and was like "found her πŸ’–" and the second one searched the whole thing and came back with #f? relatable honestly 😭

πŸ’€ 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. so like, if you pass the wrong stuff, she will let you know πŸ™ˆ

πŸ‘‘ SEE ALSO πŸ‘‘

🌸 STANDARDS 🌸

R6RS, SRFI-1 β€” certified, iconic, standards-approved ✨

πŸŽ€ HISTORY πŸŽ€

this procedure is new in R6RS, which got it from SRFI-1. so basically it's an SRFI-1 baddie that got promoted to R6RS main character status πŸ‘‘

πŸ’œ AUTHORS πŸ’œ

this page is part of the scheme-manpages project β€” it includes materials from the RnRS documents, and you can find more info at https://github.com/schemedoc/manpages/ 🫢


and that's the whole page, bestie!! 🌟 dated 2022-03-27, from the scheme-manpages project, find(3scm) β€” go forth and search your lists, you've got this πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from