Changeset 39598 in project


Ignore:
Timestamp:
02/15/21 12:19:28 (2 weeks ago)
Author:
juergen
Message:

pseudolists 3.0 docU

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/5/pseudolists

    r38335 r39598  
    22[[toc:]]
    33
    4 == Pseudolists
     4== Rationale
    55
    66This module exports routines to handle pseudolists as a generalisation
    7 of ordinary lists.
    8 
    9 === Rationale
    10 
    11 Pseudolists differ from lists insofor, as their sentinels might be
    12 arbitrary atoms instead of the empty list. In other words, a
    13 pseudolist is either a pair or an atom. But since an atom is simply not
    14 a pair, everything is a pseudolist, in particular, a list is one.
    15 
    16 So the routines of this module have to be written so that they work for
    17 lists as well. For example, this means, that the sentinel doesn't count
    18 in a length routine.
    19 
    20 Most functions in this module are written in curried and uncurried form.
    21 So the curried version can be used in maps and friends. The signature of
    22 both versions is documented below, but only the uncurried version is
    23 described. If the pseudolist argument is missing in the signature, it's
    24 the curried version.
    25 
    26 Note, that the order of arguments is consistent: Procedures come first
    27 and pseudolists last.
    28 
    29 === Module pseudolists
    30 
    31 ==== pseudolists
    32 
    33 <procedure>(pseudolists)</procedure>
    34 <procedure>(pseudolists sym)</procedure>
    35 
    36 documentation procedure. The first call shows the list of exported
    37 routines, the second documentation of the routine with symbol sym.
    38 
    39 ==== pl-sentinel
    40 
    41 <parameter>(pl-sentinel)</parameter>
    42 
    43 gets and sets the sentinel to be needed by constructors.
    44 Default is '(), so that the routines work for lists as well.
    45 Mostly used in constructors.
    46 
    47 ==== pl-check-sentinel?
    48 
    49 <procedure>(pl-check-sentinel?)</procedure>
    50 <procedure>(pl-check-sentinel? pl)</procedure>
    51 
    52 checks if pl's sentinel is equal to (pl-sentinel)
    53 
    54 
    55 ==== pl-change-sentinel
    56 
    57 <procedure>(pl-change-sentinel new-sentinel)</procedure>
    58 <procedure>(pl-change-sentinel new-sentinel pl)</procedure>
    59 
    60 changes pl's sentinel
     7of ordinary lists. They can be considered as parametrized (or
     8tagged) lists, where the parameter (or tag) is stored in the sentinel of a
     9dotted list. In such a naive approch, we are faced with two problems.
     10
     11First, since dotted lists differ from lists only insofor, as their
     12sentinels might be arbitrary atoms instead of the empty list. In other
     13words, a dotted list is either a pair or an atom. But since an atom is
     14simply not a pair, everything is a pseudolist, in particular, a list is
     15one. Hence, there is no meaningfull predicate for dotted lists.
     16
     17Second, there is an efficency problem: to get a handle to the sentinel,
     18we have to traverse the whole dotted list. This is not acceptable, if,
     19for example, the parameter is a type predicate to check the type of
     20items to be put into the dotted list. Ok, as in previous versions of
     21this module, we can put the sentinel into a parameter, but this alone
     22doesn't help much, if different parameters are used simultaneously.
     23
     24This module offers a simple solution to both problems: Make the dotted
     25list callable, in other words, put it into a closure and acces the items
     26as well as the sentinel -- and the length for that matter -- via calls
     27to that closure, e.g. (pls i), where i is an index.
     28
     29Note, that most procedures are implemented in a curried and uncurried
     30form, but only the latter is described in detail in the documentation.
     31The former can be used in map and friends.
     32
     33Note also, that the order or arguments of all procedures is consistent:
     34The pseudolist argument(s) are always last, other procedures first.
     35
     36=== API
     37
     38==== pl-parameter
     39 
     40<parameter>(pl-parameter)</parameter>
     41
     42<parameter>(pl-parameter new)</parameter>
     43
     44returns or resets the sentinel of a pseudolist, initially '()
     45
     46==== pl-checker
     47 
     48<procedure>(pl-checker ok? arg)</procedure>
     49
     50<procedure>(pl-checker ok?)</procedure>
     51
     52type constructor: wrap the predicate ok? into a unary procedure,
     53which returns its argument unchanged, if only it passes the ok? test.
     54An uncurried version is given as well
     55
     56==== pl-checker?
     57 
     58<procedure>(pl-checker? xpr)</procedure>
     59
     60type predicate. Used to check if the tag can be used to check all items.
    6161
    6262==== pl
    63 
     63 
    6464<procedure>(pl . args)</procedure>
    6565
    66 creates a pseudolist, with sentinel from (pl-sentinel).
     66constructor: creates a pseudolist with sentinel tag from pl-parameter
     67and items from args, encapsulated into a closure, which, when called with an
     68index, returns the argument at that index, or, when called with -1,
     69returns the length of args.
     70
     71==== pl?
     72 
     73<procedure>(pl? xpr)</procedure>
     74
     75type predicate
    6776
    6877==== pl-maker
     78 
     79<procedure>(pl-maker len fill)</procedure>
    6980
    7081<procedure>(pl-maker len)</procedure>
    71 <procedure>(pl-maker len fill)</procedure>
    72 
    73 creates a pseudolist of length len with sentinel from (pl-sentinel)
    74 and items fill, which is (pl-sentinel) if not given.
     82
     83creates a pseudolist of length len with sentinel (pl-parameter),
     84items fill or (pl-sentinel), if fill is not given
     85
     86==== pl-at
     87 
     88<procedure>(pl-at k pls)</procedure>
     89
     90<procedure>(pl-at k)</procedure>
     91
     92returns the kth item of pls
     93
     94==== pl-set!
     95 
     96<procedure>(pl-set! k val pls)</procedure>
     97
     98sets the kth item of pls to val
     99
     100==== pl-length
     101 
     102<procedure>(pl-length pls)</procedure>
     103
     104returns the length of the pseudolist pls
     105
     106==== pl-null?
     107 
     108<procedure>(pl-null? xpr)</procedure>
     109
     110checks, if no items are stored in the pseudolist xpr
     111
     112==== pl-head
     113 
     114<procedure>(pl-head pls)</procedure>
     115
     116returns the list part of the pseudolist pls
     117
     118==== pl-tail
     119 
     120<procedure>(pl-tail pls)</procedure>
     121
     122returns the sentinel of the pseudolist pls
     123
     124==== pl-data
     125 
     126<procedure>(pl-data pls)</procedure>
     127
     128returns the dotted list underlying the pseudolist pls
     129
     130==== pl-cons
     131 
     132<procedure>(pl-cons x pls)</procedure>
     133
     134<procedure>(pl-cons x)</procedure>
     135
     136adds the item x to the front of the pseudolist pls
     137
     138==== pl-car
     139 
     140<procedure>(pl-car pls)</procedure>
     141
     142returns the first item of the pseudolist pls
     143
     144==== pl-cdr
     145 
     146<procedure>(pl-cdr pls)</procedure>
     147
     148returns a new pseudolist removing the first item of pls
     149
     150==== pl-of?
     151 
     152<procedure>(pl-of? tag . preds)</procedure>
     153
     154creates a unary predicate, which tests, if its argument is a
     155pseudolist with parameter tag, whose items pass all the predicates preds
    75156
    76157==== pl-iterate
    77 
    78 <procedure>(pl-iterate fn k)</procedure>
    79 <procedure>(pl-iterate fn k init)</procedure>
    80 
    81 creates a pseudolist with sentinel from (pl-sentinel),
    82 applying fn to init recursively k times.
    83 
    84 ==== pl?
    85 
    86 <procedure>(pl? xpr)</procedure>
    87 
    88 type predicate. Note that everything is a pseudolist!
    89 
    90 ==== pl-of?
    91 
    92 <procedure>(pl-of? . preds)</procedure>
    93 
    94 returns a unary predicate, which tests, if its argument is
    95 passed by each predicate in preds.
    96 
    97 ==== pl-null?
    98 
    99 <procedure>(pl-null? xpr)</procedure>
    100 
    101 not a pair.
    102 
    103 ==== pl-length
    104 
    105 <procedure>(pl-length pl)</procedure>
    106 
    107 length of a pseudolist. The sentinel is not counted.
    108 
    109 ==== pl-at
    110 
    111 <procedure>(pl-at k)</procedure>
    112 <procedure>(pl-at k pl)</procedure>
    113 
    114 returns the kth item of pl.
    115 
    116 ==== pl-head
    117 
    118 <procedure>(pl-head pl)</procedure>
    119 
    120 returns the list of items with pl's sentinel stripped.
     158 
     159<procedure>(pl-iterate fn times init)</procedure>
     160
     161<procedure>(pl-iterate fn times)</procedure>
     162
     163creates a pseudolist with sentinel (pl-parameter) applying fn
     164to init recursively k times
    121165
    122166==== pl-drop
     167 
     168<procedure>(pl-drop n pls)</procedure>
    123169
    124170<procedure>(pl-drop n)</procedure>
    125 <procedure>(pl-drop n pl)</procedure>
    126 
    127 returns the tail of pl with the sentinel kept removing
    128 all head items with index less than n.
     171
     172returns a new pseudolist removing the first n items of the pseudolist pls
    129173
    130174==== pl-drop-while
     175 
     176<procedure>(pl-drop-while ok? pls)</procedure>
    131177
    132178<procedure>(pl-drop-while ok?)</procedure>
    133 <procedure>(pl-drop-while ok? pl)</procedure>
    134 
    135 returns the tail pseudolist of pl with sentinel kept starting
    136 with the first item that does not pass the ok? test.
     179
     180returns the tail of pls starting with the first item
     181that does not pass the ok? test
    137182
    138183==== pl-take
     184 
     185<procedure>(pl-take n pls)</procedure>
    139186
    140187<procedure>(pl-take n)</procedure>
    141 <procedure>(pl-take n pl)</procedure>
    142 
    143 returns the head pseudolist of pl with sentinel kept
    144 up to but excluding index n, where n is less than or equal
    145 to pl's pl-length.
     188
     189returns a new pseudolist consisting of the first n items of
     190the pseudolist pls, keeping the sentinel
    146191
    147192==== pl-take-while
     193 
     194<procedure>(pl-take-while ok? pls)</procedure>
    148195
    149196<procedure>(pl-take-while ok?)</procedure>
    150 <procedure>(pl-take-while ok? pl)</procedure>
    151 
    152 returns the head pseudolist of pl with sentinel kept consisting
    153 of items until the first doesn't pass the ok? test.
     197
     198returns the sublist of pls consisting of items
     199until the first item doesn't pass the ok? test.
     200
     201==== pl-reverse
     202 
     203<procedure>(pl-reverse pl)</procedure>
     204
     205reverses its pseudolist argument to a new pseudolist
     206with same sentinel
    154207
    155208==== pl-map
    156 
    157 <procedure>(pl-map fn)</procedure>
    158 <procedure>(pl-map fn . pls)</procedure>
    159 
    160 maps fn over the pseudolists pls, returning a new pseudolist
    161 with sentinel from the first pl with minimal length, applying
    162 fn successively to the list of car items up to the first list
    163 containing a pl-null item.
    164 This is R7RS-logic contrary to R5RS.
     209 
     210<procedure>(pl-map fn . plss)</procedure>
     211
     212maps fn over the pseudolists plss as long as none of the items is
     213pl-null? and returns a new pseudolist if all sentinels are equal.
     214Note, that this is R7RS-, not R5RS-logic.
    165215
    166216==== pl-for-each
    167 
    168 <procedure>(pl-for-each fn pl . pls)</procedure>
    169 
    170 applies fn to successive cars of pl . pls as long as none
    171 of them is pl-null?
    172 This is R7RS-logic contrary to R5RS.
     217 
     218<procedure>(pl-for-each fn pls . plss)</procedure>
     219
     220applies fn over the pseudolists (cons pls plss)
     221stops if one of the items is pl-null?
     222Note, that this is R7RS-, not R5RS-logic
     223
     224==== pl-memp
     225 
     226<procedure>(pl-memp ok? pls)</procedure>
     227
     228<procedure>(pl-memp ok?)</procedure>
     229
     230returns the subpseudolist starting at the first
     231item which passes the ok? test, keeping ps's sentinel.
     232Returns #f if no item passes the ok? test
     233
     234==== pl-memq
     235 
     236<procedure>(pl-memq x pls)</procedure>
     237
     238<procedure>(pl-memq x)</procedure>
     239
     240same as (pl-memp (cut eq? <> x) pls)
     241
     242==== pl-memv
     243 
     244<procedure>(pl-memv x pls)</procedure>
     245
     246<procedure>(pl-memv x)</procedure>
     247
     248same as (pl-memp (cut eqv? <> x) pls)
     249
     250==== pl-member
     251 
     252<procedure>(pl-member x pls)</procedure>
     253
     254<procedure>(pl-member x)</procedure>
     255
     256same as (pl-memp (cut equal? <> x) pls)
    173257
    174258==== pl-index
     259 
     260<procedure>(pl-index ok? pls)</procedure>
    175261
    176262<procedure>(pl-index ok?)</procedure>
    177 <procedure>(pl-index ok? pl)</procedure>
    178263
    179264returns the index of the first item passing
    180 the ok? test, -1 otherwise.
     265the ok? test, -1 otherwise
    181266
    182267==== pl-filter
     268 
     269<procedure>(pl-filter ok? pls)</procedure>
    183270
    184271<procedure>(pl-filter ok?)</procedure>
    185 <procedure>(pl-filter ok? pl)</procedure>
    186 
    187 returns two values, the sublist of pl consisting of all items
    188 passing or not passing the ok? predicate respectively.
    189 The sentinel is kept in both values.
    190 
    191 ==== pl-reverse
    192 
    193 <procedure>(pl-reverse  pl)</procedure>
    194 
    195 reverses its pseudolist argument, keeping the sentinel.
     272
     273filters a pseudolist by means of a predicate ok?
     274returning two new pseudolists, those of items of pls
     275passing the ok? test, and those that don't
    196276
    197277==== pl-append
    198 
    199 <procedure>(pl-append pl . pls)</procedure>
    200 
    201 appends all argument pseudolists to a new pseudolist
    202 with sentinel from the last pseudolist argument.
    203 
    204 ==== pl-memp
    205 
    206 <procedure>(pl-memp ok?)</procedure>
    207 <procedure>(pl-memp ok? pl)</procedure>
    208 
    209 returns the sublist starting at the first
    210 item which passes the ok? test. The sentinel is preserved.
    211 If no item passes the ok? test, #f is returned.
    212 
    213 ==== pl-member
    214 
    215 <procedure>(pl-member x)</procedure>
    216 <procedure>(pl-member x pl)</procedure>
    217 
    218 same as (pl-memp (cut equal? <> x) pl).
    219 
    220 ==== pl-memq
    221 
    222 <procedure>(pl-memq x)</procedure>
    223 <procedure>(pl-memq x pl)</procedure>
    224 
    225 same as (pl-memp (cut eq? <> x) pl).
    226 
    227 ==== pl-memv
    228 
    229 <procedure>(pl-memv x)</procedure>
    230 <procedure>(pl-memv x pl)</procedure>
    231 
    232 same as (pl-memp (cut eqv? <> x) pl).
     278 
     279<procedure>(pl-append pls . plss)</procedure>
     280
     281appends all argument pseudolist, provided their tags are
     282all equal
    233283
    234284==== pl-fold-right
     285 
     286<procedure>(pl-fold-right op init pls)</procedure>
    235287
    236288<procedure>(pl-fold-right op init)</procedure>
    237 <procedure>(pl-fold-right op init pl)</procedure>
    238 
    239 folds pl from the right with binary operation op
    240 and starting value init.
     289
     290folds pls from the right with binary operation op
     291and starting value init
    241292
    242293==== pl-fold-right0
     294 
     295<procedure>(pl-fold-right0 op pls)</procedure>
    243296
    244297<procedure>(pl-fold-right0 op)</procedure>
    245 <procedure>(pl-fold-right0 op pl)</procedure>
    246 
    247 folds (cdr pl) from the right with binary operation op
    248 and starting value (car pl).
     298
     299folds (pl-cdr pls) from the right with binary operation op
     300and starting value (pl-car pls)
    249301
    250302==== pl-fold-left
     303 
     304<procedure>(pl-fold-left op init pls)</procedure>
    251305
    252306<procedure>(pl-fold-left op init)</procedure>
    253 <procedure>(pl-fold-left op init pl)</procedure>
    254 
    255 folds pl from the left with binary operation op
    256 and starting value init.
     307
     308folds pls from the left with binary operation op
     309and starting value init
    257310
    258311==== pl-fold-left0
     312 
     313<procedure>(pl-fold-left0 op pls)</procedure>
    259314
    260315<procedure>(pl-fold-left0 op)</procedure>
    261 <procedure>(pl-fold-left0 op pl)</procedure>
    262 
    263 folds (cdr pl) from the left with binary operation op
    264 and starting value (car pl).
     316
     317folds (pl-cdr pls) from the left with binary operation op
     318and starting value (pl-car pls)
    265319
    266320==== pl-adjoin
    267 
    268 <procedure>(adjoin obj)</procedure>
    269 <procedure>(adjoin obj pl)</procedure>
    270 
    271 adds obj to the pseudolist pl, provided obj is not an item of pl.
    272 As always, the sentinel is kept.
     321 
     322<procedure> (pl-adjoin obj pls)</procedure>
     323
     324<procedure> (pl-adjoin obj)</procedure>
     325
     326add obj to the front of pls only if it is not already a member of pls
    273327
    274328==== pl-remove-dups
    275 
    276 <procedure>(pl-remove-dups pl)</procedure>
    277 
    278 removes all duplicates of pl.
     329 
     330<procedure>(pl-remove-dups pls)</procedure>
     331
     332removes the duplicates in the pseudolist pls
     333
     334==== pl-flat?
     335 
     336<procedure>(pl-flat? xpr)</procedure>
     337
     338is xpr a flat pseudolist, i.e. not containing other pseudolists
    279339
    280340==== pl-flatten
    281 
     341 
    282342<procedure>(pl-flatten pl-tree)</procedure>
    283343
    284 transforms a nested pseudolist to a flat pseudolist
    285 with sentinel taken from the depth zero pseudolist.
     344flattens the nested pseudolist pl-tree to a pseudolist,
     345i.e. splices the pseudolist items of pl-tree into pl-tree
     346provided all parameters are equal
    286347
    287348==== pl-collect
    288 
    289 <macro>(pl-collect item-xpr (var pl ok-xpr ...) ....)</macro>
    290 
    291 creates a new list by binding var to each element
    292 of the pseudolist pl in sequence, and if it passes the checks,
    293 ok-xpr ..., inserts the value of item-xpr into the resulting list.
    294 The qualifieres, (var pl ok-xpr ...), are processed
     349 
     350<macro>(pl-collect item-xpr (var pls ok-xpr ...))</macro>
     351
     352<macro>(pl-collect item-xpr (var pls ok-xpr ...) (var1 pls1 ok-xpr1 ...) ...)</macro>
     353
     354creates a new pseudolist by binding var to each element
     355of the pseudolist pls in sequence, and if it passes the checks,
     356ok-xpr ..., inserts the value of xpr into the resulting pseudolist.
     357The qualifieres, (var pls ok-xpr ...), are processed
    295358sequentially from left to right, so that filters of a
    296359qualifier have access to the variables of qualifiers
    297360to its left.
    298 The sentinel of the result is that of the first pseudolist argument.
    299 
    300 === Dependencies
    301 
    302 none
     361
     362==== pseudolists
     363 
     364<procedure>(pseudolists)</procedure>
     365
     366<procedure>(pseudolists sym)</procedure>
     367
     368with sym: documentation of exported symbol
     369without sym: list of exported symbols
    303370
    304371=== Examples
     
    308375(import pseudolists)
    309376
    310 ((pl-of? symbol?) '(a b . c)) ;-> #t
    311 (pl-iterate add1 5 #f 0) ;-> '(0 1 2 3 4 . #f)
    312 
    313 (pl-length '(0 1 2 3 . 4)) ;-> 4
    314 (pl-head '(0 . 1)) ;-> '(0)
    315 (pl-at 2 '(0 1 2 3 . #f)) ;-> 2
    316 (condition-case (pl-at 0 1)
    317   ((exn) #f)) ;-> #f
    318 
    319 (pl-index odd? '(0 2 4 . 1)) ;-> -1
    320 (pl-drop 0 1) ;-> 1
    321 (pl-drop 2 '(0 1 2 3 . #f)) ;-> '(2 3 . #f)
    322 (pl-take-while negative? '(1 3 2 4 . #f)) ;-> #f
    323 (pl-take 2 '(0 1 2 3 . #f)) ;-> '(0 1 . #f))
    324 
    325 (pl-filter odd? '(0 1 2 3 . 4)) ;-> '(1 3 . 4)
    326 (pl-map add1 '(0 1 2 3 . 4)) ;-> '(1 2 3 4 . 4)
    327 (pl-map add1 '(0 1 2 3)) ;-> '(1 2 3 4)
    328 (pl-map add1 #f) ;-> #f
    329 
    330 (pl-reverse '(0 1 2 3 . 4)) ;-> '(3 2 1 0 . 4)
    331 
    332 (pl-append '(0 1 . #t) '(2 3 . #t) '(4 5 . #t)) ;-> '(0 1 2 3 4 5 . #t)
    333 (pl-append '(0 1) '(2 3) #f) ;-> '(0 1 2 3 . #f)
    334 (pl-adjoin 2 '(0 1 2 3 . #f)) ;-> '(0 1 2 3 . #f)
    335 (pl-adjoin 1 '()) ;-> '(1)
    336 (pl-remove-dups '(0 1 2 3 2 . 2)) ;-> '(0 1 3 2 . 2)
    337 
    338 (pl-flatten '(1 (2 3) . #t)) ;-> '(1 2 3 . #t)
    339 (pl-flatten '(1 (2 (3 . #f) . #t) . #f)) ;-> '(1 2 3 . #f)
    340 (pl-flatten #f) ;-> #f
    341 
    342 (pl-collect (add1 x) (x '(0 1 2 3 . #t))) ; map
    343   ;-> '(1 2 3 4 . #t)
    344 (pl-collect (add1 x) (x '(0 1 2 3))) ; map
    345   ;-> '(1 2 3 4)
    346 (pl-collect x (x '(0 1 2 3 4 5) (odd? x))) ; filter
    347   ;-> '(1 3 5)
    348 (pl-collect (* 10 n)
    349             (n '(0 1 2 3 4 5) (positive? n) (even? n)))
    350   ;-> '(20 40)
    351 (pl-collect (list c k)
    352             (c '(A B C)) (k '(1 2 3 4)))
    353   ;-> '((A 1) (A 2) (A 3) (A 4)
    354   ;     (B 1) (B 2) (B 3) (B 4)
    355   ;     (C 1) (C 2) (C 3) (C 4))
    356 (pl-collect (list c k)
    357             (c '(A B C . #f)) (k '(1 2 3 4 . #t)))
    358   ;-> '((A 1) (A 2) (A 3) (A 4)
    359   ;     (B 1) (B 2) (B 3) (B 4)
    360   ;     (C 1) (C 2) (C 3) (C 4) . #f)
     377'(basic?
     378   parameter
     379   (pl-parameter 0)
     380   pls
     381   (pl 0 1 2 3)
     382   mls
     383   (pl-maker 5)
     384   ils
     385   (pl-iterate add1 5 1))
     386
     387(pl-parameter)
     388;-> 0
     389
     390(pl-data pls)
     391;-> (quote (0 1 2 3 . 0))
     392
     393(pl-data mls)
     394;-> (quote (0 0 0 0 0 . 0))
     395
     396(pl-data ils)
     397;-> (quote (1 2 3 4 5 . 0))
     398
     399(pl? pls)
     400;-> #t
     401
     402(pl? mls)
     403;-> #t
     404
     405(pl? ils)
     406;-> #t
     407
     408(pl? '(0 1 2 3))
     409;-> #f
     410
     411((pl-of? 0) pls)
     412;-> #t
     413
     414((pl-of? '()) mls)
     415;-> #f
     416
     417(pl-car mls)
     418;-> 0
     419
     420(pl-at 3 mls)
     421;-> 0
     422
     423(pl-at 3 pls)
     424;-> 3
     425
     426(pls 3)
     427;-> 3
     428
     429(pl-head pls)
     430;-> (quote (0 1 2 3))
     431
     432(pls)
     433;-> (quote (0 1 2 3))
     434
     435(pl-tail pls)
     436;-> 0
     437
     438(pl-data pls)
     439;-> (quote (0 1 2 3 . 0))
     440
     441(pl-data mls)
     442;-> (quote (0 0 0 0 0 . 0))
     443
     444(pl-tail mls)
     445;-> 0
     446
     447(pl-data ils)
     448;-> (quote (1 2 3 4 5 . 0))
     449
     450(ils)
     451;-> (quote (1 2 3 4 5))
     452
     453(pl-tail ils)
     454;-> 0
     455
     456(pl-head (pl-cons -1 pls))
     457;-> (quote (-1 0 1 2 3))
     458
     459(pl-head (pl-cdr pls))
     460;-> (quote (1 2 3))
     461
     462(pl-set! 0 1 mls)
     463;-> (void)
     464
     465(pl-at 0 mls)
     466;-> 1
     467
     468(pl-set! 1 2 mls)
     469;-> (void)
     470
     471(pl-at 1 mls)
     472;-> 2
     473
     474(mls 1)
     475;-> 2
     476
     477(mls 2 3)
     478;-> (void)
     479
     480(mls 2)
     481;-> 3
     482
     483(mls)
     484;-> (quote (1 2 3 0 0))
     485
     486(pl-head mls)
     487;-> (quote (1 2 3 0 0))
     488
     489(newline)
     490
     491'(checked? parameter (pl-parameter (pl-checker integer?)) pls (pl 0 1 2 3))
     492
     493(pl-tail pls)
     494;-> (pl-parameter)
     495
     496(pl-head pls)
     497;-> (quote (0 1 2 3))
     498
     499(condition-case (pl 0 1 #f 3) ((exn) #f))
     500;-> #f
     501
     502(condition-case (pl-set! 0 #f pls) ((exn) #f))
     503;-> #f
     504
     505(pl-set! 0 100 pls)
     506;-> (void)
     507
     508(pl-car pls)
     509;-> 100
     510
     511(pls 0 10)
     512;-> (void)
     513
     514(pls 0)
     515;-> 10
     516
     517(newline)
     518
     519'(ops? parameter
     520       (pl-parameter 0)
     521       pls
     522       (pl 0 1 2 3)
     523       mls
     524       (pl-maker 5)
     525       ils
     526       (pl-iterate add1 5 1)
     527       ii
     528       (pl-iterate add1 5))
     529
     530(pl-parameter)
     531;-> 0
     532
     533(pl-data pls)
     534;-> (quote (0 1 2 3 . 0))
     535
     536(pl-data mls)
     537;-> (quote (0 0 0 0 0 . 0))
     538
     539(pl-data ils)
     540;-> (quote (1 2 3 4 5 . 0))
     541
     542(pl-data (ii 1))
     543;-> (quote (1 2 3 4 5 . 0))
     544
     545(pls)
     546;-> (quote (0 1 2 3))
     547
     548(pl? pls)
     549;-> #t
     550
     551((pl-of? 1) pls)
     552;-> #f
     553
     554((pl-of? 0) pls)
     555;-> #t
     556
     557((pl-of? 0 integer?) pls)
     558;-> #t
     559
     560((pl-of? 0 integer? positive?) pls)
     561;-> #f
     562
     563(pl? '(0 1 2 3 . 0))
     564;-> #f
     565
     566(pl-at 0 pls)
     567;-> 0
     568
     569(pl-at 3 pls)
     570;-> 3
     571
     572(pl-head (pl-map add1 pls))
     573;-> (quote (1 2 3 4))
     574
     575(pl-head (pl-map + pls pls))
     576;-> (quote (0 2 4 6))
     577
     578(pl-index negative? pls)
     579;-> -1
     580
     581(pl-index odd? pls)
     582;-> 1
     583
     584(pl-head (pl-filter odd? pls))
     585;-> (quote (1 3))
     586
     587(receive (_ pl-no) (pl-filter odd? pls) (pl-head pl-no))
     588;-> (quote (0 2))
     589
     590(pl-head (pl-append pls ils))
     591;-> (quote (0 1 2 3 1 2 3 4 5))
     592
     593(pl-head (pl-append pls ils mls))
     594;-> (quote (0 1 2 3 1 2 3 4 5 0 0 0 0 0))
     595
     596(pl-set! 2 20 pls)
     597;-> (void)
     598
     599(pl-head pls)
     600;-> (quote (0 1 20 3))
     601
     602(pl-length pls)
     603;-> 4
     604
     605(pl-tail pls)
     606;-> 0
     607
     608(pl-at 2 pls)
     609;-> 20
     610
     611(pl-head pls)
     612;-> (quote (0 1 20 3))
     613
     614(pl-head (pl-drop 3 pls))
     615;-> (quote (3))
     616
     617(pl-head (pl-drop-while zero? pls))
     618;-> (quote (1 20 3))
     619
     620(pl-head (pl-drop-while (cut <= <> 10) pls))
     621;-> (quote (20 3))
     622
     623(pl-head (pl-take 3 pls))
     624;-> (quote (0 1 20))
     625
     626(pl-head (pl-take-while (cut <= <> 10) pls))
     627;-> (quote (0 1))
     628
     629(pl-head (pl-reverse pls))
     630;-> (quote (3 20 1 0))
     631
     632(pl-head (pl-memp (lambda (x) (> x 10)) pls))
     633;-> (quote (20 3))
     634
     635(pl-head mls)
     636;-> (quote (0 0 0 0 0))
     637
     638((pl-of? 0 zero?) mls)
     639;-> #t
     640
     641(pl-length mls)
     642;-> 5
     643
     644(pl-set! 2 20 mls)
     645;-> (void)
     646
     647(pl-head mls)
     648;-> (quote (0 0 20 0 0))
     649
     650(pl-tail mls)
     651;-> 0
     652
     653(pl? mls)
     654;-> #t
     655
     656(pl-head (pl-maker 5 1))
     657;-> (quote (1 1 1 1 1))
     658
     659(pl? ils)
     660;-> #t
     661
     662(pl-head ils)
     663;-> (quote (1 2 3 4 5))
     664
     665(pl-tail ils)
     666;-> 0
     667
     668(pl-at 2 ils)
     669;-> 3
     670
     671(pl? ii)
     672;-> #f
     673
     674(pl? (ii 1))
     675;-> #t
     676
     677(pl-length (ii 1))
     678;-> 5
     679
     680(pl-at 3 (ii 1))
     681;-> 4
     682
     683(pl-head (pl-map * (pl 0 1 2 3) (pl 10 20)))
     684;-> (quote (0 20))
     685
     686(condition-case
     687  (pl-map
     688    +
     689    (parameterize ((pl-parameter #f)) (pl 0 1 2 3))
     690    (parameterize ((pl-parameter #t)) (pl 0 1 2 3)))
     691  ((exn) #f))
     692;-> #f
     693
     694(newline)
     695
     696'(new-ops? parameter (pl-parameter 0) pls (pl 0 1 2 3 4 5))
     697
     698(pl-data pls)
     699;-> (quote (0 1 2 3 4 5 . 0))
     700
     701(pl-fold-right + 0 pls)
     702;-> 15
     703
     704(pl-fold-left + 0 pls)
     705;-> 15
     706
     707(pl-fold-right0 + pls)
     708;-> 15
     709
     710(pl-fold-left0 + pls)
     711;-> 15
     712
     713(pl-head (pl-fold-right pl-cons (pl) pls))
     714;-> (quote (0 1 2 3 4 5))
     715
     716(pl-fold-right cons '() pls)
     717;-> (quote (0 1 2 3 4 5))
     718
     719(pl-head (pl-adjoin 3 pls))
     720;-> (quote (0 1 2 3 4 5))
     721
     722(pl-head (pl-adjoin #f pls))
     723;-> (quote (#f 0 1 2 3 4 5))
     724
     725(pl-head (pl-remove-dups pls))
     726;-> (quote (0 1 2 3 4 5))
     727
     728(pl-head (pl-remove-dups (pl 0 1 0 1 0 1)))
     729;-> (quote (0 1))
     730
     731(pl-flat? pls)
     732;-> #t
     733
     734(pl-flat? (pl 0 (pl 1 (pl 2))))
     735;-> #f
     736
     737(pl-head (pl-flatten (pl 1 2 3)))
     738;-> (quote (1 2 3))
     739
     740(pl-head (pl-flatten (pl 1 '(2 3))))
     741;-> (quote (1 (2 3)))
     742
     743(pl-head (pl-flatten (pl 1 (pl 2 3))))
     744;-> (quote (1 2 3))
     745
     746(pl-head (pl-flatten (pl 1 (pl 2 3) (pl 4 5) 6)))
     747;-> (quote (1 2 3 4 5 6))
     748
     749(pl-head (pl-flatten (pl 1 (pl 2 (pl 3)))))
     750;-> (quote (1 2 3))
     751
     752(pl-head (pl-flatten (pl 1 (pl 2 (pl 3 (pl 4)) 5) 6)))
     753;-> (quote (1 2 3 4 5 6))
     754
     755(condition-case
     756  (pl-flatten (pl 1 (parameterize ((pl-parameter #f)) (pl 2 3))))
     757  ((exn) #f))
     758;-> #f
     759
     760(newline)
     761
     762(pl-data (pl-collect (add1 x) (x (pl 0 1 2 3))))
     763;-> (quote (1 2 3 4 . 0))
     764
     765(pl-data (pl-collect (add1 x) (x (pl 0 1 2 3))))
     766;-> (quote (1 2 3 4 . 0))
     767
     768(pl-data (pl-collect x (x (pl 0 1 2 3 4 5) (odd? x))))
     769;-> (quote (1 3 5 . 0))
     770
     771(pl-data (pl-collect x (x (pl 0 1 2 3 4 5) (odd? x))))
     772;-> (quote (1 3 5 . 0))
     773
     774(pl-data (pl-collect (* 10 n) (n (pl 0 1 2 3 4 5) (positive? n) (even? n))))
     775;-> (quote (20 40 . 0))
     776
     777(pl-data (pl-collect (list c k) (c (pl 'A 'B 'C)) (k (pl 1 2 3 4))))
     778;-> (quote ((A 1) (A 2) (A 3) (A 4) (B 1) (B 2) (B 3) (B 4) (C 1) (C 2) (C 3) (C 4) . 0))
     779
     780(newline)
    361781
    362782</enscript>
    363783
     784
     785== Requirements
     786
     787None
     788
    364789== Last update
    365790
    366 Mar 24, 2020
     791Feb 15, 2021
    367792
    368793== Author
    369794
    370 [[/users/juergen-lorenz|Juergen Lorenz]]
     795Juergen Lorenz
    371796
    372797== License
    373798
    374  Copyright (c) 2020, Juergen Lorenz
    375  All rights reserved.
    376 
    377  Redistribution and use in source and binary forms, with or without
    378  modification, are permitted provided that the following conditions are
    379  met:
    380  
    381  Redistributions of source code must retain the above copyright
    382  notice, this list of conditions and the following disclaimer.
    383  
    384  Redistributions in binary form must reproduce the above copyright
    385  notice, this list of conditions and the following disclaimer in the
    386  documentation and/or other materials provided with the distribution.
    387  Neither the name of the author nor the names of its contributors may be
    388  used to endorse or promote products derived from this software without
    389  specific prior written permission.
    390    
    391  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
    392  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    393  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
    394  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    395  HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    396  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
    397  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    398  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    399  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    400  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    401  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    402 
     799Copyright (c) 2013-2021 , Juergen Lorenz, ju (at) jugilo (dot) de
     800All rights reserved.
     801
     802Redistribution and use in source and binary forms, with or without
     803modification, are permitted provided that the following conditions are
     804met:
     805
     806Redistributions of source code must retain the above copyright
     807notice, this list of conditions and the following disclaimer.
     808
     809Redistributions in binary form must reproduce the above copyright
     810notice, this list of conditions and the following disclaimer in the
     811documentation and/or other materials provided with the distribution.
     812Neither the name of the author nor the names of its contributors may be
     813used to endorse or promote products derived from this software without
     814specific prior written permission.
     815 
     816THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
     817IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     818TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     819PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     820HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     821SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
     822TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     823PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     824LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     825NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     826SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     827
     828== Version history
    403829== Version History
     830; 3.0 : pseudolists as parametrized (or tagged) lists
    404831; 2.0 : sentinels kept, not stripped
    405832; 1.4 : pl-maker added
     
    409836; 1.0 : initial import
    410837
     838
Note: See TracChangeset for help on using the changeset viewer.