((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/tuples" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (tags "egg") (toc)) (section 2 "tuples" (p "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.") (p "singles are the only tuples, which can assign to their content. Other special tuples are couples and triples. They are all packaged in their own modules, and all of them use another module, %tuples, which contains the basic implementations without any checks. The unchecked routines are all prefixed with a %.") (p "Note, that couples can be used instead of pairs to implement immutable lists.")) (section 2 "Documentation" (p "In this implementation tuples and their relatives (except %tuples) are implemented in the Design by Contract style, i.e. using the dbc egg. A corollary of this is, that the documentation is included in each of these modules in form of a procedure with the module's name. Called without any argument, the list of exported symbols is shown, with such a symbol as argument, the symbol's documentation is shown, and with a string argument, some wiki-like documentation is printed to a file, which you can inspect below.") (section 3 "module tuples" (section 4 "list->tuple" (def (sig (procedure "(list->tuple lst)" (id list->tuple))) (p "function (result)") (highlight scheme "\n(list->tuple lst)\n\nrequires (list? lst)\n\nensures  (and (%tuple? result) (= (length lst) (%tuple-length result)))\n"))) (section 4 "tuple" (def (sig (procedure "(tuple . args)" (id tuple))) (p "function (result)") (highlight scheme "\n(tuple . args)\n\nrequires #t\n\nensures  (%tuple? result)\n"))) (section 4 "tuple->list" (def (sig (procedure "(tuple->list tup)" (id tuple->list))) (p "function (result)") (highlight scheme "\n(tuple->list tup)\n\nrequires (%tuple? tup)\n\nensures  (list? result)\n"))) (section 4 "tuple->vector" (def (sig (procedure "(tuple->vector tup)" (id tuple->vector))) (p "function (result)") (highlight scheme "\n(tuple->vector tup)\n\nrequires (%tuple? tup)\n\nensures  (vector? result)\n"))) (section 4 "tuple-append" (def (sig (procedure "(tuple-append . tups)" (id tuple-append))) (p "function (result)") (highlight scheme "\n(tuple-append . tups)\n\nrequires ((list-of? %tuple?) tups)\n\nensures  (and (%tuple? result)\n              (= (tuple-length result)\n                 (apply + (map tuple-length tups))))\n"))) (section 4 "tuple-butleft" (def (sig (procedure "(tuple-butleft tup)" (id tuple-butleft))) (p "function (result)") (highlight scheme "\n(tuple-butleft tup)\n\nrequires (and (%tuple? tup)\n              (positive? (%tuple-length tup)))\n\nensures  (and (%tuple result)\n              (= (%tuple-length result)\n                 (- (%tuple-length tup) 1)))\n"))) (section 4 "tuple-butright" (def (sig (procedure "(tuple-butright tup)" (id tuple-butright))) (p "function (result)") (highlight scheme "\n(tuple-butright tup)\n\nrequires (and (%tuple? tup) (positive? (%tuple-length tup)))\n\nensures  (and (%tuple result)\n              (= (%tuple-length result)\n                 (- (%tuple-length tup) 1)))\n"))) (section 4 "tuple-cons-left" (def (sig (procedure "(tuple-cons-left arg tup)" (id tuple-cons-left))) (p "function (result)") (highlight scheme "\n(tuple-cons-left arg tup)\n\nrequires (%tuple? tup)\n\nensures  (and (%tuple result)\n              (= (%tuple-length result)\n                 (+ (%tuple-length tup) 1)))\n"))) (section 4 "tuple-cons-right" (def (sig (procedure "(tuple-cons-right arg tup)" (id tuple-cons-right))) (p "function (result)") (highlight scheme "\n(tuple-cons-right arg tup)\n\nrequires (%tuple? tup)\n\nensures  (and (%tuple result)\n              (= (%tuple-length result)\n                 (+ (%tuple-length tup) 1)))\n"))) (section 4 "tuple-copy" (def (sig (procedure "(tuple-copy tup)" (id tuple-copy))) (p "function (result)") (highlight scheme "\n(tuple-copy tup)\n\nrequires (%tuple tup)\n\nensures  (%tuple result)\n"))) (section 4 "tuple-empty?" (def (sig (procedure "(tuple-empty? xpr)" (id tuple-empty?))) (p "function (result)") (highlight scheme "\n(tuple-empty? xpr)\n\nrequires #t\n\nensures  (boolean? result)\n"))) (section 4 "tuple-eq?" (def (sig (procedure "(tuple-eq? tup0 tup1)" (id tuple-eq?))) (p "function (result)") (highlight scheme "\n(tuple-eq? tup0 tup1)\n\nrequires (and (%tuple? tup0) (%tuple? tup1))\n\nensures  (boolean? result)\n"))) (section 4 "tuple-eql?" (def (sig (procedure "(tuple-eql? eql? tup0 tup1)" (id tuple-eql?))) (p "function (result)") (highlight scheme "\n(tuple-eql? eql? tup0 tup1)\n\nrequires (and (procedure? eql?)\n              (%tuple? tup0) (%tuple? tup1))\n\nensures  (boolean? result)\n"))) (section 4 "tuple-equal?" (def (sig (procedure "(tuple-equal? tup0 tup1)" (id tuple-equal?))) (p "function (result)") (highlight scheme "\n(tuple-equal? tup0 tup1)\n\nrequires (and (%tuple? tup0) (%tuple? tup1))\n\nensures  (boolean? result)\n"))) (section 4 "tuple-eqv?" (def (sig (procedure "(tuple-eqv? tup0 tup1)" (id tuple-eqv?))) (p "function (result)") (highlight scheme "\n(tuple-eqv? tup0 tup1)\n\nrequires (and (%tuple? tup0) (%tuple? tup1))\n\nensures  (boolean? result)\n"))) (section 4 "tuple-find" (def (sig (procedure "(tuple-find ok? tup)" (id tuple-find))) (p "function (result)") (highlight scheme "\n(tuple-find ok? tup)\n\nrequires (and (procedure? ok?) (%tuple? tup))\n\nensures  (or (not result)\n             (and (cardinal? result)\n                  (< result (%tuple-length tup))\n                  \"index of found item\"))\n"))) (section 4 "tuple-for-each" (def (sig (procedure "(tuple-for-each proc tup . tups)" (id tuple-for-each))) (p "command ((old new (lambda (proc tup . tups) #t)))") (highlight scheme "\n(tuple-for-each proc tup . tups)\n\nrequires (and (procedure? proc)\n              (%tuple tup)\n              ((list-of? %tuple?) tups)\n              (apply = (%tuple-length tup) (map %tuple-length tups)))\n\nensures  \"proc applied to each item\"\n"))) (section 4 "tuple-from-upto" (def (sig (procedure "(tuple-from-upto tup . interval)" (id tuple-from-upto))) (p "function (result)") (highlight scheme "\n(tuple-from-upto tup . interval)\n\nrequires (and (%tuple tup)\n              ((list-of? (lambda (x)\n                           (and (cardinal? x)\n                           (<= x (%tuple-length tup))))) interval)\n              (<= (length interval) 2) (apply <= 0 interval))\n\nensures  (and (%tuple? result)\n              (= (%tuple-length result)\n                 (case (length interval)\n\t\t\t\t\t\t\t\t\t ((0) (%tuple-length tup))\n\t\t\t\t\t\t\t\t\t ((1) (- (%tuple-length tup) (car interval)))\n\t\t\t\t\t\t\t\t\t ((2) (- (cadr interval) (car interval))))))\n"))) (section 4 "tuple-head" (def (sig (procedure "(tuple-head tup n)" (id tuple-head))) (p "function (result)") (highlight scheme "\n(tuple-head tup n)\n\nrequires (and (%tuple? tup)\n              (<= n (%tuple-length tup)))\n\nensures  (and (%tuple result) (= (%tuple-length result) n))\n"))) (section 4 "tuple-left" (def (sig (procedure "(tuple-left tup)" (id tuple-left))) (p "function (result)") (highlight scheme "\n(tuple-left tup)\n\nrequires (and (%tuple? tup) (positive? (%tuple-length tup)))\n\nensures  \"tup's leftmost item\"\n"))) (section 4 "tuple-length" (def (sig (procedure "(tuple-length tup)" (id tuple-length))) (p "function (result)") (highlight scheme "\n(tuple-length tup)\n\nrequires (%tuple? tup)\n\nensures  (cardinal? result)\n"))) (section 4 "tuple-map" (def (sig (procedure "(tuple-map fn tup . tups)" (id tuple-map))) (p "function (result)") (highlight scheme "\n(tuple-map fn tup . tups)\n\nrequires (and (procedure? fn)\n              (%tuple? tup)\n              ((list-of? %tuple?) tups)\n              (apply = (%tuple-length tup)\n                       (map %tuple-length tups)))\n\nensures  (and (%tuple? result)\n              (= (%tuple-length tup)\n                 (%tuple-length result)))\n"))) (section 4 "tuple-of?" (def (sig (procedure "(tuple-of? ok?)" (id tuple-of?))) (p "function (result)") (highlight scheme "\n(tuple-of? ok?)\n\nrequires (procedure? ok?)\n\nensures  (procedure? result)\n"))) (section 4 "tuple-ref" (def (sig (procedure "(tuple-ref tup n)" (id tuple-ref))) (p "function (result)") (highlight scheme "\n(tuple-ref tup n)\n\nrequires (and (%tuple? tup)\n              (cardinal? n)\n              (< -1 n (%tuple-length tup)))\n\nensures  \"tup's nth item\"\n"))) (section 4 "tuple-reverse" (def (sig (procedure "(tuple-reverse tup)" (id tuple-reverse))) (p "function (result)") (highlight scheme "\n(tuple-reverse tup)\n\nrequires (%tuple? tup)\n\nensures  (and (%tuple result)\n              (= (%tuple-length result)\n                 (%tuple-length tup)))\n"))) (section 4 "tuple-right" (def (sig (procedure "(tuple-right tup)" (id tuple-right))) (p "function (result)") (highlight scheme "\n(tuple-right tup)\n\nrequires (and (%tuple? tup) (positive? (%tuple-length tup)))\n\nensures  \"tup's rightmost item\"\n"))) (section 4 "tuple-split" (def (sig (procedure "(tuple-split tup at)" (id tuple-split))) (p "function (head tail)") (highlight scheme "\n(tuple-split tup at)\n\nrequires (and (%tuple? tup)\n          (cardinal? at) (< at (%tuple-length tup)))\n\nensures (and (%tuple? head) (%tuple? tail)\n          (%tuple-eql? equal? tup (%tuple-append head tail)))))\n"))) (section 4 "tuple-tail" (def (sig (procedure "(tuple-tail tup n)" (id tuple-tail))) (p "function (result)") (highlight scheme "\n(tuple-tail tup n)\n\nrequires (and (%tuple? tup) (<= n (%tuple-length tup)))\n\nensures  (and (%tuple result)\n              (= (%tuple-length result)\n                 (- (%tuple-length tup) n)))\n"))) (section 4 "tuple?" (def (sig (procedure "(tuple? xpr)" (id tuple?))) (p "function (result)") (highlight scheme "\n(tuple? xpr)\n\nrequires #t\n\nensures  (boolean? result)\n"))) (section 4 "vector->tuple" (def (sig (procedure "(vector->tuple vec)" (id vector->tuple))) (p "function (result)") (highlight scheme "\n(vector->tuple vec)\n\nrequires (vector? vec)\n\nensures  (and (%tuple? result)\n              (= (%tuple-length result)\n                 (vector-length vec)))\n")))) (section 3 "Module triples" (section 4 "triple" (def (sig (procedure "(triple x y z)" (id triple))) (p "function (result)") (highlight scheme "\n(triple x y z)\n\nrequires #t\n\nensures  (%triple? result)\n"))) (section 4 "triple->tuple" (def (sig (procedure "(triple->tuple trp)" (id triple->tuple))) (p "function (result)") (highlight scheme "\n(triple->tuple trp)\n\nrequires (%triple? trp)\n\nensures  (and (%tuple? result)\n              (= (%tuple-length result) 3))\n"))) (section 4 "triple-eq?" (def (sig (procedure "(triple-eq? trp0 trp1)" (id triple-eq?))) (p "function (result)") (highlight scheme "\n(triple-eq? trp0 trp1)\n\nrequires (and (%triple? trp0) (%triple? trp1))\n\nensures  (boolean? result)\n"))) (section 4 "triple-eql?" (def (sig (procedure "(triple-eql? eql? trp0 trp1)" (id triple-eql?))) (p "function (result)") (highlight scheme "\n(triple-eql? eql? trp0 trp1)\n\nrequires (and (procedure? eql?)\n              (%triple? trp0)\n              (%triple? trp1))\n\nensures  (boolean? result)\n"))) (section 4 "triple-equal?" (def (sig (procedure "(triple-equal? trp0 trp1)" (id triple-equal?))) (p "function (result)") (highlight scheme "\n(triple-equal? trp0 trp1)\n\nrequires (and (%triple? trp0) (%triple? trp1))\n\nensures  (boolean? result)\n"))) (section 4 "triple-eqv?" (def (sig (procedure "(triple-eqv? trp0 trp1)" (id triple-eqv?))) (p "function (result)") (highlight scheme "\n(triple-eqv? trp0 trp1)\n\nrequires (and (%triple? trp0) (%triple? trp1))\n\nensures  (boolean? result)\n"))) (section 4 "triple-left" (def (sig (procedure "(triple-left trp)" (id triple-left))) (p "function (result)") (highlight scheme "\n(triple-left trp)\n\nrequires (%triple? trp)\n\nensures  \"leftmost item\"\n"))) (section 4 "triple-middle" (def (sig (procedure "(triple-middle trp)" (id triple-middle))) (p "function (result)") (highlight scheme "\n(triple-middle trp)\n\nrequires (%triple? trp)\n\nensures  \"item in the middle\"\n"))) (section 4 "triple-right" (def (sig (procedure "(triple-right trp)" (id triple-right))) (p "function (result)") (highlight scheme "\n(triple-right trp)\n\nrequires (%triple? trp)\n\nensures  \"rightmost item\"\n"))) (section 4 "triple?" (def (sig (procedure "(triple? x)" (id triple?))) (p "function (result)") (highlight scheme "\n(triple? x)\n\nrequires #t\n\nensures  (boolean? result)\n")))) (section 3 "Module couples" (section 4 "couple" (def (sig (procedure "(couple x y)" (id couple))) (p "function (result)") (highlight scheme "\n(couple x y)\n\nrequires #t\n\nensures  (%couple? result)\n"))) (section 4 "couple->tuple" (def (sig (procedure "(couple->tuple cpl)" (id couple->tuple))) (p "function (result)") (highlight scheme "\n(couple->tuple cpl)\n\nrequires (%couple? cpl)\n\nensures  (and (%tuple? result)\n              (= (%tuple-length result) 2))\n"))) (section 4 "couple-eq?" (def (sig (procedure "(couple-eq? cpl0 cpl1)" (id couple-eq?))) (p "function (result)") (highlight scheme "\n(couple-eq? cpl0 cpl1)\n\nrequires (and (%couple? cpl0) (%couple? cpl1))\n\nensures  (boolean? result)\n"))) (section 4 "couple-eql?" (def (sig (procedure "(couple-eql? eql? cpl0 cpl1)" (id couple-eql?))) (p "function (result)") (highlight scheme "\n(couple-eql? eql? cpl0 cpl1)\n\nrequires (and (procedure? eql?)\n              (%couple? cpl0) (%couple? cpl1))\n\nensures  (boolean? result)\n"))) (section 4 "couple-equal?" (def (sig (procedure "(couple-equal? cpl0 cpl1)" (id couple-equal?))) (p "function (result)") (highlight scheme "\n(couple-equal? cpl0 cpl1)\n\nrequires (and (%couple? cpl0) (%couple? cpl1))\n\nensures  (boolean? result)\n"))) (section 4 "couple-eqv?" (def (sig (procedure "(couple-eqv? cpl0 cpl1)" (id couple-eqv?))) (p "function (result)") (highlight scheme "\n(couple-eqv? cpl0 cpl1)\n\nrequires (and (%couple? cpl0) (%couple? cpl1))\n\nensures  (boolean? result)\n"))) (section 4 "couple-left" (def (sig (procedure "(couple-left cpl)" (id couple-left))) (p "function (result)") (highlight scheme "\n(couple-left cpl)\n\nrequires (%couple? cpl)\n\nensures  \"leftmost item\"\n"))) (section 4 "couple-right" (def (sig (procedure "(couple-right cpl)" (id couple-right))) (p "function (result)") (highlight scheme "\n(couple-right cpl)\n\nrequires (%couple? cpl)\n\nensures  \"rightmost item\"\n"))) (section 4 "couple?" (def (sig (procedure "(couple? x)" (id couple?))) (p "function (result)") (highlight scheme "\n(couple? x)\n\nrequires #t\n\nensures  (boolean? result)\n")))) (section 3 "Module singles" (section 4 "single" (def (sig (procedure "(single x)" (id single))) (p "function (result)") (highlight scheme "\n(single x)\n\nrequires #t\n\nensures  (%single? result)\n"))) (section 4 "single-eq?" (def (sig (procedure "(single-eq? sgl0 sgl1)" (id single-eq?))) (p "function (result)") (highlight scheme "\n(single-eq? sgl0 sgl1)\n\nrequires (and (%single? sgl0) (%single? sgl1))\n\nensures  (boolean? result)\n"))) (section 4 "single-eql?" (def (sig (procedure "(single-eql? eql? sgl0 sgl1)" (id single-eql?))) (p "function (result)") (highlight scheme "\n(single-eql? eql? sgl0 sgl1)\n\nrequires (and (procedure? eql?)\n              (%single? sgl0) (%single? sgl1))\n\nensures  (boolean? result)\n"))) (section 4 "single-equal?" (def (sig (procedure "(single-equal? sgl0 sgl1)" (id single-equal?))) (p "function (result)") (highlight scheme "\n(single-equal? sgl0 sgl1)\n\nrequires (and (%single? sgl0) (%single? sgl1))\n\nensures  (boolean? result)\n"))) (section 4 "single-eqv?" (def (sig (procedure "(single-eqv? sgl0 sgl1)" (id single-eqv?))) (p "function (result)") (highlight scheme "\n(single-eqv? sgl0 sgl1)\n\nrequires (and (%single? sgl0) (%single? sgl1))\n\nensures  (boolean? result)\n"))) (section 4 "single-ref" (def (sig (procedure "(single-ref sg)" (id single-ref))) (p "function (result)") (highlight scheme "\n(single-ref sg)\n\nrequires (%single? sg)\n\nensures  \"sg's stored item\"\n"))) (section 4 "single-set!" (def (sig (procedure "(single-set! sg x)" (id single-set!))) (p "command ((old new (lambda (sg x) (%single-ref sg))))") (highlight scheme "\n(single-set! sg x)\n\nrequires (%single? sg)\n\nensures  (equal? new x)\n"))) (section 4 "single?" (def (sig (procedure "(single? x)" (id single?))) (p "function (result)") (highlight scheme "\n(single? x)\n\nrequires #t\n\nensures  (boolean? result)\n"))))) (section 2 "Requirements" (p (int-link "dbc"))) (section 2 "Last update" (p "Feb 11, 2014")) (section 2 "Author" (p (int-link "/users/juergen-lorenz" "Juergen Lorenz"))) (section 2 "License" (pre "Copyright (c) 2012-2014, Juergen Lorenz\nAll rights reserved.") (pre "Redistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\nRedistributions of source code must retain the above copyright\nnotice, this list of conditions and the following disclaimer.\n\nRedistributions in binary form must reproduce the above copyright\nnotice, this list of conditions and the following disclaimer in the\ndocumentation and/or other materials provided with the distribution.\nNeither the name of the author nor the names of its contributors may be\nused to endorse or promote products derived from this software without\nspecific prior written permission. \n  \nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS\nIS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\nTO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\nPARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nHOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\nTO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\nPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\nNEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.")) (section 2 "Version History" (dl (dt "1.2") (dd "tests with define-test instead of simple-test") (dt "1.1") (dd "implementation-module renamed, tests with simple-tests, tuple-split added") (dt "1.0") (dd "dependency on contracts changed to dbc, modules further split, addition routines") (dt "0.8") (dd "code split into two modules") (dt "0.7") (dd "single-state and single-state! renamed to single-ref and single-set!") (dt "0.6") (dd "contracts rewritten") (dt "0.5") (dd "code maintenance") (dt "0.4") (dd "added copyright notice") (dt "0.3") (dd "updated for using contracts 1.0") (dt "0.2") (dd "added tuple-copy, tuple-left,  tuple-right") (dt "0.1") (dd "initial import"))))