8.18.0.15
2 Data Structures
2.1 Booleans
| (require toolbox/boolean) | package: toolbox-lib |
Returns #f if v is #f, otherwise returns #t.
2.2 Boxes
| (require toolbox/box) | package: toolbox-lib |
procedure
(box-cas-update! box proc) → any/c
box : (and/c box? (not/c immutable?) (not/c impersonator?)) proc : (-> any/c any/c)
Atomically updates the contents of box by applying proc to the old value to produce a new value. The proc procedure will be applied more than once if the box is concurrently modified between reading the old value and writing the new one, so proc should generally be inexpensive. The result of the call to box-cas-update! is the value written to box.
Examples:
> (define b (box "hello")) > (box-cas-update! b string-upcase) "HELLO"
> (unbox b) "HELLO"
procedure
(box-cas-update!* box proc) → any/c
box : (and/c box? (not/c immutable?) (not/c impersonator?)) proc : (-> any/c (values any/c any/c))
Like box-cas-update!, but proc should return two values: the first value is returned, and the second value is written to box.
Examples:
procedure
box : (and/c box? (not/c immutable?) (not/c impersonator?))
procedure
box : (and/c box? (not/c immutable?) (not/c impersonator?))
2.3 Lists
| (require toolbox/list) | package: toolbox-lib |
procedure
(take-at-most lst n) → list?
lst : list? n : exact-nonnegative-integer?
Like take, except if lst has fewer than n elements, take-at-most returns lst instead of raising an exception.
Examples:
> (take-at-most '(1 2 3 4 5) 3) '(1 2 3)
> (take-at-most '(1 2) 3) '(1 2)
procedure
(split-at-most lst n) →
list? list? lst : list? n : exact-nonnegative-integer?
Like split-at, except if lst has fewer than n elements, split-at-most returns (values lst '()) instead of raising an exception.
Examples:
> (split-at-most '(1 2 3 4 5) 3)
'(1 2 3)
'(4 5)
> (split-at-most '(1 2) 3)
'(1 2)
'()
procedure
(maybe->list v) → list?
v : any/c
syntax
(when/list test-expr body ...+)
syntax
(unless/list test-expr body ...+)
syntax
(when/list* test-expr body ...+)
Equivalent to (if test-expr (let () body ...) '()), except that the last body form must evaluate to a list, or an exn:fail:contract exception is raised.
syntax
(unless/list* test-expr body ...+)
Equivalent to (if test-expr '() (let () body ...)), except that the last body form must evaluate to a list, or an exn:fail:contract exception is raised.
2.4 Strings
| (require toolbox/string) | package: toolbox-lib |
syntax
(when/string test-expr body ...+)
Equivalent to (if test-expr (let () body ...) ""), except that the last body form must evaluate to a string, or an exn:fail:contract exception is raised.
syntax
(unless/string test-expr body ...+)
Equivalent to (if test-expr "" (let () body ...)), except that the last body form must evaluate to a string, or an exn:fail:contract exception is raised.