Update of /cvsroot/pure-data/abstractions/footils/list-abs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15689
Added Files: list-filter-help.pd list-filter.pd list-map-help.pd list-map.pd list-reduce-help.pd list-reduce.pd Log Message: Added three Functional Programming Tools for lists inspired by the Python functions map, reduce and filter.
--- NEW FILE: list-reduce-help.pd --- #N canvas 407 86 648 705 10; #X floatatom 128 311 5 0 0 0 - - -; #X msg 137 151 bang; #X obj 179 306 print TWO_ITEMS; #X obj 107 336 print RESULT; #X msg 144 175 1; #X msg 152 221 1 2 3; #X msg 149 197 1 2; #X msg 155 244 1 2 3 4; #X obj 196 273 *; #X text 182 152 redo last list; #X text 73 22 [list-reduce]; #X text 188 176 list with only one item will pass unchanged.; #X symbolatom 101 451 15 0 0 0 - - -; #X msg 196 420 $2-$1; #X obj 103 587 list-reduce; #X msg 103 560 1 2 3 4 5 6 7 8; #X msg 198 586 $2 $1; #N canvas 209 220 605 355 more-info 0; #X msg 84 101 bang; #X obj 126 236 print TWO_ITEMS; #X obj 54 266 print RESULT; #X msg 91 125 1; #X msg 99 171 1 2 3; #X msg 96 147 1 2; #X text 36 42 If nothing is connected to the right inlet , [list-reduce] will act like the left and right outlets of [list split 2] reversed. ; #X obj 54 203 list-reduce; #X msg 342 100 bang; #X obj 385 244 print TWO_ITEMS; #X obj 312 265 print RESULT; #X msg 349 124 1; #X msg 357 170 1 2 3; #X msg 354 146 1 2; #X obj 312 202 list split 2; #X text 178 202 equal to this:; #X connect 0 0 7 0; #X connect 3 0 7 0; #X connect 4 0 7 0; #X connect 5 0 7 0; #X connect 7 0 2 0; #X connect 7 1 1 0; #X connect 8 0 14 0; #X connect 11 0 14 0; #X connect 12 0 14 0; #X connect 13 0 14 0; #X connect 14 0 9 0; #X connect 14 2 10 0; #X restore 354 422 pd more-info; #X obj 103 615 print REVERSE?; #X obj 101 421 list-reduce; #X text 93 64 [list-reduce] returns a single value constructed by calling the user-defined objects connected to the right outlet on the first two items of the sequence , then on the result (if it comes in through the right inlet) and the next item of the original list , and so on. ; #X obj 107 273 list-reduce; #X text 100 485 It's important , that there will be only one element coming back in through the right inlet. Lists with more than one item will be shortened automatically to avoid stack overflows.; #X text 252 585 <-- two items == bad idea; #X msg 101 394 a b c d e; #X connect 1 0 21 0; #X connect 4 0 21 0; #X connect 5 0 21 0; #X connect 6 0 21 0; #X connect 7 0 21 0; #X connect 8 0 21 1; #X connect 13 0 19 1; #X connect 14 0 18 0; #X connect 14 1 16 0; #X connect 15 0 14 0; #X connect 16 0 14 1; #X connect 19 0 12 0; #X connect 19 1 13 0; #X connect 21 0 0 0; #X connect 21 0 3 0; #X connect 21 1 2 0; #X connect 21 1 8 0; #X connect 24 0 19 0;
--- NEW FILE: list-map.pd --- #N canvas 470 232 489 423 10; #X obj 86 33 inlet; #X obj 275 52 inlet; #X obj 151 352 outlet; #X obj 170 248 outlet; #X obj 151 317 list; #X obj 170 215 list-drip; #X obj 275 215 list prepend; #X obj 354 185 t a; #X obj 151 155 t b a a b; #X obj 86 58 route bang; #X obj 86 83 b; #X obj 151 84 t b a; #X obj 151 124 list; #X connect 0 0 9 0; #X connect 1 0 6 0; #X connect 4 0 2 0; #X connect 5 0 3 0; #X connect 6 0 7 0; #X connect 6 0 4 1; #X connect 7 0 6 1; #X connect 8 0 4 0; #X connect 8 1 5 0; #X connect 8 2 4 1; #X connect 8 3 6 1; #X connect 9 0 10 0; #X connect 9 1 11 0; #X connect 10 0 12 0; #X connect 11 0 12 0; #X connect 11 1 12 1; #X connect 12 0 8 0;
--- NEW FILE: list-map-help.pd --- #N canvas 344 116 618 692 10; #X obj 67 310 list-map; #X text 65 32 [list-map] - the swiss army knife of list-operations ; #X obj 135 310 spigot; #X obj 171 293 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1; #X msg 67 266 0 1 2 3; #X obj 118 347 print SERIALIZED; #X obj 67 376 print MAIN; #X msg 313 268 0 1 2 3; #X obj 364 349 print SERIALIZED; #X obj 313 378 print MAIN; #X floatatom 404 292 5 0 0 0 - - -; #X msg 67 245 bang; #X msg 145 265 a b c; #X msg 145 245 bang; #X obj 381 312 * 10; #X msg 313 244 bang; #X msg 72 447 0 1 2 3; #X obj 72 536 list trim; #X obj 72 516 list prepend set; #X msg 72 558; #X obj 138 471 list append -|-; #X msg 227 541 set; #X text 304 564 A more complex example:; #N canvas 164 99 846 438 filters 0; #N canvas 0 0 450 300 (subpatch) 0; #X array $0-in 64 float 0; #X coords 0 1 63 -1 128 60 1; #X restore 503 222 graph; #N canvas 0 0 450 300 (subpatch) 0; #X array $0-out 64 float 0; #X coords 0 1 63 -1 128 60 1; #X restore 645 222 graph; #X obj 110 316 s $0-out; #N canvas 414 307 437 371 tabdump-in 0; #X obj 147 152 tabread $0-in; #X obj 147 205 list prepend; #X obj 238 205 t a; #X obj 125 254 list; #X obj 125 23 inlet; #X obj 125 279 outlet; #X obj 125 46 t b b b; #X msg 147 104 64; #N canvas 0 0 450 300 countto 0; #X obj 163 151 f 0; #X obj 190 151 + 1; #X obj 163 109 until; #X msg 205 111 0; #X obj 163 180 outlet; #X obj 163 39 inlet; #X obj 163 87 t a b; #X connect 0 0 1 0; #X connect 0 0 4 0; #X connect 1 0 0 1; #X connect 2 0 0 0; #X connect 3 0 0 1; #X connect 5 0 6 0; #X connect 6 0 2 0; #X connect 6 1 3 0; #X restore 147 126 pd countto; #X connect 0 0 1 0; #X connect 1 0 3 1; #X connect 1 0 2 0; #X connect 2 0 1 1; #X connect 3 0 5 0; #X connect 4 0 6 0; #X connect 6 0 3 0; #X connect 6 1 7 0; #X connect 6 2 1 1; #X connect 7 0 8 0; #X connect 8 0 0 0; #X restore 110 206 pd tabdump-in; #X msg 110 155 bang; #X obj 110 294 list prepend 0; #N canvas 0 0 297 272 pole 0; #X obj 71 140 +; #X obj 71 172 t a a; #X obj 117 173 * 0.9; #X obj 71 54 inlet; #X obj 147 51 inlet; #X obj 71 230 outlet; #X text 72 17 one-pole filter; #X obj 147 74 t b a; #X msg 87 118 0; #X connect 0 0 1 0; #X connect 1 0 5 0; #X connect 1 1 2 0; #X connect 2 0 0 1; #X connect 3 0 0 0; #X connect 4 0 7 0; #X connect 7 0 8 0; #X connect 7 1 2 1; #X connect 8 0 0 1; #X restore 297 269 pd pole; #X obj 269 117 hsl 64 15 0 0.99 0 0 empty empty filter-coeff -2 -8 1 10 -262144 -1 -1 0 1; #N canvas 0 0 297 272 zero 0; #X obj 71 142 t a a; #X obj 71 44 inlet; #X obj 124 41 inlet; #X obj 71 230 outlet; #X text 71 20 one-zero filter; #X obj 71 204 +; #X obj 154 112 * -1; #X obj 71 168 * -0.5; #X obj 124 66 t b a; #X msg 87 113 0; #X connect 0 0 7 0; #X connect 0 1 5 0; #X connect 1 0 0 0; #X connect 2 0 8 0; #X connect 5 0 3 0; #X connect 6 0 7 1; #X connect 7 0 5 1; #X connect 8 0 9 0; #X connect 8 1 6 0; #X connect 9 0 5 1; #X restore 244 269 pd zero; #N canvas 0 0 341 267 split 0; #X obj 11 193 outlet; #X obj 68 194 outlet; #X obj 11 143 list prepend 0; #X obj 11 169 route 0 1; #X obj 104 110 hradio 12 1 0 2 empty empty zero 28 3 1 10 -262144 -1 -1 0; #X obj 11 68 inlet; #X obj 180 33 select 0 1; #X msg 180 62 label zero; #X msg 211 87 label pole; #X obj 104 38 loadbang; #X msg 104 64 0; #X connect 2 0 3 0; #X connect 3 0 0 0; #X connect 3 1 1 0; #X connect 4 0 2 1; #X connect 4 0 6 0; #X connect 5 0 2 0; #X connect 6 0 7 0; #X connect 6 1 8 0; #X connect 7 0 4 0; #X connect 8 0 4 0; #X connect 9 0 10 0; #X connect 10 0 4 0; #X coords 0 -1 1 1 60 30 2 100 100; #X restore 244 217 pd split; #X floatatom 266 139 5 0 0 0 - - -; #N canvas 0 0 297 280 noise 0; #X obj 33 115 random 1000; #X obj 33 88 t b a; #X obj 33 194 tabwrite $0-in; #X obj 33 143 / 500; #X obj 33 163 - 1; #X msg 33 44 64; #N canvas 0 0 450 300 countto 0; #X obj 163 151 f 0; #X obj 190 151 + 1; #X obj 163 109 until; #X msg 205 111 0; #X obj 163 180 outlet; #X obj 163 39 inlet; #X obj 163 87 t a b; #X connect 0 0 1 0; #X connect 0 0 4 0; #X connect 1 0 0 1; #X connect 2 0 0 0; #X connect 3 0 0 1; #X connect 5 0 6 0; #X connect 6 0 2 0; #X connect 6 1 3 0; #X restore 33 66 pd countto; #X obj 33 21 inlet; #X connect 0 0 3 0; #X connect 1 0 0 0; #X connect 1 1 2 1; #X connect 3 0 4 0; #X connect 4 0 2 0; #X connect 5 0 6 0; #X connect 6 0 1 0; #X connect 7 0 5 0; #X restore 504 184 pd noise; #X msg 504 160 make noise; #X obj 266 158 t b a a; #X msg 439 324 const 0; #X obj 439 365 s $0-in; #X obj 440 390 s $0-out; #X msg 500 324 const 0 , 16 1; #X text 498 308 impulse; #X text 112 34 This is a more complex example showing how to apply a set of elementary filters on a list of floats. Try playing with the coeff-slider and switch between pole and zero operation.; #X obj 110 236 list-map; #X connect 3 0 20 0; #X connect 4 0 3 0; #X connect 5 0 2 0; #X connect 6 0 20 1; #X connect 7 0 10 0; #X connect 8 0 20 1; #X connect 9 0 8 0; #X connect 9 1 6 0; #X connect 10 0 13 0; #X connect 12 0 11 0; #X connect 13 0 3 0; #X connect 13 1 8 1; #X connect 13 2 6 1; #X connect 14 0 15 0; #X connect 14 0 16 0; #X connect 17 0 15 0; #X connect 20 0 5 0; #X connect 20 1 9 0; #X restore 330 586 pd filters; #X text 67 626 2007 Frank Barknecht , original idea by IOhannes m zmoelnig and Thomas Musil.; #X obj 313 312 list-map; #X obj 72 471 list-map; #X msg 71 421 bang; #X text 64 72 Calls a user-defined operation for each of the incoming list's items and returns a list of the return values.; #X text 64 120 [list-map] is a helper abstraction to make element-wise operations on lists easy to patch. The basic idea is to bundle a list-serializer and a list-repacker into one object. Then you connect whatever operation should be applied on every list item to the right outlet and send the modified items back to the right inlet. Here the modified elements get packed into a list again and sent to the left outlet of [list-map]. ; #X obj 315 460 list-map; #X obj 315 502 list trim; #X obj 315 482 list prepend set; #X obj 387 460 pow 3; #X floatatom 417 437 5 0 0 0 - - -; #X msg 315 435 1 2 3 4 5; #X msg 315 524; #X connect 0 0 6 0; #X connect 0 1 2 0; #X connect 0 1 5 0; #X connect 2 0 0 1; #X connect 3 0 2 1; #X connect 4 0 0 0; #X connect 7 0 25 0; #X connect 10 0 14 1; #X connect 11 0 0 0; #X connect 12 0 0 1; #X connect 13 0 0 1; #X connect 14 0 25 1; #X connect 15 0 25 0; #X connect 16 0 26 0; #X connect 17 0 19 0; #X connect 18 0 17 0; #X connect 20 0 26 1; #X connect 21 0 19 0; #X connect 25 0 9 0; #X connect 25 1 8 0; #X connect 25 1 14 0; #X connect 26 0 18 0; #X connect 26 1 20 0; #X connect 27 0 26 0; #X connect 30 0 32 0; #X connect 30 1 33 0; #X connect 31 0 36 0; #X connect 32 0 31 0; #X connect 33 0 30 1; #X connect 34 0 33 1; #X connect 35 0 30 0;
--- NEW FILE: list-reduce.pd --- #N canvas 238 102 593 526 10; #X obj 86 33 inlet; #X obj 275 52 inlet; #X obj 151 352 outlet; #X obj 205 353 outlet; #X obj 86 58 route bang; #X obj 86 83 b; #X obj 151 84 t b a; #X obj 151 124 list; #X obj 151 233 list split 2; #X obj 151 155 t a b; #X obj 275 189 list append; #X text 53 386 [list-reduce]; #X text 55 423 [list-reduce] returns a single value constructed by calling the user-defined objects connected to the right outlet on the first two items of the sequence , then on the result (if it comes in through the right inlet) and the next item , and so on.; #X obj 275 124 list split 1; #X connect 0 0 4 0; #X connect 1 0 13 0; #X connect 4 0 5 0; #X connect 4 1 6 0; #X connect 5 0 7 0; #X connect 6 0 7 0; #X connect 6 1 7 1; #X connect 7 0 9 0; #X connect 8 0 3 0; #X connect 8 1 10 1; #X connect 8 2 2 0; #X connect 9 0 8 0; #X connect 9 1 10 1; #X connect 10 0 8 0; #X connect 13 0 10 0;
--- NEW FILE: list-filter-help.pd --- #N canvas 367 75 578 673 10; #X obj 226 453 mod 2; #X obj 226 483 != 0; #X obj 274 454 mod 3; #X obj 274 483 != 0; #X obj 226 517 &&; #X obj 226 426 t a a; #N canvas 0 0 450 300 show 0; #X obj 129 107 list prepend set; #X obj 129 129 list trim; #X obj 129 79 inlet; #X obj 129 154 outlet; #X connect 0 0 1 0; #X connect 1 0 3 0; #X connect 2 0 0 0; #X restore 70 548 pd show; #X msg 70 574 5 7 11 13 17 19 23; #X text 62 27 [list-filter]; #X text 66 58 [list-filter] returns a sequence consisting of those items from the sequence for which the user-defined operation cross-connected to the rightmost in- and outlet is true.; #X text 66 112 Everything that is not 0 is considered a TRUE value. Internally [select 0] is used.; #X msg 70 213 0 1 2 3 4 5; #N canvas 0 0 450 300 show 0; #X obj 129 107 list prepend set; #X obj 129 129 list trim; #X obj 129 79 inlet; #X obj 129 154 outlet; #X connect 0 0 1 0; #X connect 1 0 3 0; #X connect 2 0 0 0; #X restore 70 286 pd show; #X msg 70 312 3 4 5; #X obj 167 266 >= 3; #X text 67 163 Examples:; #X text 217 266 remove values smaller than 3 from list; #X obj 160 212 t b a; #X floatatom 160 193 5 0 0 0 - - -; #X text 200 212 "bang" to [list-filter] will resend the last list; #X obj 70 265 list-filter; #X text 70 362 Calculate some small primes:; #X msg 70 387 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24; #X obj 70 471 list-filter; #X connect 0 0 1 0; #X connect 1 0 4 0; #X connect 2 0 3 0; #X connect 3 0 4 1; #X connect 4 0 23 1; #X connect 5 0 0 0; #X connect 5 1 2 0; #X connect 6 0 7 0; #X connect 11 0 20 0; #X connect 12 0 13 0; #X connect 14 0 20 1; #X connect 17 0 20 0; #X connect 17 1 14 1; #X connect 18 0 17 0; #X connect 20 0 12 0; #X connect 20 1 14 0; #X connect 22 0 23 0; #X connect 23 0 6 0; #X connect 23 1 5 0;
--- NEW FILE: list-filter.pd --- #N canvas 400 208 519 432 10; #X obj 86 33 inlet; #X obj 275 52 inlet; #X obj 151 352 outlet; #X obj 170 268 outlet; #X obj 151 317 list; #X obj 170 215 list-drip; #X obj 326 250 list prepend; #X obj 405 220 t a; #X obj 86 58 route bang; #X obj 86 83 b; #X obj 151 84 t b a; #X obj 151 124 list; #X obj 275 111 select 0; #X obj 326 133 b; #X obj 326 209 list; #X obj 170 244 t a a; #X obj 151 155 t b a a b b; #X connect 0 0 8 0; #X connect 1 0 12 0; #X connect 4 0 2 0; #X connect 5 0 15 0; #X connect 6 0 7 0; #X connect 6 0 4 1; #X connect 7 0 6 1; #X connect 8 0 9 0; #X connect 8 1 10 0; #X connect 9 0 11 0; #X connect 10 0 11 0; #X connect 10 1 11 1; #X connect 11 0 16 0; #X connect 12 1 13 0; #X connect 13 0 14 0; #X connect 14 0 6 0; #X connect 15 0 3 0; #X connect 15 1 14 1; #X connect 16 0 4 0; #X connect 16 1 5 0; #X connect 16 2 4 1; #X connect 16 3 6 1; #X connect 16 4 14 1;