You are looking at historical revision 27163 of this page. It may differ significantly from its current revision.

- tuples
- Documentation
- tuples
- triple-right
- triple-middle
- triple-left
- triple
- triple?
- couple-right
- couple-left
- couple
- couple?
- single-set!
- single-ref
- single
- single?
- empty
- empty?
- tuple-for-each
- tuple->list
- tuple-find
- tuple-right
- tuple-left
- tuple-ref
- tuple-length
- tuple-copy
- tuple-append
- tuple-map
- list->tuple
- tuple
- tuple-of?
- tuple?

- Requirements
- Last update
- Author
- License
- Version History

## tuples

Tuples are a datatype which has much in common with vectors. Namely they store a finite number of items with random access and make them available via (tuple-ref tup n). But contrary to vectors, the items can only by accessed but not assigned to. If you want to change a particular item, you must package it into a box or a single, which is a special tuple storing exactly one item, which can be changed via single-set! without changing the identity of the single object itself.

singles are the only tuples, which can assign to their content. Other special tuples are empty, couple and triple. Note, that couples can be used instead of pairs to implement immutable lists.

## Documentation

In this implementation skiplists are implemented in the Design by Contract style, i.e. using the contracts module. A corollary of this is, that the documentation is included in one of the two modules in form of a procedure with the module's name. Apart from this documentation procedure the two modules, %tuples and tuples, have the same interface. The first module contains the raw implementations of the procedures, the second imports the first with prefix % and wraps those prefixed routines with contracts.

#### tuples

*[procedure]*

`(tuples [sym])`

returns all available routines of the module when called without an argument, but when called with one of these routines as a symbol, returns its contract and documentation string.

Another way to get the complete documentation is to use print-doclist from the contracts module. Issuing

(import tuples (only contracts print-doclist)) (with-output-to-file"tuples.docu" (lambda() (print-doclist)))

you'll get a file tuples.docu which is the basis for the following documentation.

#### triple-right

*[procedure]*

`(triple-right tup)`

returns the right item of a triple

#### triple-middle

*[procedure]*

`(triple-middle tup)`

returns the middle item of a triple

#### triple-left

*[procedure]*

`(triple-left tup)`

returns the left item of a triple

#### triple

*[procedure]*

`(triple x y z)`

constructor for a tuple storing two items

#### triple?

*[procedure]*

`(triple? x)`

tests for a tuple storing two items

#### couple-right

*[procedure]*

`(couple-right tup)`

returns the right item of a couple

#### couple-left

*[procedure]*

`(couple-left tup)`

returns the left item of a couple

#### couple

*[procedure]*

`(couple x y)`

constructor for a tuple storing two items

#### couple?

*[procedure]*

`(couple? x)`

tests for a tuple storing two items

#### single-set!

*[procedure]*

`(single-set! sg arg)`

(domain (%single? sg) (true? arg)) (effect (state (%tuple-state sg) arg))

replaces state of sg with arg

#### single-ref

*[procedure]*

`(single-ref sg)`

(domain (%single? sg))

returns the state of the single object sg

#### single

*[procedure]*

`(single xpr)`

(domain (true? xpr)) (range (%single? result))

package xpr into a box so that it can be modified

#### single?

*[procedure]*

`(single? xpr)`

check, if xpr evaluates to a single

#### empty

*[procedure]*

`(empty)`

constructor for an empty tuple

#### empty?

*[procedure]*

`(empty? x)`

tests for an empty tuple

#### tuple-for-each

*[procedure]*

`(tuple-for-each proc tup)`

(domain (%tuple? tup) (procedure? proc) a one parameter procedure)

apply a one parameter procedure to each item of tup

#### tuple->list

*[procedure]*

`(tuple->list tup)`

(domain (%tuple? tup)) (range (list? result))

transforms a tuple into a list

#### tuple-find

*[procedure]*

`(tuple-find tup item compare?)`

(domain (%tuple? tup) (procedure? compare?) a two parameter predicate) (range (or (not result) (and (cardinal? result) (< result (%tuple-length tup)))))

checks by comparing with compare? if item is contained in tup

#### tuple-right

*[procedure]*

`(tuple-right tup)`

(domain (%tuple? tup) (>= (%tuple-length tup) 2))

returns the rightmost item of tup

#### tuple-left

*[procedure]*

`(tuple-left tup)`

(domain (%tuple? tup) (positive? (%tuple-length tup)))

returns the leftmost item of tup

#### tuple-ref

*[procedure]*

`(tuple-ref tup n)`

(domain (%tuple? tup) (cardinal? n) (< n (%tuple-length tup)))

returns the n'th item of tup, counting from zero

#### tuple-length

*[procedure]*

`(tuple-length tup)`

(domain (%tuple? tup)) (range (cardinal? result))

returns the number of tuple items

#### tuple-copy

*[procedure]*

`(tuple-copy tup . interval)`

(domain (%tuple? tup) (<= (length interval) 2) ((list-of? cardinal?) interval) (apply <= (append interval (list (%tuple-length tup))))) (range (%tuple? result))

constructing a subtuple with tup data from interval

#### tuple-append

*[procedure]*

`(tuple-append . tups)`

(domain ((list-of? tuple?) tups)) (range (%tuple? result))

constructs a new tuple by concatenating several others

#### tuple-map

*[procedure]*

`(tuple-map fn tup)`

(domain (%tuple? tup) (procedure? fn) a one parameterfunction) (range (%tuple? result))

constructs a new tuple by mapping each item of tup with function fn

#### list->tuple

*[procedure]*

`(list->tuple lst)`

(domain (list? lst)) (range (%tuple? result))

transforms a list into a tuple

#### tuple

*[procedure]*

`(tuple . args)`

(domain (true? args)) (range (%tuple? result))

tuple constructor

#### tuple-of?

*[procedure]*

`(tuple-of? ok?)`

(domain (procedure? ok?) ok? is a one parameter predicate) (range (procedure? result) result is a one parameter predicate)

checks, if each tuple item satisfies predicate ok?

#### tuple?

*[procedure]*

`(tuple? xpr)`

checks if xpr evaluates to a tuple

## Requirements

## Last update

Aug 02, 2012

## Author

## License

Copyright (c) 2012, Juergen Lorenz All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

## Version History

- 0.8
- code split into two modules
- 0.7
- single-state and single-state! renamed to single-ref and single-set!
- 0.6
- contracts rewritten
- 0.5
- code maintenance
- 0.4
- added copyright notice
- 0.3
- updated for using contracts 1.0
- 0.2
- added tuple-copy, tuple-left, tuple-right
- 0.1
- initial import