Selecting List Components (MIT/GNU Scheme 10.1.6)

Next: Cutting and Pasting Lists, Previous: Construction of Lists, Up: Lists [Contents][Index]

### 7.3 Selecting List Components

procedure: list? object

  Returns `#t` if object is a list, otherwise returns `#f`. By definition, all lists have finite length and are terminated by the empty list. This procedure returns an answer even for circular structures.

  Any object satisfying this predicate will also satisfy exactly one of `pair?` or `null?`.

      (list? '(a b c))                        ⇒ #t
      (list? '())                             ⇒ #t
      (list? '(a . b))                        ⇒ #f
      (let ((x (list 'a)))
        (set-cdr! x x)
        (list? x))                            ⇒ #f

procedure: circular-list? object

  (SRFI 1) Returns `#t` if object is a circular list, otherwise returns `#f`.

      (circular-list? (list 'a 'b 'c))        ⇒ #f
      (circular-list? (cons* 'a 'b 'c))       ⇒ #f
      (circular-list? (circular-list 'a 'b 'c)) ⇒ #t

procedure: dotted-list? object

  (SRFI 1) Returns `#t` if object is an improper list, otherwise returns `#f`.

      (dotted-list? (list 'a 'b 'c))          ⇒ #f
      (dotted-list? (cons* 'a 'b 'c))         ⇒ #t
      (dotted-list? (circular-list 'a 'b 'c)) ⇒ #f

procedure: length list

  Returns the length of list. Signals an error if list isn’t a proper list.

      (length '(a b c))                       ⇒ 3
      (length '(a (b) (c d e)))               ⇒ 3
      (length '())                            ⇒ 0
      (length (circular-list 'a 'b 'c))       error→

procedure: length+ clist

  (SRFI 1) Returns the length of clist, if it is a proper list. Returns `#f` if clist is a circular list. Otherwise signals an error.

      (length+ (list 'a 'b 'c))               ⇒ 3
      (length+ (cons* 'a 'b 'c))              error→
      (length+ (circular-list 'a 'b 'c))      ⇒ #f

procedure: null? object

  Returns `#t` if object is the empty list; otherwise returns `#f`.

      (null? '(a . b))                        ⇒ #f
      (null? '(a b c))                        ⇒ #f
      (null? '())                             ⇒ #t

procedure: list-ref list k

  Returns the kth element of list, using zero-origin indexing. The valid indexes of a list are the exact non-negative integers less than the length of the list. The first element of a list has index `0`, the second has index `1`, and so on.

      (list-ref '(a b c d) 2)                 ⇒ c
      (list-ref '(a b c d)
                (exact (round 1.8)))
           ⇒ c

  `(list-ref list k)` is equivalent to `(car (list-tail list k))`.

procedure: first list
procedure: second list
procedure: third list
procedure: fourth list
procedure: fifth list
procedure: sixth list
procedure: seventh list
procedure: eighth list
procedure: ninth list
procedure: tenth list

  Returns the specified element of list. It is an error if list is not long enough to contain the specified element (for example, if the argument to `seventh` is a list that contains only six elements).

Next: Cutting and Pasting Lists, Previous: Construction of Lists, Up: Lists [Contents][Index]