Next: , Previous: Common List Functions, Up: Common List Functions


7.2.1.1 List construction
— Function: make-list k
— Function: make-list k init

make-list creates and returns a list of k elements. If init is included, all elements in the list are initialized to init.

Example:

          (make-list 3)
             ⇒ (#<unspecified> #<unspecified> #<unspecified>)
          (make-list 5 'foo)
             ⇒ (foo foo foo foo foo)
— Function: list* obj1 obj2 ...

Works like list except that the cdr of the last pair is the last argument unless there is only one argument, when the result is just that argument. Sometimes called cons*. E.g.:

          (list* 1)
             ⇒ 1
          (list* 1 2 3)
             ⇒ (1 2 . 3)
          (list* 1 2 '(3 4))
             ⇒ (1 2 3 4)
          (list* args '())
             == (list args)
— Function: copy-list lst

copy-list makes a copy of lst using new pairs and returns it. Only the top level of the list is copied, i.e., pairs forming elements of the copied list remain eq? to the corresponding elements of the original; the copy is, however, not eq? to the original, but is equal? to it.

Example:

          (copy-list '(foo foo foo))
             ⇒ (foo foo foo)
          (define q '(foo bar baz bang))
          (define p q)
          (eq? p q)
             ⇒ #t
          (define r (copy-list q))
          (eq? q r)
             ⇒ #f
          (equal? q r)
             ⇒ #t
          (define bar '(bar))
          (eq? bar (car (copy-list (list bar 'foo))))
          ⇒ #t