On this page:
take-at-most
split-at-most
maybe->list
when/  list
unless/  list
when/  list*
unless/  list*

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
If v is #f, returns '(), otherwise returns (list v).

syntax

(when/list test-expr body ...+)

Equivalent to (if test-expr (list (let () body ...)) '()).

syntax

(unless/list test-expr body ...+)

Equivalent to (if test-expr '() (list (let () 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.