forsyth20121014-095501326a214 years agoHistory
204 lines · 4.1 KB · Text
RawDownload
.TH LISTS 2.SH NAMElists: allsat, anysat, append, combine, concat, delete, filter, find, ismember, last, map, pair, partition, reverse, unpair\- list operations.SH SYNOPSIS.EXinclude "lists.m"lists := load Lists Lists->PATH; append:    fn[T](l: list of T, x: T): list of T;combine:   fn[T](l1: list of T, l2: list of T): list of T;concat:    fn[T](l1: list of T, l2: list of T): list of T;delete:    fn[T](x: T, l: list of T): list of T             for { T => eq:  fn(a, b: T): int; };find:      fn[T](x: T, l: list of T): list of T             for { T => eq:  fn(a, b: T): int; };ismember:  fn[T](x: T, l: list of T): int             for { T =>  eq: fn(a, b: T): int; };last:      fn[T](l: list of T): T;pair:      fn[T1, T2](l1: list of T1, l2: list of T2):             list of (T1, T2);reverse:   fn[T](l: list of T): list of T;unpair:    fn[T1, T2](l: list of (T1, T2)):             (list of T1, list of T2); allsat:    fn[T](p: ref fn(x: T): int, l: list of T): int;anysat:    fn[T](p: ref fn(x: T): int, l: list of T): int;filter:    fn[T](p: ref fn(x: T): int, l: list of T): list of T;map:       fn[T](f: ref fn(x: T): T, l: list of T): list of T;partition: fn[T](p: ref fn(x: T): int, l: list of T):             (list of T, list of T);.EE.SH DESCRIPTIONThe module provides operations on lists of type.IR T ,which may be any reference type, or.BR string .Reference types are.BR array ,.BR chan ,.BR list ,.BR module ,and.BI ref " adt".None of the operations change their parameter lists: they always return a new list..PPFirst, there is a group of common list operations..PP.B Appendreturns a new list with the elements of.I lfollowed by the element.IR x ..PP.B Combinereturns a new list that has the elements of both.I l1and.I l2in no defined order..PP.B Concatreturns a new list that has the elements of.I l1followed by the elements of.IR l2 ..PP.B Deletereturns a new list in which the first element of.I lthat is equal to.I xhas been removed (all others remain)..I Xmust be an adt reference type.I Twith an operation.IB T .eqthat returns true (non-zero) if two values of type.I Tare considered equal..PP.B Findfinds the first instance of.I xin list.I land returns the tail of.I lwith.I xat its head..B Findreturns nil if there is noinstance of.I xin.IR l ..PP.B Ismemberreturns 1 ifthere is an element of.I lthat is equal to.IR x ..PP.B Lastreturns the value of the element at the end of list.IR l .A run-time error occurs if.I lis nil..PP.B Pairtakes two lists.I l1and.IR l2 ,and returns a new list of tuples.BI ( v1,\ v2 )in which each element of.I l1has been paired with the corresponding element of.IR l2 .A run-time error occurs if the lists are not equal in length..PP.B Reversereturns a new list containing the elements of.I lin reverse order..PP.B Unpairtakes a list of tuples.BI ( v1,\ v2 )and returns a tuple of lists.BI ( l1,\ l2 )where.I l1contains the first element of each tuple, and.I l2contains the second element of each tuple..PPA second group of operations applies a function.I for a Boolean predicate.I pto each element of a list.IR l ,returning a transformed list or a Boolean value.A predicate.I pmust return non-zero if its parameter value satisfies its condition, and must return zero if it does not..PP.B Allsatreturns 1 if all elements of.I lsatisfy.IR p ,and returns 0 otherwise..PP.B Anysatreturns 1 if any element of.I lsatisfies.IR p ,and returns 0 otherwise..PP.B Filterreturns a new list containing only the elements of.I lthat satisfy.IR p ..PP.B Mapreturns a new list in which each element of.I lhas been transformed by.I f(ie, if.I lis.IB e0 :: e1 ::  ...then the result is.IB f(e0) :: f(e1) :: ... )..PP.B Partitionreturns a tuple of lists.BI ( l1,\ l2 )of lists where.I l1contains all elements of.I lthat satisfy.I pand.I l2contains all elements of.I lthat do not satisfy.IR p ..SH SOURCE.B /appl/lib/lists.b.SH BUGSThe current implementation of polymorphism is limited to reference types and strings,which in turn limits use of this module.