Changeset 31172 in project


Ignore:
Timestamp:
08/01/14 14:37:30 (6 years ago)
Author:
juergen
Message:

in typed-lists item-equality added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/typed-lists

    r31169 r31172  
    4343                         documentation: docu
    4444                         item-predicate: ok?
     45                         item-equality: equ?
    4546                         procedure-prefix: pre)</macro>
    4647
    47 defines a new list type, name, whose items must pass the ok? predicate,
    48 and a documentation procedure, docu, by implementing a long list of
    49 functions, most of them prefixed by the prefix pre. Exceptions of this
    50 prefix rule are the constructor and type predicate for the list, named
    51 name as well or name with an appended question mark. The list of
    52 generated functions are given by a call to docu without arguments, the
    53 signature of such a function by the call (docu 'function).
     48defines a new list type, name, whose items must pass the ok? predicate
     49and are compared by equ?, and a documentation procedure, docu,
     50by implementing a long list of functions, most of them prefixed by the
     51prefix pre. Exceptions of this prefix rule are the constructor and type
     52predicate for the list, named name as well or name with an appended
     53question mark. The list of generated functions are given by a call to
     54docu without arguments, the signature of such a function by the call
     55(docu 'function).
    5456
    5557Note that most of the functions are prefixed versions of standard list
     
    6567
    6668(define-list-type lon
    67                   documentation: lons
    68                   item-predicate: (disjoin number?  (cell-of?  number?))
     69                  documentation: nlists
     70                  item-predicate: (lambda (x)
     71                                    (or (number? x)
     72                                        ((cell-of? number?) x)))
     73                  item-equality: (lambda (x y)
     74                                   (or (and (number? x)
     75                                            (number? y)
     76                                            (= x y))
     77                                       (and (cell? x)
     78                                            (cell? y)
     79                                            (= (cell-ref x)
     80                                               (cell-ref y)))))
    6981                  procedure-prefix: n)
    7082
     
    8092(napply + 1 2 (lon 3 4 5)) ; ->15
    8193(nrepeat 5 0) ; -> '#,(lon 0 0 0 0 0)
    82 (neqv? (niterate-times 5 add1 0) (lon 0 1 2 3 4)) ; -> #t
     94(nequal? (niterate-times 5 add1 0) (lon 0 1 2 3 4)) ; -> #t
    8395(niterate-while (lambda (x) (< x 5)) add1 0) ; -> '#,(lon 0 1 2 3 4))
    8496(niterate-until (lambda (x) (= x 5)) add1 0) ; -> '#,(lon 0 1 2 3 4)
     
    8799(ncdddr nlst) ; -> '#,(lon 3 4)
    88100(ncadddr nlst) ; -> 3
    89 (nequ? = (ndrop 3 nlst) (lon 3 4)) ; -> #t
    90 (nequ? = (ndrop-while odd? (lon 1 3 2 4 5))
     101(nequal? (ndrop 3 nlst) (lon 3 4)) ; -> #t
     102(nequal? (ndrop-while odd? (lon 1 3 2 4 5))
    91103         (lon 2 4 5)) ; -> #t
    92 (nequ? = (ntake-while odd? (lon 1 3 2 4 5))
     104(nequal? (ntake-while odd? (lon 1 3 2 4 5))
    93105         (lon 1 3)) ; -> #t
    94106(receive (head tail) (nsplit-with even? (lon 1 3 2 4 5))
    95   (and (neqv? head (lon 1 3))
    96        (neqv? tail (lon 2 4 5)))) ; -> #t
     107  (and (nequal? head (lon 1 3))
     108       (nequal? tail (lon 2 4 5)))) ; -> #t
    97109(ntake 2 nlst) ; -> (lon 0 1)
    98110(lon? (nnull)) ; -> #t
     
    113125(nequal? (nsublist 2 4 nlst)
    114126         (lon (cell 20) 3)) ; -> #t
    115 (nequ? =
    116        (nappend (lon 0 1 2 3)
    117                 (lon 4 5 6))
    118        (lon 0 1 2 3 4 5 6)) ; -> #t
    119 (nequ? =
    120        (nappend (lon 0)
    121                 (lon 1)
    122                 (lon 2)
    123                 (lon 3 4)
    124                 (lon 5 6 7)
    125                 (lon 8))
    126        (lon 0 1 2 3 4 5 6 7 8)) ; -> #t
    127 (nequ? =
    128        (nmap add1
    129              (lon 0 1 2 3))
    130        (lon 1 2 3 4)) ; -> #t
    131 (nequ? =
    132        (nmap +
    133              (lon 1 2 3)
    134              (lon 10 20 30 40))
    135        (lon 11 22 33)) ; -> #t
     127(nequal?
     128  (nappend (lon 0 1 2 3)
     129           (lon 4 5 6))
     130  (lon 0 1 2 3 4 5 6)) ; -> #t
     131(nequal?
     132  (nappend (lon 0)
     133           (lon 1)
     134           (lon 2)
     135           (lon 3 4)
     136           (lon 5 6 7)
     137           (lon 8))
     138  (lon 0 1 2 3 4 5 6 7 8)) ; -> #t
     139(nequal?
     140  (nmap add1
     141        (lon 0 1 2 3))
     142  (lon 1 2 3 4)) ; -> #t
     143(nequal?
     144  (nmap +
     145        (lon 1 2 3)
     146        (lon 10 20 30 40))
     147  (lon 11 22 33)) ; -> #t
    136148(nfold-right ncons (nnull) (lon 0 1 2 3 4)) ; -> '#,(lon 0 1 2 3 4))
    137149(nfold-left + 0 (lon 1 2 3) (lon 10 20 30)) ; -> 66
     
    142154    list)
    143155  (list (lon 3 2 1) (lon 30 20 10))) ; -> #t
    144 (nremv 0 (lon 1 0 2 0 3 0 4)) ; -> '#,(lon 1 2 3 4)
     156(nremove 0 (lon 1 0 2 0 3 0 4)) ; -> '#,(lon 1 2 3 4)
    145157(nmerge < (lon 2 4 5 7 8) (lon 1 3 6 9 10)) ; -> '#,(lon 1 2 3 4 5 6 7 8 9 10))
    146158(condition-case (nmerge < (nnull) (lon 1 3 2))
     
    152164(nnot-every? odd? (lon 1 2 3)) ; -> #t
    153165(nnot-any? odd? (lon 2 4 6)) ; -> #t
     166(lon->set (lon 1 2 1 3 2 3)) ; -> '#,(lon 1 2 3)
     167(lon? (lon 1 2 3)) ; -> #t
     168(nset? (lon 1 2 3)) ; -> #t
     169(nset? (lon 1 2 2 3)) ; -> #f
     170(nin? 2 (lon 1 2 3)) ; -> #t
     171(nsubset? (lon 1 2) (lon 1 2 3 4)) ; -> #t
     172(nset-equal? (lon 1 2 3) (lon 2 1 3)) ; -> #t
     173(nsubset? (nset 1 2) (nset 1 2 3 4)) ; -> #t
     174(nadjoin 0 (nset 1 2 3)) ; -> '#,(lon 0 1 2 3)
     175(nadjoin 2 (nset 1 2 3)) ; -> '#,(lon 0 1 2 3)
     176(nset 0 1 1 0 2 3 2) ; -> '#,(lon 0 1 2 3)
     177(ndifference (nset 0 2 1 3) (nset 1 1)) ; -> '#(lon 0 2 3)
     178(nunion (nset 1 2) (nset 2 3) (nset 3 4))
     179 ; -> '#(lon 1 2 3 4)
     180(nintersection (nset 1 2 3 4) (nset 2 3 5) (nset 3 4))
     181 ; -> '#(lon 3)
    154182
    155183(define-list-type lol
    156184                  documentation: lols
    157185                  item-predicate: list?
     186                  item-equality: equal?
    158187                  procedure-prefix: l)
    159188(lequal?
     
    170199== Last update
    171200
    172 Jul 30, 2014
     201Aug 02, 2014
    173202
    174203== Author
     
    178207== License
    179208
    180  Copyright (c) 2011-2014, Juergen Lorenz
     209 Copyright (c) 2014, Juergen Lorenz
    181210 All rights reserved.
    182211
Note: See TracChangeset for help on using the changeset viewer.