Next: , Previous: , Up: lists   [Index]


23.3 Constructors

Function: xcons obj1 obj2

The name stands for “eXchanged CONS”, it is like cons but reverses the arguments. Of utility only as a value to be conveniently passed to higher–order procedures.

(cons 1 2)  ⇒ (1 . 2)
(xcons 1 2) ⇒ (2 . 1)
Function: make-list n
Function: make-list n fill
Syntax: make-list/stx n
Syntax: make-list/stx n fill

Return an n–element list, whose elements are all the value fill. If fill is not given, the elements of the list may be arbitrary values.

(make-list 4 'c)
⇒ (c c c c)

(make-list 0)
⇒ ()
Function: list-copy fell
Syntax: list-copy/stx fell

Copy the spine of the argument.

Function: tree-copy fell
Syntax: tree-copy/stx fell

Copy the whole tree of fell, not only the spine (which is what list-copy does).

Function: list-tabulate n init-proc
Function: list-tabulate/reverse n init-proc
Syntax: list-tabulate/stx n init-proc
Syntax: list-tabulate/reverse/stx n init-proc

Return an n–element list. Element i of the list, where 0 <= i < n, is produced by (init-proc i).

The basic variants build the list from element 0 to element n-1. The ‘/reverse’ variants build the lists in reversed order, with element n-1 created first. The ‘/reverse’ variants may be a little faster, especially for long lists.

(list-tabulate 4 values)
⇒ (0 1 2 3)
Function: iota count
Function: iota count start
Function: iota count start step
Syntax: iota/stx count
Syntax: iota/stx count start
Syntax: iota/stx count start step

Return a list containing the elements:

(start start+step ... start+(count-1)*step)

The start and step parameters default to 0 and 1, respectively. count must be a non–negative number. The resulting list is built in reverse, starting from the last element.

(iota 5)
⇒ (0 1 2 3 4)

(iota 5 0 -0.1)
⇒ (0 -0.1 -0.2 -0.3 -0.4)

Next: , Previous: , Up: lists   [Index]