vector->list(3scm)
π 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->listis limited to the elements between start (inclusive) and end (exclusive). these arguments default to0and 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 π₯
vector(3scm)list(3scm)list->string(3scm)vector->string(3scm)
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
- 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