Changeset 37771 in project


Ignore:
Timestamp:
07/08/19 12:45:07 (4 months ago)
Author:
juergen
Message:

pseudolists-1.3 docu

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/5/pseudolists

    r37761 r37771  
    1010
    1111Pseudolists differ from lists insofor, as their sentinels might be
    12 arbitrary atoms instead of the empty lists. In other words, a
     12arbitrary atoms instead of the empty list. In other words, a
    1313pseudolist is either a pair or an atom. But since an atom is simply not
    1414a pair, everything is a pseudolist, in particular, a list is one.
     
    1616So the routines of this module have to be written so that they work for
    1717lists as well. For example, this means, that the sentinel doesn't count
    18 in a length routine, and have to be handled in constructors by supplying
    19 an additional argument, a sentinel-option.
    20 
    21 Additional sentinel-option arguments are not provided, if a sub-pseudolist is
    22 constructed, e.g. for filter, member, drop, take. In that case, the sentinel
    23 of the original pseudolist is used.
     18in a length routine.
     19
     20For simplicity, we have arrenged things in such a way, that routines,
     21which create a pseudolist, in fact create a proper list. If you want an
     22atom instead of the empty list as sentinel, simply append this atom to
     23the routine's result.
    2424
    2525Most functions in this module are written in curried and uncurried form.
     
    2929the curried version.
    3030
    31 Note, that the order of arguments is consistent: Sentinel-options come first,
    32 procedures second and pseudolists last.
    33 To conform to this convention, I've changed the syntax of pl-iterate and
    34 pl-for.
     31Note, that the order of arguments is consistent: Procedures come first
     32and pseudolists last.
    3533
    3634=== Module pseudolists
     
    4442routines, the second documentation of the routine with symbol sym.
    4543
    46 ==== pl-maker
    47 
    48 <procedure>(pl-maker opt . args)</procedure>
    49 
    50 constructs a new pseudolist with (sentinel opt).
    51 
    5244==== pl?
    5345
     
    7769==== pl-iterate
    7870
    79 <procedure>(pl-iterate opt fn k)</procedure>
    80 <procedure>(pl-iterate opt fn k init)</procedure>
    81 
    82 creates a pseudolist with (sentinel opt) applying fn to init
    83 recursively k times.
     71<procedure>(pl-iterate fn k)</procedure>
     72<procedure>(pl-iterate fn k init)</procedure>
     73
     74creates a list applying fn to init recursively k times.
    8475
    8576==== pl-at
     
    10798<procedure>(pl-drop n pl)</procedure>
    10899
    109 returns the tail of pl removing all head items
     100returns the tail of pl with the sentinel stripped removing all head items
    110101that pass the ok? test.
    111102
     
    115106<procedure>(pl-drop-while ok? pl)</procedure>
    116107
    117 returns the tail of pl starting with the first item
     108returns the tail of pl with the sentinel stripped starting with the first item
    118109that does not pass the ok? test.
    119110
     
    136127==== pl-map
    137128
    138 <procedure>(pl-map opt fn)</procedure>
    139 <procedure>(pl-map opt fn pl)</procedure>
    140 
    141 maps fn over the pseudolist pl, returning a new pseudolist
    142 with (sentinel opt).
     129<procedure>(pl-map fn)</procedure>
     130<procedure>(pl-map fn pl)</procedure>
     131
     132maps fn over the pseudolist pl, returning a new list.
    143133
    144134==== pl-index
     
    156146
    157147returns the sublist of lst consisting of all items passing the ok?
    158 predicate.
     148predicate. As always, the sentinel is stripped.
    159149
    160150==== pl-reverse
    161151
    162 <procedure>(pl-reverse opt pl)</procedure>
    163 
    164 reverses its pseudolist argument, changing the sentinel
    165 to (sentinel opt).
     152<procedure>(pl-reverse  pl)</procedure>
     153
     154reverses its pseudolist argument, stripping the sentinel.
    166155
    167156==== pl-append
    168157
    169 <procedure>(pl-append opt pl . pls)</procedure>
    170 
    171 appends all argument pseudolists to a new one with (sentinel opt).
     158<procedure>(pl-append pl . pls)</procedure>
     159
     160appends all argument pseudolists to a new list.
    172161
    173162==== pl-memp
     
    176165<procedure>(pl-memp ok? pl)</procedure>
    177166
    178 returns the sub-pseudolist starting at the first
    179 item which passes the ok? test.
     167returns the sublist starting at the first
     168item which passes the ok? test. If no item passes the ok? test,
     169#f is returned.
    180170
    181171==== pl-member
     
    238228
    239229adds obj to the pseudolist pl, provided obj is not an item of lst.
     230As always, the sentinel is stripped.
    240231
    241232==== pl-remove-dups
     
    247238==== pl-flatten
    248239
    249 <procedure>(pl-flatten opt pl-tree)</procedure>
    250 
    251 transforms a nested pseudolist to a flat pseudolist with (sentinel opt).
     240<procedure>(pl-flatten pl-tree)</procedure>
     241
     242transforms a nested pseudolist to a flat list.
    252243
    253244==== pl-collect
    254245
    255 <macro>(pl-collect opt item-xpr (var pl ok-xpr ...) ....)</macro>
    256 
    257 creates a new pseudolist with (sentinel opt) by binding var to each element
     246<macro>(pl-collect item-xpr (var pl ok-xpr ...) ....)</macro>
     247
     248creates a new list by binding var to each element
    258249of the pseudolist pl in sequence, and if it passes the checks,
    259 ok-xpr ..., inserts the value of item-xpr into the resulting (pseudo-) list.
     250ok-xpr ..., inserts the value of item-xpr into the resulting list.
    260251The qualifieres, (var pl ok-xpr ...), are processed
    261252sequentially from left to right, so that filters of a
     
    265256=== Dependencies
    266257
    267 datatype
     258none
    268259
    269260=== Examples
     
    274265
    275266((pl-of? symbol?) '(a b . c)) ;-> #t
    276 (pl-maker (Some-sentinel #f) 0 1 2 3) ;-> '(0 1 2 3 . #f)
    277 (pl-maker (No-sentinel) 0 1 2 3) ;-> '(0 1 2 3)
    278 (pl-iterate (Some-sentienel #f) add1 5 0) ;-> '(0 1 2 3 4 . #f)
     267(pl-iterate add1 5 0) ;-> '(0 1 2 3 4)
    279268
    280269(pl-length '(0 1 2 3 . 4)) ;-> 4
     
    285274
    286275(pl-index odd? '(0 2 4 . 1)) ;-> -1
    287 (pl-drop 0 1) ;-> 1
    288 (pl-drop 2 '(0 1 2 3 . #f)) ;-> '(2 3 . #f)
    289 (pl-take-while negative? '(1 3 2 4 . #f)) ;-> #f
    290 (pl-take 2 '(0 1 2 3 . #f)) ;-> '(0 1 . #f))
    291 
    292 (pl-filter odd? '(0 1 2 3 . 4)) ;-> '(1 3 . 4)
    293 (pl-map add1 (No-sentinel) '(0 1 2 3 . 4)) ;-> '(1 2 3 4)
    294 (pl-map (Some-sentinel 5) add1 '(0 1 2 3 . 4)) ;-> '(1 2 3 4 . 5)
    295 (pl-map (Some-sentinel #f) add1 '(0 1 2 3)) ;-> '(1 2 3 4 . #f)
    296 (pl-map (Some-sentinel #t) add1 #f) ;-> #t
    297 
    298 (pl-reverse (Some-sentinel #f) '(0 1 2 3 . 4)) ;-> '(3 2 1 0 . #f)
    299 (pl-reverse (No-sentinel) '(0 1 2 3 . 4)) ;-> '(3 2 1 0)
    300 
    301 (pl-append (Some-sentinel #f) '(0 1 . #t) '(2 3 . #t) '(4 5 . #t)) ;-> '(0 1 2 3 4 5 . #f)
    302 (pl-append (No-sentinel) '(0 1) '(2 3) #f) ;-> '(0 1 2 3)
    303 (pl-adjoin 2 '(0 1 2 3 . #f)) ;-> '(0 1 2 3 . #f)
     276(pl-drop 0 1) ;-> '()
     277(pl-drop 2 '(0 1 2 3 . #f)) ;-> '(2 3)
     278(pl-take-while negative? '(1 3 2 4 . #f)) ;-> '()
     279(pl-take 2 '(0 1 2 3 . #f)) ;-> '(0 1))
     280
     281(pl-filter odd? '(0 1 2 3 . 4)) ;-> '(1 3)
     282(pl-map add1 '(0 1 2 3 . 4)) ;-> '(1 2 3 4)
     283(pl-map add1 '(0 1 2 3 . 4)) ;-> '(1 2 3 4)
     284(pl-map add1 '(0 1 2 3)) ;-> '(1 2 3 4)
     285(pl-map add1 #f) ;-> '()
     286
     287(pl-reverse '(0 1 2 3 . 4)) ;-> '(3 2 1 0)
     288
     289(pl-append '(0 1 . #t) '(2 3 . #t) '(4 5 . #t)) ;-> '(0 1 2 3 4 5)
     290(pl-append '(0 1) '(2 3) #f) ;-> '(0 1 2 3)
     291(pl-adjoin 2 '(0 1 2 3 . #f)) ;-> '(0 1 2 3)
    304292(pl-adjoin 1 '()) ;-> '(1)
    305 (pl-remove-dups '(0 1 2 3 2 . 2)) ;-> '(0 1 3 2 . 2)
    306 
    307 (pl-flatten (Some-sentinel #f) '(1 (2 3) . #t)) ;-> '(1 2 3 . #f)
    308 (pl-flatten (No-sentinel) '(1 (2 (3 . #f) . #t) . #f)) ;-> '(1 2 3)
    309 (pl-flatten (Some-sentinel #t) #f) ;-> #t
    310 (null? (pl-flatten (No-sentinel) #f) ;-> '()
    311 
    312 (pl-collect (Some-sentinel #f) (add1 x) (x '(0 1 2 3 . #t))) ; map
    313   ;-> '(1 2 3 4 . #f)
    314 (pl-collect (No-sentinel) (add1 x) (x '(0 1 2 3))) ; map
     293(pl-remove-dups '(0 1 2 3 2 . 2)) ;-> '(0 1 3 2)
     294
     295(pl-flatten '(1 (2 3) . #t)) ;-> '(1 2 3)
     296(pl-flatten '(1 (2 (3 . #f) . #t) . #f)) ;-> '(1 2 3)
     297(pl-flatten #f) ;-> '()
     298
     299(pl-collect (add1 x) (x '(0 1 2 3 . #t))) ; map
    315300  ;-> '(1 2 3 4)
    316 (pl-collect (No-sentinel) x (x '(0 1 2 3 4 5) (odd? x))) ; filter
     301(pl-collect (add1 x) (x '(0 1 2 3))) ; map
     302  ;-> '(1 2 3 4)
     303(pl-collect x (x '(0 1 2 3 4 5) (odd? x))) ; filter
    317304  ;-> '(1 3 5)
    318 (pl-collect (Some-sentinel #f) (* 10 n)
     305(pl-collect (* 10 n)
    319306            (n '(0 1 2 3 4 5) (positive? n) (even? n)))
    320   ;-> '(20 40 . #f)
    321 (pl-collect (No-sentinel) (list c k)
     307  ;-> '(20 40)
     308(pl-collect (list c k)
    322309            (c '(A B C)) (k '(1 2 3 4)))
    323310  ;-> '((A 1) (A 2) (A 3) (A 4)
    324311  ;     (B 1) (B 2) (B 3) (B 4)
    325312  ;     (C 1) (C 2) (C 3) (C 4))
    326 (pl-collect (No-sentinel) (list c k)
     313(pl-collect (list c k)
    327314            (c '(A B C . #f)) (k '(1 2 3 4 . #t)))
    328315  ;-> '((A 1) (A 2) (A 3) (A 4)
     
    334321== Last update
    335322
    336 Jul 05, 2019
     323Jul 08, 2019
    337324
    338325== Author
     
    373360== Version History
    374361
     362; 1.3 : sentinel-options removed, all constructors create ordinary lists
    375363; 1.2 : macro pl-for renamed pl-collect
    376364; 1.1 : some sentinel-option arguments added; syntax-change of pl-for and pl-iterate
Note: See TracChangeset for help on using the changeset viewer.