<quote who="Adam T. Lindsay"> > I was wondering if there's a regular way of extracting the head and the tail > (meaning everything but the first element... think car/cdr) of an arbitrary > list message. I'm rooting through the docs, and am not able to come up with > an elegant way of doing this. (looked through the past two months of > archives, and didn't find much)
Use [niagara 1] of zexy. Send the list into the first inlet. The first element will come out of the first outlet and the rest of the list out the second. [niagara 2] would break the list in half at the second element. If you route the second outlet of [niagara n] into its own first inlet it will break a long list into many lists of length n. Very useful!
--andy
Andrew W. Schmeder andy@e-molecule.com
Hi. I'll try to handle both replies at once.
First, Frank Barknecht said this:
...results in a message of "bar baz" being sent to [r foo].
You might want to explore ";"-messages, like the well known [; pd dsp 1(
They work like named sends. If you have a colon message like:
[; $1 $2(
and you send it a list with, say, "volume 17" a receiver [r volume] will get the value "17".
Yep, that's precisely how I was handling my limited (static number of arguments) cases. It was kinda fun turning off the dsp from the command line. I managed the "car" case with [unpack s], but as you suggest, "cdr" isn't so easy.
Wll, with arbitrary lenght messages, the ";" trick will fail.
Precisely what I ran into, yes. For the curious, this is what I've come up with so far: http://www.comp.lancs.ac.uk/computing/users/atl/software/PD/net-dispatch.png
You might get a bit farther with [textfile]
Hmm. That's a new one to me. I'll have to look more into that--I wouldn't have guessed from the name.
Then, I believe Andrew W. Schmeder said this around Thu, 15 Aug 2002:
Use [niagara 1] of zexy. Send the list into the first inlet. The first element will come out of the first outlet and the rest of the list out the second. [niagara 2] would break the list in half at the second element. If you route the second outlet of [niagara n] into its own first inlet it will break a long list into many lists of length n. Very useful!
That sounds like useful function, but I'll need to try to recompile it for Mac OS X. Ahem. Any hints from anyone? I haven't had the time to try it yet.
Thanks for the advice, adam
Adam Lindsay +44(0)1524 594 537 atl@comp.lancs.ac.uk http://www.comp.lancs.ac.uk/computing/users/atl/ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=