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