#lang scribble/doc @(require scribble/manual (planet cce/scheme:4:1/planet) (only-in (for-label scheme) for sequence?) (for-label scheme/contract) (for-label (this-package-in main))) @title[#:tag "main"]{Bindings} @defmodule/this-package[] The main module provides bindings for list operations. @defproc[(cons [x any] [xs list?]) list?]{ Cons @scheme[x] onto @scheme[xs].} @defthing[empty empty?]{ The empty list.} @defproc[(list [x any/c] ...) list?]{ Returns a list containing the given @scheme[x]s as its elements.} @defproc[(list* [x any/c] ... [xs list?]) list?]{ Returns a list containing the give @scheme[x]s as its elements and @scheme[xs] as its tail.} @defproc[(empty? [x any/c]) boolean?]{ Is @scheme[x] the empty list?} @defproc[(cons? [x any/c]) boolean?]{ Is @scheme[x] a cons (a non-empty list)?} @defproc[(list? [x any/c]) boolean?]{ Is @scheme[x] a list?} @defproc[(first [xs cons?]) any]{ Returns the first element of the list @scheme[xs].} @defproc[(rest [xs cons?]) list?]{ Returns the rest of the element of the list @scheme[xs].} @defproc[(list-ref [xs cons?] [i natural-number/c]) any/c]{ Returns the element of @scheme[xs] at position @scheme[i]. This operation runs in O(@scheme[(min i (log2 (length xs)))]).} @defproc[(list-set [xs cons?] [i natural-number/c] [v any/c]) cons?]{ Returns a list identical to @scheme[xs], except @scheme[v] is the @scheme[i]th element. This operation runs in O(@scheme[(min i (log2 (length xs)))]).} @defproc[(list-update [xs cons?] [i natural-number/c] [f procedure?]) cons?]{ Returns @scheme[(list-set xs i (f (list-ref xs i)))].} @defproc[(list-ref/set [xs cons?] [i natural-number/c] [v any/c]) (values any/c cons?)]{ Returns @scheme[(values (list-ref xs i) (list-set xs i v))], but is more efficient.} @defproc[(list-ref/update [xs cons?] [i natural-number/c] [f procedure?]) (values any/c cons?)]{ Returns @scheme[(values (list-ref xs i) (list-set xs i (f (list-ref xs i))))], but is more efficient.} @defproc[(second [xs list?]) any/c]{ Returns the second element of the list.} @defproc[(third [xs list?]) any/c]{ Returns the third element of the list.} @defproc[(fourth [xs list?]) any/c]{ Returns the fourth element of the list.} @defproc[(fifth [xs list?]) any/c]{ Returns the fifth element of the list.} @defproc[(sixth [xs list?]) any/c]{ Returns the sixth element of the list.} @defproc[(seventh [xs list?]) any/c]{ Returns the seventh element of the list.} @defproc[(eighth [xs list?]) any/c]{ Returns the eighth element of the list.} @defproc[(ninth [xs list?]) any/c]{ Returns the ninth element of the list.} @defproc[(tenth [xs list?]) any/c]{ Returns the tenth element of the list.} @defproc[(last [xs cons?]) any/c]{ Returns the last element of the list.} @defproc[(map [f procedure?] [xs list?] ...+) list?]{ Applies @scheme[f] to each element of @scheme[xs]s from the first element to the last. The @scheme[f] argument must accept the same number of arguments as the number of supplied @scheme[xs]s. The result is a list containing each result of @scheme[proc] in order.} @defproc[(foldr [proc procedure?] [init any/c] [xs list?] ...+) any]{ Like @scheme[foldr] but for random-access lists.} @defproc[(foldl [proc procedure?] [init any/c] [xs list?] ...+) any]{ Like @scheme[foldl] but for random-access lists.} @defproc[(andmap [proc procedure?] [xs list?] ...+) any]{ Like @scheme[andmap] but for random-access lists.} @defproc[(ormap [proc procedure?] [xs list?] ...+) any]{ Like @scheme[ormap] but for random-access lists.} @defproc[(make-list [n natural-number/c] [x any?]) list?]{ Returns a list with @scheme[n] elements, all of which are @scheme[x]. Equivalent to @scheme[(build-list n (lambda (i) x))].} @defproc[(build-list [n natural-number/c] [proc procedure?]) list?]{ Like @scheme[build-list] but produces a random-access list.} @defproc[(length [xs list?]) natural-number/c]{ Returns the length of the list. This operation runs in O(@scheme[(log2 (length xs))]).} @defproc[(list-tail [xs list?] [i natural-number/c]) list?]{ Returns the list after the first @scheme[i] elements of @scheme[xs]. This operation, like its pair counterpart runs in O(@scheme[i]).} @defproc[(append [xs list?] ...) list?]{ Returns a list with all the elements of the given lists in order.} @defproc[(reverse [xs list?]) list?]{ Returns a list with all the elements of @scheme[xs] in reverse order.} @defproc[(in-list [xs list?]) list?]{ Returns a sequence equivalent to @scheme[xs]. Since lists are sequences, this is a list identity function, but an @scheme[in-list] application can provide better performance when it appears directly in a @scheme[for] clause.}