Changeset 37761 in project


Ignore:
Timestamp:
07/05/19 12:15:22 (13 days ago)
Author:
juergen
Message:

biglists, pseudolists, list-comprehensiond: doku updated

Location:
wiki/eggref/5
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/5/biglists

    r37755 r37761  
    5050* List comprehensions work as well for biglists.
    5151
    52 This is provided by the For macro.
     52This is provided by the Collect macro, inspired by Clojure's For macro.
    5353
    5454=== Documentation
     
    245245with init<procedure>(map First xss)</procedure>
    246246
    247 ==== For
    248 
    249 <macro>(For item-xpr (var xs ok-xpr ...) (var1 xs1 ok-xpr1 ...) ...)</macro>
     247==== Collect
     248
     249<macro>(Collect item-xpr (var xs ok-xpr ...) (var1 xs1 ok-xpr1 ...) ...)</macro>
    250250
    251251creates a new list by binding var to each element
     
    639639  ;-> '(1 0 3 (1 2 3 4 5))
    640640
    641 (BigList->list (For (add1 x) (x (List 0 1 2 3)))) ;  map
     641(BigList->list (Collect (add1 x) (x (List 0 1 2 3)))) ;  map
    642642  ;-> '(1 2 3 4))
    643643
    644 (BigList->list (For x (x (List 0 1 2 3 4 5 6) (odd? x)))) ; filter
     644(BigList->list (Collect x (x (List 0 1 2 3 4 5 6) (odd? x)))) ; filter
    645645  ;-> '(1 3 5))
    646646
    647 (BigList->list (For (* 10 n)
     647(BigList->list (Collect (* 10 n)
    648648                    (n (List 0 1 2 3 4 5 6) (positive? n) (even? n))))
    649649  ;-> '(20 40 60))
    650650
    651 (BigList->list (For (list c k)
     651(BigList->list (Collect (list c k)
    652652                    (c (List 'A 'B 'C)) ;lazy
    653653                    (k '(1 2 3 4)))) ;eager
     
    656656  ;     (C 1) (C 2) (C 3) (C 4))
    657657
    658 (For (list c k)
     658(Collect (list c k)
    659659     (c '(A B C)) ;eager
    660660     (k (List 1 2 3 4))) ;lazy
     
    667667== Last update
    668668
    669 Jul 04, 2019
     669Jul 05, 2019
    670670
    671671== Author
     
    706706== Version History
    707707
     708; 0.3 : For macro renamed Collect
    708709; 0.2 : syntax of For changed
    709710; 0.1.2 : some typos corrected
  • wiki/eggref/5/list-comprehensions

    r37754 r37761  
    88Standard ML, Miranda, Haskell.
    99
    10 The implementation of this module is inspired by Clojure, in particular
    11 the for macro.
     10Here, it is implemented with the macro collect, which is inspired by
     11Clojure's for macro.
    1212
    1313Other list-generating procedures, like range, repeat, iterate-times,
     
    4545==== iterate-times
    4646
    47 <procedure>(iterate-times fn times)</procedure>
    48 <procedure>(iterate-times fn times start)</procedure>
    49 
    50 produces a list of length times where the items are constructed by
    51 successively applying fn to the last value, starting with start.
     47<procedure>(iterate-times fn k)</procedure>
     48<procedure>(iterate-times fn k start)</procedure>
     49
     50produces a list where the items are constructed by successively applying
     51fn k times to the last value, starting with start.
    5252
    5353==== iterate-while
     
    7070
    7171
    72 ==== for
    73 
    74 </macro>(for item qualifier ....)</macro>
     72==== collect
     73
     74</macro>(collect item qualifier ....)</macro>
    7575
    7676where item is an expression with variables to be bound in the
     
    9292
    9393<enscript highlight=scheme>
    94   (for (list x y z)
     94  (collect (list x y z)
    9595       (x (list #\A #\B))
    9696       (y (list 1 2))
     
    141141(iterate-while sub1 positive? 5) ; -> '(5 4 3 2 1)
    142142
    143 (for (list c k)
    144     (c (string->list "ABCDEFG"))
    145     (k '(1 2 3 4 5 6 7 8)))
     143(collect (list c k)
     144                                (c (string->list "ABCDEFG"))
     145                                (k '(1 2 3 4 5 6 7 8)))
    146146; -> ((#\A 1) ... (#\A 8) ... (#\G 1) ... (#\G 8))
    147147
    148 (for (list c k)
    149     (c (string->list "ABCDEFG"))
    150     (k '(1 2 3 4 5 6 7 8) (memv c '(#\A #\G)) (memv k '(1 8))))
     148(collect (list c k)
     149                                (c (string->list "ABCDEFG"))
     150                                (k '(1 2 3 4 5 6 7 8) (memv c '(#\A #\G)) (memv k '(1 8))))
    151151; -> ((#\A 1) (#\A 8) (#\G 1) (#\G 8))
    152152
    153 (for (add1 x) (x '(0 1 2 3))) ; map
     153(collect (add1 x) (x '(0 1 2 3))) ; map
    154154; -> '(1 2 3 4)
    155155
    156 (for x (x '(0 1 2 3 4 5) (odd? x))) ; filter
     156(collect x (x '(0 1 2 3 4 5) (odd? x))) ; filter
    157157; -> '(1 3 5)
    158158</enscript>
     
    160160== Last update
    161161
    162 Jul 04, 2019
     162Jul 05, 2019
    163163
    164164== Author
     
    198198
    199199== Version History
     200; 1.2 : macro for renamed collect
    200201; 1.1 : curried and uncurried versions, syntax of for changed
    201202; 1.0 : initial import for chicken-5
  • wiki/eggref/5/pseudolists

    r37758 r37761  
    251251transforms a nested pseudolist to a flat pseudolist with (sentinel opt).
    252252
    253 ==== pl-for
    254 
    255 <macro>(pl-for opt item-xpr (var pl ok-xpr ...) ....)</macro>
     253==== pl-collect
     254
     255<macro>(pl-collect opt item-xpr (var pl ok-xpr ...) ....)</macro>
    256256
    257257creates a new pseudolist with (sentinel opt) by binding var to each element
     
    310310(null? (pl-flatten (No-sentinel) #f) ;-> '()
    311311
    312 (pl-for (Some-sentinel #f) (add1 x) (x '(0 1 2 3 . #t))) ; map
     312(pl-collect (Some-sentinel #f) (add1 x) (x '(0 1 2 3 . #t))) ; map
    313313  ;-> '(1 2 3 4 . #f)
    314 (pl-for (No-sentinel) (add1 x) (x '(0 1 2 3))) ; map
     314(pl-collect (No-sentinel) (add1 x) (x '(0 1 2 3))) ; map
    315315  ;-> '(1 2 3 4)
    316 (pl-for (No-sentinel) x (x '(0 1 2 3 4 5) (odd? x))) ; filter
     316(pl-collect (No-sentinel) x (x '(0 1 2 3 4 5) (odd? x))) ; filter
    317317  ;-> '(1 3 5)
    318 (pl-for (Some-sentinel #f) (* 10 n)
    319         (n '(0 1 2 3 4 5) (positive? n) (even? n)))
     318(pl-collect (Some-sentinel #f) (* 10 n)
     319            (n '(0 1 2 3 4 5) (positive? n) (even? n)))
    320320  ;-> '(20 40 . #f)
    321 (pl-for (No-sentinel) (list c k)
    322         (c '(A B C)) (k '(1 2 3 4)))
     321(pl-collect (No-sentinel) (list c k)
     322            (c '(A B C)) (k '(1 2 3 4)))
    323323  ;-> '((A 1) (A 2) (A 3) (A 4)
    324324  ;     (B 1) (B 2) (B 3) (B 4)
    325325  ;     (C 1) (C 2) (C 3) (C 4))
    326 (pl-for (No-sentinel) (list c k)
    327         (c '(A B C . #f)) (k '(1 2 3 4 . #t)))
     326(pl-collect (No-sentinel) (list c k)
     327            (c '(A B C . #f)) (k '(1 2 3 4 . #t)))
    328328  ;-> '((A 1) (A 2) (A 3) (A 4)
    329329  ;     (B 1) (B 2) (B 3) (B 4)
     
    334334== Last update
    335335
    336 Jul 03, 2019
     336Jul 05, 2019
    337337
    338338== Author
     
    373373== Version History
    374374
     375; 1.2 : macro pl-for renamed pl-collect
    375376; 1.1 : some sentinel-option arguments added; syntax-change of pl-for and pl-iterate
    376377; 1.0 : initial import
Note: See TracChangeset for help on using the changeset viewer.