Changeset 38335 in project


Ignore:
Timestamp:
03/24/20 15:57:59 (2 weeks ago)
Author:
juergen
Message:

pseudolists 2.0 docu with sentinels kept

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/5/pseudolists

    r38200 r38335  
    1717lists as well. For example, this means, that the sentinel doesn't count
    1818in a length routine.
    19 
    20 For simplicity, we have arranged things in such a way, that routines,
    21 which create a pseudolist, in fact create a proper list; the exception
    22 is pl-maker. If you want an atom instead of the empty list as sentinel,
    23 simply append this atom to the routine's result with (apply pl-maker
    24 atom lst).
    2519
    2620Most functions in this module are written in curried and uncurried form.
     
    4337routines, the second documentation of the routine with symbol sym.
    4438
     39==== pl-sentinel
     40
     41<parameter>(pl-sentinel)</parameter>
     42
     43gets and sets the sentinel to be needed by constructors.
     44Default is '(), so that the routines work for lists as well.
     45Mostly used in constructors.
     46
     47==== pl-check-sentinel?
     48
     49<procedure>(pl-check-sentinel?)</procedure>
     50<procedure>(pl-check-sentinel? pl)</procedure>
     51
     52checks 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
     60changes pl's sentinel
     61
     62==== pl
     63
     64<procedure>(pl . args)</procedure>
     65
     66creates a pseudolist, with sentinel from (pl-sentinel).
     67
    4568==== pl-maker
    4669
    47 <procedure>(pl-maker sentinel . args)</procedure>
    48 
    49 creates a pseudolist with given sentinel from the rest argument
     70<procedure>(pl-maker len)</procedure>
     71<procedure>(pl-maker len fill)</procedure>
     72
     73creates a pseudolist of length len with sentinel from (pl-sentinel)
     74and items fill, which is (pl-sentinel) if not given.
     75
     76==== pl-iterate
     77
     78<procedure>(pl-iterate fn k)</procedure>
     79<procedure>(pl-iterate fn k init)</procedure>
     80
     81creates a pseudolist with sentinel from (pl-sentinel),
     82applying fn to init recursively k times.
    5083
    5184==== pl?
     
    74107length of a pseudolist. The sentinel is not counted.
    75108
    76 ==== pl-iterate
    77 
    78 <procedure>(pl-iterate fn k)</procedure>
    79 <procedure>(pl-iterate fn k init)</procedure>
    80 
    81 creates a list applying fn to init recursively k times.
    82 
    83109==== pl-at
    84110
     
    94120returns the list of items with pl's sentinel stripped.
    95121
    96 ==== pl-sentinel
    97 
    98 <procedure>(pl-sentinel pl)</procedure>
    99 
    100 returns the sentinel of pl.
    101 
    102122==== pl-drop
    103123
     
    105125<procedure>(pl-drop n pl)</procedure>
    106126
    107 returns the tail of pl with the sentinel stripped removing all head items
    108 that pass the ok? test.
     127returns the tail of pl with the sentinel kept removing
     128all head items with index less than n.
    109129
    110130==== pl-drop-while
     
    113133<procedure>(pl-drop-while ok? pl)</procedure>
    114134
    115 returns the tail of pl with the sentinel stripped starting with the first item
    116 that does not pass the ok? test.
     135returns the tail pseudolist of pl with sentinel kept starting
     136with the first item that does not pass the ok? test.
    117137
    118138==== pl-take
     
    121141<procedure>(pl-take n pl)</procedure>
    122142
    123 returns the head of pl up to but excluding index n,
    124 where n is less than or equal to pl's pl-length.
     143returns the head pseudolist of pl with sentinel kept
     144up to but excluding index n, where n is less than or equal
     145to pl's pl-length.
    125146
    126147==== pl-take-while
     
    129150<procedure>(pl-take-while ok? pl)</procedure>
    130151
    131 returns the head of pl consisting of items
    132 which pass the ok? test.
     152returns the head pseudolist of pl with sentinel kept consisting
     153of items until the first doesn't pass the ok? test.
    133154
    134155==== pl-map
    135156
    136157<procedure>(pl-map fn)</procedure>
    137 <procedure>(pl-map fn pl)</procedure>
    138 
    139 maps fn over the pseudolist pl, returning a new list.
     158<procedure>(pl-map fn . pls)</procedure>
     159
     160maps fn over the pseudolists pls, returning a new pseudolist
     161with sentinel from the first pl with minimal length, applying
     162fn successively to the list of car items up to the first list
     163containing a pl-null item.
     164This is R7RS-logic contrary to R5RS.
     165
     166==== pl-for-each
     167
     168<procedure>(pl-for-each fn pl . pls)</procedure>
     169
     170applies fn to successive cars of pl . pls as long as none
     171of them is pl-null?
     172This is R7RS-logic contrary to R5RS.
    140173
    141174==== pl-index
     
    152185<procedure>(pl-filter ok? pl)</procedure>
    153186
    154 returns the sublist of lst consisting of all items passing the ok?
    155 predicate. As always, the sentinel is stripped.
     187returns two values, the sublist of pl consisting of all items
     188passing or not passing the ok? predicate respectively.
     189The sentinel is kept in both values.
    156190
    157191==== pl-reverse
     
    159193<procedure>(pl-reverse  pl)</procedure>
    160194
    161 reverses its pseudolist argument, stripping the sentinel.
     195reverses its pseudolist argument, keeping the sentinel.
    162196
    163197==== pl-append
     
    165199<procedure>(pl-append pl . pls)</procedure>
    166200
    167 appends all argument pseudolists to a new list.
     201appends all argument pseudolists to a new pseudolist
     202with sentinel from the last pseudolist argument.
    168203
    169204==== pl-memp
     
    173208
    174209returns the sublist starting at the first
    175 item which passes the ok? test. If no item passes the ok? test,
    176 #f is returned.
     210item which passes the ok? test. The sentinel is preserved.
     211If no item passes the ok? test, #f is returned.
    177212
    178213==== pl-member
     
    234269<procedure>(adjoin obj pl)</procedure>
    235270
    236 adds obj to the pseudolist pl, provided obj is not an item of lst.
    237 As always, the sentinel is stripped.
     271adds obj to the pseudolist pl, provided obj is not an item of pl.
     272As always, the sentinel is kept.
    238273
    239274==== pl-remove-dups
     
    241276<procedure>(pl-remove-dups pl)</procedure>
    242277
    243 removes all duplicates of lst.
     278removes all duplicates of pl.
    244279
    245280==== pl-flatten
     
    247282<procedure>(pl-flatten pl-tree)</procedure>
    248283
    249 transforms a nested pseudolist to a flat list.
     284transforms a nested pseudolist to a flat pseudolist
     285with sentinel taken from the depth zero pseudolist.
    250286
    251287==== pl-collect
     
    260296qualifier have access to the variables of qualifiers
    261297to its left.
     298The sentinel of the result is that of the first pseudolist argument.
    262299
    263300=== Dependencies
     
    272309
    273310((pl-of? symbol?) '(a b . c)) ;-> #t
    274 (pl-iterate add1 5 0) ;-> '(0 1 2 3 4)
     311(pl-iterate add1 5 #f 0) ;-> '(0 1 2 3 4 . #f)
    275312
    276313(pl-length '(0 1 2 3 . 4)) ;-> 4
     
    281318
    282319(pl-index odd? '(0 2 4 . 1)) ;-> -1
    283 (pl-drop 0 1) ;-> '()
    284 (pl-drop 2 '(0 1 2 3 . #f)) ;-> '(2 3)
    285 (pl-take-while negative? '(1 3 2 4 . #f)) ;-> '()
    286 (pl-take 2 '(0 1 2 3 . #f)) ;-> '(0 1))
    287 
    288 (pl-filter odd? '(0 1 2 3 . 4)) ;-> '(1 3)
    289 (pl-map add1 '(0 1 2 3 . 4)) ;-> '(1 2 3 4)
    290 (pl-map add1 '(0 1 2 3 . 4)) ;-> '(1 2 3 4)
     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)
    291327(pl-map add1 '(0 1 2 3)) ;-> '(1 2 3 4)
    292 (pl-map add1 #f) ;-> '()
    293 
    294 (pl-reverse '(0 1 2 3 . 4)) ;-> '(3 2 1 0)
    295 
    296 (pl-append '(0 1 . #t) '(2 3 . #t) '(4 5 . #t)) ;-> '(0 1 2 3 4 5)
    297 (pl-append '(0 1) '(2 3) #f) ;-> '(0 1 2 3)
    298 (pl-adjoin 2 '(0 1 2 3 . #f)) ;-> '(0 1 2 3)
     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)
    299335(pl-adjoin 1 '()) ;-> '(1)
    300 (pl-remove-dups '(0 1 2 3 2 . 2)) ;-> '(0 1 3 2)
    301 
    302 (pl-flatten '(1 (2 3) . #t)) ;-> '(1 2 3)
    303 (pl-flatten '(1 (2 (3 . #f) . #t) . #f)) ;-> '(1 2 3)
    304 (pl-flatten #f) ;-> '()
     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
    305341
    306342(pl-collect (add1 x) (x '(0 1 2 3 . #t))) ; map
    307   ;-> '(1 2 3 4)
     343  ;-> '(1 2 3 4 . #t)
    308344(pl-collect (add1 x) (x '(0 1 2 3))) ; map
    309345  ;-> '(1 2 3 4)
     
    322358  ;-> '((A 1) (A 2) (A 3) (A 4)
    323359  ;     (B 1) (B 2) (B 3) (B 4)
    324   ;     (C 1) (C 2) (C 3) (C 4))
     360  ;     (C 1) (C 2) (C 3) (C 4) . #f)
    325361
    326362</enscript>
     
    328364== Last update
    329365
    330 Feb 25, 2020
     366Mar 24, 2020
    331367
    332368== Author
     
    366402
    367403== Version History
     404; 2.0 : sentinels kept, not stripped
    368405; 1.4 : pl-maker added
    369406; 1.3 : sentinel-options removed, all constructors create ordinary lists
Note: See TracChangeset for help on using the changeset viewer.