find(3scm)
β¨ 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
listis 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
procto the extent performed by applying it as described. - an implementation may check whether
procis 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
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2022 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms