Changeset 37751 in project


Ignore:
Timestamp:
07/04/19 11:34:15 (2 weeks ago)
Author:
juergen
Message:

pseudolist-1.1 docu: sentinell-options added, syntax of pl-iterate and pl-for changed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/5/pseudolists

    r37449 r37751  
    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 are not touched in a map routine. Moreover,
    19 constructors must supply the sentinel as an additional argument.
     18in a length routine, and have to be handled in constructors by supplying
     19an additional argument, a sentinel-option.
     20
     21Additional sentinel-option arguments are not provided, if a sub-pseudolist is
     22constructed, e.g. for filter, member, drop, take. In that case, the sentinel
     23of the original pseudolist is used.
    2024
    2125Most functions in this module are written in curried and uncurried form.
    2226So the curried version can be used in maps and friends. The signature of
    2327both versions is documented below, but only the uncurried version is
    24 described.
     28described. If the pseudolist argument is missing in the signature, it's
     29the curried version.
     30
     31Note, that the order of arguments is consistent: Sentinel-options come first,
     32procedures second and pseudolists last.
     33To conform to this convention, I've changed the syntax of pl-iterate and
     34pl-for.
    2535
    2636=== Module pseudolists
     
    3646==== pl-maker
    3747
    38 <procedure>(pl-maker sentinel . args)</procedure>
    39 
    40 constructs a new pseudolist. Note the position of the sentineal
    41 argument.
     48<procedure>(pl-maker opt . args)</procedure>
     49
     50constructs a new pseudolist with (sentinel opt).
    4251
    4352==== pl?
     
    6877==== pl-iterate
    6978
    70 <procedure>(pl-iterate sentinel k fn)</procedure>
    71 <procedure>(pl-iterate sentinel k fn init)</procedure>
    72 
    73 creates a pseudolist with sentinel applying fn to init
     79<procedure>(pl-iterate opt fn k)</procedure>
     80<procedure>(pl-iterate opt fn k init)</procedure>
     81
     82creates a pseudolist with (sentinel opt) applying fn to init
    7483recursively k times.
    7584
     
    95104==== pl-drop
    96105
    97 <procedure>(pl-drop pl)</procedure>
     106<procedure>(pl-drop n)</procedure>
    98107<procedure>(pl-drop n pl)</procedure>
    99108
     
    103112==== pl-drop-while
    104113
    105 <procedure>(pl-drop-while pl)</procedure>
    106 <procedure>(pl-drop-while n pl)</procedure>
     114<procedure>(pl-drop-while ok?)</procedure>
     115<procedure>(pl-drop-while ok? pl)</procedure>
    107116
    108117returns the tail of pl starting with the first item
     
    111120==== pl-take
    112121
     122<procedure>(pl-take n)</procedure>
    113123<procedure>(pl-take n pl)</procedure>
    114 <procedure>(pl-take pl)</procedure>
    115124
    116125returns the head of pl up to but excluding index n,
     
    119128==== pl-take-while
    120129
    121 <procedure>(pl-take-while pl)</procedure>
     130<procedure>(pl-take-while ok?)</procedure>
    122131<procedure>(pl-take-while ok? pl)</procedure>
    123132
     
    127136==== pl-map
    128137
    129 <procedure>(pl-map fn)</procedure>
    130 <procedure>(pl-map fn pl)</procedure>
    131 
    132 maps fn over the pseudolist pl.
     138<procedure>(pl-map opt fn)</procedure>
     139<procedure>(pl-map opt fn pl)</procedure>
     140
     141maps fn over the pseudolist pl, returning a new pseudolist
     142with (sentinel opt).
    133143
    134144==== pl-index
     
    150160==== pl-reverse
    151161
    152 <procedure>(pl-reverse pl)</procedure>
    153 
    154 reverses its pseudolist argument.
     162<procedure>(pl-reverse opt pl)</procedure>
     163
     164reverses its pseudolist argument, changing the sentinel
     165to (sentinel opt).
    155166
    156167==== pl-append
    157168
    158 <procedure>(pl-append pl . pls)</procedure>
    159 
    160 appends all argument pseudolists.
     169<procedure>(pl-append opt pl . pls)</procedure>
     170
     171appends all argument pseudolists to a new one with (sentinel opt).
    161172
    162173==== pl-memp
     
    236247==== pl-flatten
    237248
    238 <procedure>(pl-flatten tree)</procedure>
    239 
    240 transforms a nested pseudolist to a flat list including sentinels.
     249<procedure>(pl-flatten opt pl-tree)</procedure>
     250
     251transforms a nested pseudolist to a flat pseudolist with (sentinel opt).
    241252
    242253==== pl-for
    243254
    244 <macro>(pl-for ((var pl ok-xpr ...) (var1 pl1 ok-xpr1 ...) ...) item-xpr)</macro>
    245 
    246 creates a new pseudolist by binding var to each element
     255<macro>(pl-for opt item-xpr (var pl ok-xpr ...) ....)</macro>
     256
     257creates a new pseudolist with (sentinel opt) by binding var to each element
    247258of the pseudolist pl in sequence, and if it passes the checks,
    248 ok-xpr ..., inserts the value of item-xpr into the resulting pseudolist.
     259ok-xpr ..., inserts the value of item-xpr into the resulting (pseudo-) list.
    249260The qualifieres, (var pl ok-xpr ...), are processed
    250261sequentially from left to right, so that filters of a
     
    254265=== Dependencies
    255266
    256 none
     267datatype
    257268
    258269=== Examples
     
    263274
    264275((pl-of? symbol?) '(a b . c)) ;-> #t
    265 (pl-maker #f 0 1 2 3) ;-> '(0 1 2 3 . #f)
    266 (pl-maker '() 0 1 2 3) ;-> '(0 1 2 3)
    267 (pl-iterate #f 5 add1 0) ;-> '(0 1 2 3 4 . #f)
     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)
    268279
    269280(pl-length '(0 1 2 3 . 4)) ;-> 4
     
    277288(pl-drop 2 '(0 1 2 3 . #f)) ;-> '(2 3 . #f)
    278289(pl-take-while negative? '(1 3 2 4 . #f)) ;-> #f
     290(pl-take 2 '(0 1 2 3 . #f)) ;-> '(0 1 . #f))
    279291
    280292(pl-filter odd? '(0 1 2 3 . 4)) ;-> '(1 3 . 4)
    281 (pl-map add1 '(0 1 2 3 . 4)) ;-> '(1 2 3 4 . 4)
    282 (pl-map add1 #f) ;-> #f
    283 (pl-reverse '(0 1 2 3 . 4)) ;-> '(3 2 1 0 . 4)
    284 
    285 (pl-append '(0 1) '(2 3) #f) ;-> '(0 1 2 3 . #f)
     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)
    286303(pl-adjoin 2 '(0 1 2 3 . #f)) ;-> '(0 1 2 3 . #f)
    287304(pl-adjoin 1 '()) ;-> '(1)
    288305(pl-remove-dups '(0 1 2 3 2 . 2)) ;-> '(0 1 3 2 . 2)
    289 (pl-flatten '(0 (1 (2 . 3) 4 . #f))) ;-> '(0 1 2 3 4 #f)
    290 
    291 (pl-for ((x '(0 1 2 3 . #f))) (add1 x)) ; map
     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-for (Some-sentinel #f) (add1 x) (x '(0 1 2 3 . #t))) ; map
    292313  ;-> '(1 2 3 4 . #f)
    293 (pl-for ((x '(0 1 2 3))) (add1 x)) ; map
     314(pl-for (No-sentinel) (add1 x) (x '(0 1 2 3))) ; map
    294315  ;-> '(1 2 3 4)
    295 (pl-for ((x '(0 1 2 3 4 5) (odd? x))) x) ; filter
     316(pl-for (No-sentinel) x (x '(0 1 2 3 4 5) (odd? x))) ; filter
    296317  ;-> '(1 3 5)
    297 (pl-for ((n '(0 1 2 3 4 5) (positive? n) (even? n)))
    298             (* 10 n))
    299   ;-> '(20 40)
    300 (pl-for ((c '(A B C)) (k '(1 2 3 4)))
    301   (list c k))
     318(pl-for (Some-sentinel #f) (* 10 n)
     319        (n '(0 1 2 3 4 5) (positive? n) (even? n)))
     320  ;-> '(20 40 . #f)
     321(pl-for (No-sentinel) (list c k)
     322        (c '(A B C)) (k '(1 2 3 4)))
    302323  ;-> '((A 1) (A 2) (A 3) (A 4)
    303324  ;     (B 1) (B 2) (B 3) (B 4)
    304325  ;     (C 1) (C 2) (C 3) (C 4))
    305 (pl-for ((c '(A B C . #f)) (k '(1 2 3 4 . #t))) (list c k))
     326(pl-for (No-sentinel) (list c k)
     327        (c '(A B C . #f)) (k '(1 2 3 4 . #t)))
    306328  ;-> '((A 1) (A 2) (A 3) (A 4)
    307329  ;     (B 1) (B 2) (B 3) (B 4)
    308   ;     (C 1) (C 2) (C 3) (C 4) . #f)
     330  ;     (C 1) (C 2) (C 3) (C 4))
    309331
    310332</enscript>
     
    312334== Last update
    313335
    314 Mar 24, 2019
     336Jul 03, 2019
    315337
    316338== Author
     
    351373== Version History
    352374
     375; 1.1 : some sentinel-option arguments added; syntax-change of pl-for and pl-iterate
    353376; 1.0 : initial import
    354377
    355 
    356 
Note: See TracChangeset for help on using the changeset viewer.