vector(3scm)

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

πŸ’– 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