Previous: , Up: iklib lists   [Index]


6.25.3 Miscellaneous functions

The following bindings are exported by the library (vicare).

Function: circular-list? obj

Return #t if obj is a circular list; otherwise return #f.

Function: list-of-single-item? obj

Return #t if obj is a list with a single item, otherwise return #f. In other words: return #t if obj is a pair whose cdr is null.

Function: make-list len
Function: make-list len fill

Build and return a new list of len elements. fill is used to initialise the the list pairs; when not given: it defaults to the return value of (void).

Function: last-pair pair

Return the last pair in the non–empty, finite list pair.

(last-pair '(a b c))    ⇒ (c)
Function: for-each-in-order proc list0 list ...

Like for-each from (rnrs base (6)) but guarantees that proc is applied starting from the head of the lists.

Function: andmap proc ell
Function: andmap proc ell1 ell2

Iterate in order the list arguments, applying proc to the items in the lists, left to right. If proc returns #f: andmap stops the iteration and returns false. If proc returns a non–false value for all the items from the list arguments: andmap returns the result of the last proc application. If all the list arguments are null: the return value is #t.

When applied to two arguments: proc must be a function accepting a single argument and returning a single value; ell must be proper list (possibly empty).

When applied to three arguments: proc must be a function accepting a two arguments and returning a single value; ell1 and ell2 must be proper lists of equal length (possibly empty).

(andmap (lambda (x) x) '())
⇒ #t

(andmap (lambda (x) x) '(1 2 3))
⇒ 3

(andmap (lambda (x) x) '(1 #f 3))
⇒ #f

(andmap (lambda (x y) (and x y))
        '() '())
⇒ #t

(andmap (lambda (x y) (and x y))
        '(1 2) '(3 4))
⇒ 4

(andmap (lambda (x y) (and x y))
        '(1 2) '(3 #f))
⇒ #f
Function: ormap proc ell

Iterate in order the list arguments, applying proc to the items in the list argument ell. If proc returns non–false: ormap stops the iteration and returns the non–false value. If proc returns #f for all the items in ell: ormap returns #f. If ell is null: the return value is #f.

proc must be a function accepting a single argument and returning a single value; ell must be proper list (possibly empty).

(ormap (lambda (x) x) '())
⇒ #f

(ormap (lambda (x) x) '(#f #f #f))
⇒ #f

(ormap (lambda (x) x) '(#f 123 #f))
⇒ 123

(ormap (lambda (x) (or x 123)) '())
⇒ #f

(ormap (lambda (x) (or x 123)) '(1 2 3))
⇒ 1

(ormap (lambda (x) (or x 123)) '(#f #f 1))
⇒ 123

Previous: , Up: iklib lists   [Index]