vector->list(3scm)

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

πŸ’œ vector->list(3scm) β€” or, how to glow-up between vectors and lists

okay bestie, welcome to the Scheme Programmer's Manual ✨ this little page is all about the two-way pipeline between vectors and lists, and honestly? it's giving "easy A energy" πŸŽ€


🌸 NAME 🌸

vector->list, list->vector β€” the conversion girlies between vectors and lists πŸ’…


πŸ“š LIBRARY πŸ“š

so you gotta import it first, obviously 🫢

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

✨ SYNOPSIS ✨

here's the whole menu, no cap 😌

(vector->list vector)
(vector->list vector start)         ;R7RS
(vector->list vector start end)     ;R7RS
(list->vector list)

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so vector->list hands you back a newly allocated list made of the objects sitting in the elements of vector. fresh out of the oven, brand new, nobody else's πŸ“

and list->vector? it returns a newly created vector initialized to the elements of the list list. also new, also iconic πŸ‘‘

in both of these procedures, order is preserved β€” the vibes stay in the exact same sequence, periodt 🌈

R7RS β€” heads up! vector->list is limited to the elements between start (inclusive) and end (exclusive). these arguments default to 0 and the length of the vector, respectively. so like, you can slice if you want to slice πŸ’–

🧚 IMPLEMENTATION NOTES 🧚

  • Chez Scheme, Loko Scheme β€” sooo the empty vector is a unique object, which means (list->vector '()) does not return a newly allocated vector. it's the same little guy every time 🫢

πŸŽ€ RETURN VALUES πŸŽ€

both procedures return a single value β€” either a vector object or a list. one value, no drama πŸ’€


⭐ EXAMPLES ⭐

watch and learn bestie:

(vector->list '#(dah dah didah))
            => (dah dah didah)

(list->vector '(dididit dah))
            => #(dididit dah)

ate, no crumbs πŸ’…


πŸ’€ COMPATIBILITY πŸ’€

these procedures work the same everywhere, with one tiny exception: the start and end arguments, which are only present in the R7RS variant of vector->list. so if you're on something older, don't come for those extra args, they're not invited πŸ™ˆ


😭 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. basically: you did too much, or you did too little πŸ€·β€β™€οΈ
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, like full-on main character meltdown πŸ’€
in particular, if list->vector is passed a cyclical list then the procedure may not terminate. forever loop era, and not in a cute way 😭 please don't do this to yourself.

πŸ”₯ SEE ALSO πŸ”₯

go read those next, iykyk πŸ“–


πŸ‘‘ STANDARDS πŸ‘‘

R4RS, R5RS, R6RS, R7RS β€” certified by literally everyone 🌈


πŸ•°οΈ HISTORY πŸ•°οΈ

these procedures first appeared in R2RS β€” ancient, historic, grandmother energy 🫢. they were left out of IEEE Scheme. but in spite of this, list->vector appears as an example in the standard. not me being excluded and still showing up in the textbook πŸ˜­πŸ’…


🌸 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/. slay πŸŽ€


and that's the whole page bestie!! πŸ’– dated 2023-01-24, and filed under that vector->list(3scm) name β€” now go convert some data structures, you got this πŸ¦‹βœ¨

πŸ“¦ where this page comes from