This page lists the procedures of R7RS-small (chapter 6) for the data types that hold other data, with the additions of R6RS and the usual SRFIs. The procedures are the ones the viewer colours as functions. Optional start and end arguments, where shown, are R7RS additions to several string and vector procedures.
Pairs and lists
A pair holds two objects, its car and cdr. A list is the empty list or a pair whose cdr is a list; a pair whose chain of cdrs ends in something else is an improper or dotted list, and a chain that returns to itself is circular. (a b c) is the same object as (a . (b . (c . ()))).
| Group | Procedures |
|---|---|
| Construct and take apart | cons car cdr set-car! set-cdr! list make-list list-copy |
| Predicates | pair? null? list? (true only for lists, which by definition are finite and end in the empty list, so false for a circular list) |
| Compositions of car and cdr | the four of two letters (caar cadr cdar cddr) in the base library, and the 24 of three and four letters (caaar to cddddr) in (scheme cxr) |
| Length and access | length (error if not a proper list) list-ref list-tail list-set! (R7RS) |
| Combine | append (the last argument is not copied, and may be improper) reverse |
| Search | memq memv member and assq assv assoc; the last two of each take an optional comparison procedure in R7RS |
| Map and iterate | map for-each apply |
An association list is a list of pairs used as a table: ((a . 1) (b . 2)); assq, assv and assoc find a pair by key. A property list alternates keys and values. Lists made by quote are constants and must not be mutated.
R6RS lists library
(rnrs lists) adds find for-all exists filter partition fold-left fold-right remp remove remq remv memp assp cons*, and (rnrs sorting) adds list-sort, vector-sort and vector-sort!. for-all and exists are every and any of SRFI 1.
SRFI 1
SRFI 1 is the list library most implementations offer, and its procedures are the ones the viewer knows by name: constructors xcons list-tabulate circular-list iota; selectors first through tenth car+cdr take drop take-right drop-right split-at last last-pair; predicates proper-list? circular-list? dotted-list? not-pair? null-list? list=; length+ concatenate reverse! append-reverse append! zip unzip1 to unzip5 count; fold unfold pair-fold reduce fold-right unfold-right pair-fold-right reduce-right append-map map-in-order pair-for-each filter-map; partition filter remove find find-tail any every list-index take-while drop-while span break delete delete-duplicates and their ! forms; association lists alist-cons alist-copy alist-delete; and the set operations lset<= lset= lset-adjoin lset-union lset-intersection lset-difference lset-xor lset-diff+intersection. R7RS made map and for-each stop at the shortest list and gave member and assoc the third argument, both after SRFI 1; The SRFI index tags SRFI 1 as part of R7RS-large (the Red edition).
Symbols
A symbol is a name; two symbols are eqv? when they have the same characters. (symbol? obj), (symbol=? s1 s2 ...) (R6RS, R7RS), (symbol->string s) (returns an immutable string) and (string->symbol string). string->symbol can make a symbol that has no written form without bars. Case: symbols are case-sensitive in R6RS and R7RS, and were folded to lower case in R5RS and earlier. Implementations add gensym, generate-uninterned-symbol, symbol-append and the uninterned symbols of SRFI 258.
Characters
| Group | Procedures |
|---|---|
| Predicate and conversion | char? char->integer integer->char |
| Comparison, by Unicode scalar value | char=? char<? char>? char<=? char>=?, with any number of arguments in R7RS |
| Comparison ignoring case (char library) | char-ci=? char-ci<? char-ci>? char-ci<=? char-ci>=? |
| Classes (char library) | char-alphabetic? char-numeric? char-whitespace? char-upper-case? char-lower-case? |
| Case (char library) | char-upcase char-downcase char-foldcase |
| Digit value (char library) | digit-value: the value 0 to 9 of a character for which char-numeric? is true (including digits of other scripts), or #f |
| R6RS adds | char-titlecase char-title-case? char-general-category |
Strings
A string is a fixed-length sequence of characters, indexed from 0. string-length and string-ref are the basics; changing a string is string-set!, string-fill! and string-copy!, and literals are immutable.
| Group | Procedures |
|---|---|
| Make | string? make-string string (from characters) string-copy substring string-append list->string vector->string utf8->string |
| Access | string-length string-ref string->list string->vector string->utf8 (optional start and end) |
| Mutate | string-set! string-fill! string-copy! |
| Compare | string=? string<? string>? string<=? string>=?, and in the char library string-ci=? string-ci<? string-ci>? string-ci<=? string-ci>=?. R7RS no longer requires string order to agree with character order |
| Case (char library) | string-upcase string-downcase string-foldcase; R6RS adds string-titlecase and the four string-normalize-nf* procedures |
| Map | string-map string-for-each (R7RS) |
| Number and symbol | number->string string->number symbol->string string->symbol |
The reports have no search, split, join, trim, pad or index procedures. They come from SRFI 13 (string-index string-contains string-trim string-pad string-join string-prefix? string-suffix? string-take string-drop string-reverse string-concatenate string-fold string-count and others), from SRFI 130, 140 and 152, from SRFI 135 (immutable texts) and from each implementation, with different argument orders; check the implementation before relying on one. The R6RS (rnrs unicode) and (rnrs mutable-strings) libraries hold the Unicode procedures and string-set! and string-fill!.
(string-append "foo" "bar") ; "foobar"
(string-copy "hello" 1 3) ; "el"
(string-map char-upcase "abc") ; "ABC"
(list->string (reverse (string->list "abc"))) ; "cba"
(string-for-each
(lambda (c) (write-char (char-upcase c)))
"hi") ; prints HI
Vectors
A vector is a fixed-length sequence indexed from 0, with constant-time access. R7RS and R6RS have a literal #(1 2 3) that evaluates to itself.
| Group | Procedures |
|---|---|
| Make | vector? make-vector (optional fill) vector vector-copy vector-append list->vector string->vector |
| Access and change | vector-length vector-ref vector-set! vector-fill! vector-copy! vector->list vector->string |
| Map | vector-map vector-for-each |
vector-copy, vector-append, vector-copy!, vector-fill! with a range and vector->string are R7RS additions; R5RS had only make-vector, vector, vector-length, vector-ref, vector-set!, vector->list, list->vector, vector-fill! and vector?. SRFI 43 and SRFI 133 add vector-fold vector-count vector-index vector-binary-search vector-swap! vector-reverse! vector-unfold subvector vector-head vector-tail vector-grow and more; SRFI 95 and 132 add sort, sort! and merge.
Bytevectors
A bytevector is a vector of exact integers from 0 to 255, written #u8(...) in R7RS and #vu8(...) in R6RS.
| Group | Procedures |
|---|---|
| R7RS-small | bytevector? make-bytevector bytevector bytevector-length bytevector-u8-ref bytevector-u8-set! bytevector-copy bytevector-copy! bytevector-append utf8->string string->utf8 |
R6RS adds ((rnrs bytevectors)) | endianness native-endianness bytevector=? bytevector-fill!, access to signed and unsigned 8, 16, 32 and 64-bit integers and to arbitrary-width ones (bytevector-u16-ref, bytevector-s32-native-set!, bytevector-uint-ref, bytevector-sint-set! and the others of the pattern), IEEE single and double floats (bytevector-ieee-single-ref, bytevector-ieee-double-native-set! and the others), bytevector->u8-list u8-list->bytevector bytevector->uint-list uint-list->bytevector bytevector->sint-list sint-list->bytevector, and string->utf16 string->utf32 utf16->string utf32->string |
R7RS-small provides only the unsigned-byte procedures, because the wider ones were left to later work (SRFI 160 homogeneous numeric vectors, SRFI 281 bytevector utilities).
Not described
Known, not yet covered
- Reference: the argument order and result of each SRFI 1, 13, 43 and 133 procedure are not described; the SRFI documents were not read, and the procedure names above come from memory of those documents.
- Reference: the hash tables of R6RS (
(rnrs hashtables)), SRFI 69 and SRFI 125 are not described here; the names are in Standard libraries and SRFI. - Reference: R6RS’s requirement that
vector-mapandstring-for-eachcall the procedure in a particular order, and the unspecified order ofmap, are in the reports and not described.
See also
- Data types – the storage model and mutability
- I/O ports – reading and writing characters and bytes
- SRFI – the list, string and vector libraries