manpagez: man pages & more
info bigloo
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.3 Pairs and lists

The form () is illegal.

procedure: pair? obj
procedure: cons a d
bigloo procedure: pair-or-null? obj

Returns #t if obj is either a pair or the empty list. Otherwise it returns #f.

procedure: car pair
procedure: cdr pair
procedure: set-car! pair obj
procedure: set-cdr! pair obj
library procedure: caar pair
library procedure: cadr pair
library procedure: cadar pair
library procedure: caadr pair
library procedure: caaar pair
library procedure: caddr pair
library procedure: cadar pair
library procedure: cdddar pair
library procedure: cddddr pair
library procedure: null? obj
library procedure: list? obj
library procedure: list obj …
library procedure: length list
library procedure: append list …
bigloo procedure: append! list …

A destructive append.

library procedure: reverse list
bigloo procedure: reverse! list

A destructive reverse.

library procedure: list-ref list k
library procedure: take list k
library procedure: drop list k
library procedure: list-tail list k

list-ref returns the k element of the list.

take returns a new list made of the first k element of the list.

Drop and list-tail returns the sublist of list obtained by omitting the first k elements.

bigloo procedure: last-pair list

Returns the last pair in the nonempty, possibly improper, list.

library procedure: memq obj list
library procedure: memv obj list
library procedure: member obj list
library procedure: assq obj alist
library procedure: assv obj alist
library procedure: assoc obj alist
bigloo procedure: remq obj list

Returns a new list which is a copy of list with all items eq? to obj removed from it.

bigloo procedure: remq! obj list

Same as remq but in a destructive way.

bigloo procedure: delete obj list [eq equal?]

Returns a new list which is a copy of list with all items equal? to obj deleted from it.

bigloo procedure: delete! obj list [eq equal?]

Same as delete but in a destructive way.

bigloo procedure: cons* obj …

Returns an object formed by consing all arguments together from right to left. If only one obj is supplied, that obj is returned.

bigloo procedure: every fun clist1 clist2 ...

Applies the function fun across the lists, returning the last non-false if the function returns non-false on every application. If non-false, the result of every is the last value returned by the last application of fun.

(every < '(1 2 3) '(2 3 4))            ⇒ #t
(every < '(1 2 3) '(2 3 0))            ⇒ #f
bigloo procedure: any fun clist1 clist2 ...

Applies the function fun across the lists, returning non-false if the function returns non-false for at least one application. If non-false, the result of any is the first non-false value returned by fun.

(any < '(1 2 3) '(2 3 4))            ⇒ #t
(any < '(1 2 3) '(2 3 0))            ⇒ #t
bigloo procedure: find pred clist

Return the first element of clist that satisfies predicate pred; false if no element does.

(find even? '(3 1 4 1 5 9))          ⇒ 4

Note that find has an ambiguity in its lookup semantics – if find returns #f, you cannot tell (in general) if it found a #f element that satisfied pred, or if it did not find any element at all. In many situations, this ambiguity cannot arise – either the list being searched is known not to contain any #f elements, or the list is guaranteed to have an element satisfying pred. However, in cases where this ambiguity can arise, you should use find-tail instead of find – find-tail has no such ambiguity:

    (cond ((find-tail pred lis) => (lambda (pair) ...)) ; Handle (CAR PAIR)
          (else ...)) ; Search failed.
bigloo procedure: find-tail pred clist

Return the first pair of clist whose car satisfies pred. If no pair does, return false.

find-tail can be viewed as a general-predicate variant of the member function.

Examples:

    (find-tail even? '(3 1 37 -8 -5 0 0)) ⇒ (-8 -5 0 0)
    (find-tail even? '(3 1 37 -5)) ⇒ #f

    ;; MEMBER X LIS:
    (find-tail (lambda (elt) (equal? x elt)) lis)

    In the circular-list case, this procedure "rotates" the list.
bigloo procedure: reduce f ridentity list

If list if null returns ridentity, if list has one element, returns that element. Otherwise, returns f applied to the first element of the list and to reduce of the rest of the list.

Examples:

    (reduce max 0 l) ≡ (apply max l)
bigloo procedure: make-list n [fill]

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

(make-list 4 'c)                     ⇒ (c c c c)
bigloo procedure: list-tabulate n init-proc

Returns an n-element list. Element i of the list, where 0 <= i < n, is produced by (init-proc i). No guarantee is made about the dynamic order in which init-proc is applied to these indices.

(list-tabulate 4 values)             ⇒ (0 1 2 3)
bigloo procedure: list-split list n [filler]
bigloo procedure: list-split list n [filler]

Split a list into a list of lists of length n. Last smaller list is filled with filler.

(list-split '(1 2 3 4 5 6 7 8) 3 0) ⇒ ((1 2 3) (4 5 6) (7 8 0))
(list-split (iota 10) 3)            ⇒ ((0 1 2) (3 4 5) (6 7 8) (9))
(list-split (iota 10 3) '-1)      ⇒ ((0 1 2) (3 4 5) (6 7 8) (9 -1 -1))
bigloo procedure: iota count [start step]

Returns a list containing the elements

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

The start and step parameters default to 0 and 1, respectively. This procedure takes its name from the APL primitive.

(iota 5) ⇒ (0 1 2 3 4)
(iota 5 0 -0.1) ⇒ (0 -0.1 -0.2 -0.3 -0.4)
bigloo procedure: list-copy l
bigloo procedure: tree-copy l

The function list-copy copies the spine of the of the list. The function tree-copy recursively copies its arguments, descending only into the list cells.

bigloo procedure: delete-duplicates list [eq equal?]
bigloo procedure: delete-duplicates! list [eq equal?]

delete-duplicates removes duplicate elements from the list argument. If there are multiple equal elements in the argument list, the result list only contains the first or leftmost of these elements in the result. The order of these surviving elements is the same as in the original list – delete-duplicates does not disorder the list (hence it is useful for "cleaning up" association lists).

The equal parameter is used to compare the elements of the list; it defaults to equal?. If x comes before y in list, then the comparison is performed (= x y). The comparison procedure will be used to compare each pair of elements in list no more than once; the order in which it is applied to the various pairs is not specified.

delete-duplicates is allowed to share common tails between argument and result lists – for example, if the list argument contains only unique elements, it may simply return exactly this list.

See (R5RS)r5rs.info, for more details.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on March 31, 2014 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.