BANNER | ||
---|---|---|

Prev | DSSSL Documentation Project Procedures Library | Next |

**Table of Contents**- List
- Character
- String
- Length
- Node
- Flow Object
- Procedure
- Debugging

(any? |

Returns `#t` if predicate ` pred?` returns true when applied to any element of the list

;; Return #t if predicate `pred?' returns #t when applied to any ;; element of the `xs'. (define (any? pred? xs) (let loop ((xs xs)) (and (not (null? xs)) (or (pred? (car xs)) (loop (cdr xs)))))) |

(assoc-objs |

Returns a list of the objects in ` alist` as an associative list.

(define (assoc-objs alist) ;; Returns a list of the objects in an associative list. ;; (("a" "b") ("c" "d")) => ("a" "c") (let loop ((result '()) (al alist)) (if (null? al) result (loop (append result (list (car (car al)))) (cdr al))))) |

(break |

Returns

;; Like `span', but with the sense of the test reversed. (define (break test? xs) (span (compose not test?) xs)) |

(drop |

Returns the list ` xs` less the first

;; Return list `xs' less the first `n' elements. (define (drop n xs) (list-tail xs n)) |

(dropwhile |

Remove leading elements of list ` xs` for which

;; Remove leading elements of list `xs' for which `test?' returns ;; true. (define (dropwhile test? xs) (cond ((null? xs) '()) ((test? (car xs)) (dropwhile test? (cdr xs))) (else xs))) |

(list-member-find |

Returns the offset within ` element-list` of

The offset of the first element in ` element-list` is 0. Occurence of

(define (list-member-find element element-list) ;; Finds element in element-list and returns the index of its location. ;; The first element in a list has index 0. (let loop ((elemlist element-list) (count 0)) (if (null? elemlist) -1 (if (equal? element (car elemlist)) count (loop (cdr elemlist) (+ count 1)))))) |

(list-member-get |

Returns the element at offset ` count` within

(define (list-member-get element-list count) ;; Returns the count'th element from element-list. ;; The first element in a list has index 0. (let loop ((elemlist element-list) (idx count)) (if (null? elemlist) #f (if (= idx 0) (car elemlist) (loop (cdr elemlist) (- idx 1)))))) |

(remove |

Returns list ` ys` without any elements equalling

;; Remove any occurrences of `x' from list `ys'. (define (remove x ys) (cond ((null? ys) ys) ((equal? x (car ys)) (remove x (cdr ys))) (else (cons (car ys) (remove x (cdr ys)))))) |

(remove-if |

Returns list ` ys` without any elements for which predicate

;; Remove any elements `x' from that answer #t to `pred?'. (define (remove-if pred? ys) (cond ((null? ys) ys) ((pred? (car ys)) (remove-if pred? (cdr ys))) (else (cons (car ys) (remove-if pred? (cdr ys)))))) |

(sort |

Returns list ` l` sorted using comparison function

;; O'Keefe's smooth applicative merge sort: sort list `l' using ;; comparison function `<='. (define (sort <= l) (letrec ((merge (lambda (xs ys) (cond ((null? xs) ys) ((null? ys) xs) (else (if (<= (car xs) (car ys)) (cons (car xs) (merge (cdr xs) ys)) (cons (car ys) (merge xs (cdr ys)))))))) (mergepairs (lambda (l k) (if (null? (cdr l)) l (if (= 1 (modulo k 2)) l (mergepairs (cons (merge (car l) (cadr l)) (cddr l)) (quotient k 2)))))) (sorting (lambda (l a k) (if (null? l) (car (mergepairs a 0)) (sorting (cdr l) (mergepairs (cons (list (car l)) a) (+ k 1)) (+ k 1)))))) (cond ((not (list? l)) (error "sort: second arg not a list")) ((not (procedure? <=)) (error "sort: first arg not a procedure")) ((null? l) '()) (else (sorting l '() 0))))) |

(span |

Returns a pair of lists, one is the leading elements of the list ` xs` for which

;; From the list `xs', return a pair of lists comprising the leading ;; elements of `xs' for which `test?' returns true and the rest of ;; `xs'. After the Haskell prelude. (define (span test? xs) (if (null? xs) (cons '() '()) (let ((x (car xs)) ; split the xs into head (xss (cdr xs))) ; and tail (if (test? x) (let* ((spanned (span test? xss)) ;; and split the result of span into head and tail (ys (car spanned)) (zs (cdr spanned))) (cons (cons x ys) zs)) (cons '() xs))))) |

(take |

Returns the first ` n` elements of list

(define (take n xs) (let loop ((i 1) (xs xs)) (if (or (> i n) (null? xs)) '() (cons (car xs) (loop (+ 1 i) (cdr xs)))))) |

;; List zipping with the given `zipper' function. Like `map', but the ;; list args can be unequal lengths. (define (zip-with zipper #!rest xs) (if (any? null? xs) '() (cons (apply zipper (map car xs) ) (apply zip-with zipper (map cdr xs))))) |

Prev | Home | Next |

Derived Procedures [10.2] | Character |