# [PD] list-math: do math on lists

Frank Barknecht fbar at footils.org
Sat Sep 10 12:32:51 CEST 2005

```Hi,

I figured, attached abstraction could be useful to someone else, too,
even though it's very simple.

list-math.pd will do basic math operations on lists, that is, add a
constant to a list, multiply a list with a float etc. It is similar to
Gem's vector operations v+, v*, etc. but is only using builtin objects
(as of pd-0.39, where "list" was introduced) and can deal with mixed
lists that also contain symbols, like "list a b c 1 2 3 x".

The basic principle used inside can also be changed to do symbol
operations or even more general ops. Just replace the central "expr"
with something else.

Ciao
--
Frank Barknecht                 _ ______footils.org_ __goto10.org__
-------------- next part --------------
#N canvas 424 89 624 640 10;
#X msg 119 113 1 2 3 4 a b c;
#X text 251 117 <- click to test;
#X obj 196 386 list;
#X obj 77 499 list;
#X obj 100 271 route float;
#X obj 100 385 list prepend;
#X floatatom 248 273 5 0 0 0 - - -;
#N canvas 0 0 533 407 drip 0;
#X obj 64 206 list split 1;
#X obj 64 123 until;
#X obj 64 181 list append;
#X obj 194 206 bang;
#X text 146 90 First store list \, then start the loop;
#X text 163 118 "until" bangs its output until told to stop by a "bang"
to its right inlet.;
#X text 182 160 Store the remaining list.;
#X text 239 205 third outlet of "split" tells us to stop.;
#X obj 64 243 outlet;
#X obj 64 57 inlet;
#X obj 64 86 t b l;
#X text 237 44 From list-help.pd;
#X connect 0 0 8 0;
#X connect 0 1 2 1;
#X connect 0 2 3 0;
#X connect 1 0 2 0;
#X connect 2 0 0 0;
#X connect 3 0 1 1;
#X connect 9 0 10 0;
#X connect 10 0 1 0;
#X connect 10 1 2 1;
#X restore 100 242 pd drip;
#X obj 78 150 t b a b;
#X text 254 314 Do math only on float elements;
#X obj 122 178 s \\$0-reset-result;
#X obj 179 357 r \\$0-reset-result;
#X text 260 177 clear result list;
#X text 175 242 "Drip" (serialize) the list;
#X text 258 389 Repack the list (think of the counter);
#X text 124 496 Final result is built here;
#X obj 78 81 inlet;
#X obj 100 307 expr \$f1 \\$1 \$f2;
#X obj 200 273 inlet;
#X obj 77 530 outlet;
#X text 182 32 Use as "list-math operator" where operator is some binary
operator \, expr can understand.;
#X connect 0 0 8 0;
#X connect 2 0 5 1;
#X connect 3 0 19 0;
#X connect 4 0 17 0;
#X connect 4 1 5 0;
#X connect 5 0 2 0;
#X connect 5 0 3 1;
#X connect 6 0 17 1;
#X connect 7 0 4 0;
#X connect 8 0 3 0;
#X connect 8 1 7 0;
#X connect 8 2 10 0;
#X connect 11 0 5 1;
#X connect 16 0 8 0;
#X connect 17 0 5 0;
#X connect 18 0 17 1;
-------------- next part --------------
#N canvas 395 384 675 536 10;
#X obj 160 259 print L;
#X msg 160 194 1 2 3 4 a b c;
#X floatatom 270 193 5 0 0 0 - - -;
#X obj 404 263 print L;
#X msg 404 198 1 2 3 4 a b c;
#X floatatom 514 197 5 0 0 0 - - -;
#X obj 164 365 print L;
#X msg 164 300 1 2 3 4 a b c;
#X floatatom 274 299 5 0 0 0 - - -;
#X obj 160 226 list-math *;
#X msg 159 167 1 2 3 4 a b c \, 10 20 30 x y z;
#X text 144 93 Use as "list-math operator" where operator is some binary
operator \, that expr can understand \, like + \, - \, * or /;
#X obj 406 373 print L;
#X msg 406 308 1 2 3 4 a b c;
#X floatatom 516 307 5 0 0 0 - - -;
#X obj 132 31 cnv 15 140 30 empty empty list-math 20 12 0 14 -233017
-66577 0;
#X text 292 40 simple mathematical operations on lists.;
#X obj 404 230 list-math +;
#X obj 164 332 list-math /;
#X obj 406 340 list-math -;
#X connect 1 0 9 0;
#X connect 2 0 9 1;
#X connect 4 0 17 0;
#X connect 5 0 17 1;
#X connect 7 0 18 0;
#X connect 8 0 18 1;
#X connect 9 0 0 0;
#X connect 10 0 9 0;
#X connect 13 0 19 0;
#X connect 14 0 19 1;
#X connect 17 0 3 0;
#X connect 18 0 6 0;
#X connect 19 0 12 0;
```