vector(3scm)
π vector(3scm) β the Scheme Programmer's Manual, bestie edition π
okay so quick vibe check: this is the vector page from the Scheme Programmer's Manual, and it's honestly iconic. it's the little constructor that could. let's get into it π«Ά
β¨ NAME β¨
vector β make a shiny new vector out of the arguments you hand it, no cap
π LIBRARY π
import this from whichever Scheme flavor you're sipping on, all of these work:
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
like, pick your fighter π
π SYNOPSIS π
(vector obj ...)
πΈ DESCRIPTION πΈ
it returns a newly allocated vector, and its elements are literally just the arguments you passed in. that's the whole thing. that's the assignment. slay β¨
π§ IMPLEMENTATION NOTES π§
okay this is the messy part, listen up π
some implementations allocate a new object every single time this procedure returns an empty vector. one such implementation is Chicken 5.2.0. other implementations, like Chez Scheme 9.5, are out here returning the same empty vector object every time.
so likeβ¦ it depends on your implementation's mood, basically π
π¦ RETURN VALUES π¦
- returns a newly allocated vector π
- if you call this procedure with no arguments, it returns the empty vector β which may or may not be newly allocated (see the messy section above, iykyk)
π₯ EXAMPLES π₯
(vector 'a 'b 'c) => #(a b c)
; Newly allocated vectors are mutable:
(define x (vector 'a 'b 'c))
(vector-set! x 0 'A)
x => #(A b c)
; Vector literals are immutable (but implementations may or
; may not catch this error):
(define x '#(a b c))
(vector-set! x 0 'A) => error
; Implementations are free to choose if they use one or
; multiple objects to represent the empty vector.
(eq? (vector) (vector)) => #t or #f
the mutable vs immutable thing is so important bestie, don't sleep on it. vector literals are immutable and your implementation may or may not catch the error β so like, it might just vibe and let you do it, or it might yell at you π
π APPLICATION USAGE π
applications should avoid calling this procedure with an unknown number of arguments. the arguments get passed on the stack, and the stack may not be able to handle a very large number of arguments. like, it's giving overflow energy π
a better way to convert a list to a vector is with the list->vector(3scm) procedure. use that one, trust π«Ά
π COMPATIBILITY π
the vector procedure enjoys wide support across Lisp dialects. she's universally beloved, main character energy fr fr π
π ERRORS π
this procedure does not raise exceptions, but it may cause an out-of-memory condition which generally cannot be handled. so likeβ¦ not an error error, more of a whole-situation-goes-wrong situation π
lowkey scary but okay, now you know
β SEE ALSO β
π STANDARDS π
R4RS, IEEE Scheme, R5RS, R6RS, R7RS
she's certified. she's legit. periodt π
πΈ 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/. shoutout to the legends who wrote this down for us π«Ά
and that's the page!! mwah π
this adorable lil rewrite of vector(3scm) from the Scheme Programmer's Manual is dated 2020-08-14 β go forth and build vectors, bestie πβ¨
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2020 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms