list-tail(3scm)

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

✨ list-tail(3scm) β€” bestie's guide to skipping list elements ✨

okay so real talk, this one is from the Scheme Programmer's Manual (the list-tail page, duh πŸ’…) and it's honestly such a vibe. lowkey one of the most useful little list procedures ever. let's get into it 🫢

🌸 LIBRARY 🌸

before you can even use this icon, you gotta import her. she lives in a few different places depending on what flavor of Scheme you're on:

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

pick your girl, import her, slay ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

(list-tail list k)

that's it. that's the whole call. two args, no drama πŸ’–


πŸ’œ DESCRIPTION πŸ’œ

so what does she actually do? list-tail returns the subchain of pairs of list that you get by omitting the first k elements. literally just "skip ahead k times and hand me whatever's left." main character energy honestly πŸ‘‘


πŸŽ€ IMPLEMENTATION NOTES πŸŽ€

okay bestie, listen up, this part matters:

  • Implementation responsibilities: the implementation must check that list is a chain of pairs whose length is at least k. no cap, that check is required.
  • it should not check that it's a chain of pairs beyond this length. like, don't do extra work, she's not gonna go there 🧚
so: required to verify the length reaches k, not required to keep going past it. that's the vibe check the implementation has to pass.

πŸ’– RETURN VALUES πŸ’–

returns a single value β€” a subchain of pairs from list. one girl, one return value, periodt πŸ’…


πŸ”₯ EXAMPLES πŸ”₯

the classic. the iconic. the one everybody screenshots:

(list-tail '(a b c d) 2)  =>  (c d)

see how she skipped a and b and gave us (c d)? ate. no notes πŸ’―


🌈 COMPATIBILITY 🌈

apart from error conditions, this procedure works the same everywhere. so like, portable queen behavior. you love to see it 🫢


πŸ’€ ERRORS πŸ’€

she can raise exceptions with these condition types, so know what you're getting into:

  • &assertion (R6RS) β€” the wrong number of arguments was passed, or an argument was outside its domain. in particular, list should be a list of size at least k. (so like… don't pass her a list that's too short, bestie, she will not be happy 😭)
  • 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.
fail catastrophically is right there in the original and I am not softening that for you πŸ’€ it's giving "choose your own disaster" and honestly? iconic of the standard.

πŸ“ SEE ALSO πŸ“

go read those next, iykyk ✨


πŸ‘‘ STANDARDS πŸ‘‘

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

miss girl has been standardized everywhere. pedigree? unmatched 🌟


🌸 HISTORY 🌸

this procedure first appeared in R2RS. ancient. legendary. she's been doing this since before you were born πŸ’…


🧚 AUTHORS 🧚

this page is part of the scheme-manpages project. it includes materials from the RnRS documents. more info can be found at https://github.com/schemedoc/manpages/ β€” go check the repo, it's giving community love 🫢


okay that's the whole page, bestie!! you're now officially educated on list-tail. go skip some elements. slay πŸ’–βœ¨πŸŽ€

β€” signed off from the 3scm edition, dated 2023-08-13, brought to you by the Scheme Programmer's Manual πŸŒˆπŸ¦‹πŸ’œ

πŸ“¦ where this page comes from