<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>I'm still not familiar with data structure and pointers in pd, but I think I'll use your suggestion as a starting point. Thanks!</span></div><div><span>BEnoît<br></span></div><div><br><span></span></div><div><br><span></span></div><div><span><br></span></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> <hr size="1">  <b><span style="font-weight:bold;">De&nbsp;:</span></b> Frank Barknecht &lt;fbar@footils.org&gt;<br> <b><span style="font-weight: bold;">À&nbsp;:</span></b> pd-list@iem.at <br> <b><span style="font-weight: bold;">Envoyé le :</span></b> samedi 17 mars 2012 11h49<br> <b><span style="font-weight: bold;">Objet&nbsp;:</span></b> Re: [PD]
 Re&nbsp;: store and manipulate multiple lists<br> </font> </div> <br>Hi,<br><br>On Thu, Mar 15, 2012 at 11:39:51AM +0000, Andy Farnell wrote:<br>&gt; Yes of course. Once you can sort items of any type you can sort <br>&gt; aggregate items, structs, sublists&nbsp; or whatever on one of their<br>&gt; elements. Its a little messy in Pd. The best way might be to<br>&gt; use pointers and try to do the classic Kernighan and Richie<br>&gt; head swap thing but I have no idea how to exchange pointers in<br>&gt; Pd.<br><br>Sorting lists of numbers by their first element is pretty easy to do<br>with Pd's data structures/pointers. I don't have Pd at hand now to patch<br>an example (maybe Monday), but basically you first define a data<br>structure with one "float x" field and one with an array of these<br>float-items in addition to its own float x. <br><br> [pd $0-f]: <br>&nbsp; &nbsp; structure with one float item:<br>&nbsp; &nbsp; [struct $0-f float x]<br><br> [pd
 $0-record]:<br>&nbsp;  structure with an x-float for sorting and the array "data" to hold<br>&nbsp;  all the list items:<br>&nbsp;  [struct $0-record float x array data $0-f]<br><br>Then you create the structured data from the lists and write them to a<br>subpatch as usual with data structures. The first element in an incoming<br>lists doubles as "x" position, the array holds the rest of the list.<br><br>&nbsp;  [r one-list]<br>&nbsp;  |<br>&nbsp;  [t a a a]<br>&nbsp;  |&nbsp; &nbsp; |&nbsp; |<br>&nbsp;  |&nbsp; &nbsp; |&nbsp; [list split 1]<br>&nbsp;  |&nbsp; &nbsp; |&nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ... traverse subpatch blabla<br>&nbsp;  |&nbsp; &nbsp; |&nbsp; [append $0-record x]<br>&nbsp;  |&nbsp; &nbsp; |&nbsp; |<br>&nbsp;  |&nbsp; &nbsp; |&nbsp; [s $0-current-pointer]<br>&nbsp;  |&nbsp; &nbsp; |<br>&nbsp;  |&nbsp; &nbsp; [list length]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [r $0-current-pointer]<br>&nbsp;  |&nbsp;
 &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |<br>&nbsp;  |&nbsp; &nbsp; [setsize $0-record data]<br>&nbsp;  |<br>&nbsp;  [list-enumerate] &lt;- list-drip with index numbers, i.e. "list a b" -&gt; "0 a, 1 b"<br>&nbsp;  |<br>&nbsp;  [swap]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [r $0-current-pointer]<br>&nbsp;  |&nbsp;  \&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  |<br>&nbsp;  [element $0-record data]<br>&nbsp;  |&nbsp; &nbsp; &nbsp; \<br>&nbsp;  [set $0-f x]<br><br>Then sorting is just a message "sort" to the subpatch receiver,<br>afterwards dump the lists again using basically the opposite from above.<br>You're only interested in the "data" array now.<br><br>Ciao<br>-- <br>Frank<br><br>_______________________________________________<br><a ymailto="mailto:Pd-list@iem.at" href="mailto:Pd-list@iem.at">Pd-list@iem.at</a> mailing list<br>UNSUBSCRIBE and account-management -&gt; <a
 href="http://lists.puredata.info/listinfo/pd-list" target="_blank">http://lists.puredata.info/listinfo/pd-list</a><br><br><br> </div> </div>  </div></body></html>