Hi,
is there a way (preferably vanilla) to collect all the arguments of an abstraction into a list? Something like:
The number of arguments is not fixed.
Thanks in advance for your help.
Collect all arguments as a list
Hi,
is there a way (preferably vanilla) to collect all the arguments of an abstraction into a list? Something like:
The number of arguments is not fixed.
Thanks in advance for your help.
@weightless the safe way to get floats as well as symbols is [list append $1 $2 $3]
. To write "list append" not just "list" is the important part here (list prepend also works).
i think it is not possible to get the number of arguments in vanilla.
Possible solutions in vanilla:
In iemlib there is [dollarg], which does it.
@ingox Thanks for the explanation, they are all good methods although unfortunately the arguments can be zero.
For now I wouldn't mind using an external if there is one just to get it going, but [dollarg] does not create. In fact, there is only the help file in the library I have downloaded and I'm not sure why.
EDIT: I downloaded the other version of iemlib from Deken and this one works. Thanks, I will use [dollarg] for now. If anybody else can come up with a universal way to do it vanilla-style that would be very interesting, but like you said it mightn't be possible.
Pd Vanilla only has one way to do that-- exploit the inconsistency in dollsymarg and dollararg expansion for non-existent abstraction arguments.
For example-- suppose our parent abstraction is [foo 0]. Inside that abstraction we try [list append $1]
which gives "0". We also try [list append $1-sym]
which gives "0-sym". But we don't know if that means the abstraction arg was zero or there was no abstraction arg given.
So let us try abstraction [foo]
with no args. Now inside foo we create [list append $1]
which again gives us "0". That's no help at all. But now look at the output from [list append $1-sym]
:
symbol \\$1-sym
When "$1" doesn't exist, Pd's string concatenation algorithm doesn't expand the dollararg to 0 but instead quotes it directly. Weird.
So now we've got an algorithm for finding the length of the list of args, which consequently means we can reproduce that list of args inside the abstraction:
(pseudocode)
check if [list append $1]--[$1-sym( is equal to [list append $1-sym]
if it isn't then you've got one less arguments than the dollararg you tried.
if it is equal then "add2" the value of the dollararg into a msg box and try with the next biggest dollarsign variable
...
at the end, bang out the msg box to get the full list of args
Notice that you must do this inside the canvas or subcanvas where you want to get the arguments. So you cannot modularize this algorithm inside an abstraction-- you must always paste a subpatch inside the relevant abstraction.
Or in Purr Data you can just do this:
[list append $@]
or this:
[args(
|
[canvasinfo]
@jancsika This is a great trick, thanks for taking the time to explain it. I got it to work by patching your algorithm, here it is:
This obviously needs to iterate a given number of arguments, which are pre-typed in the two [list append] objects. One step further would be to be able to have an indefinite number of arguments, and retrive the next one after each step. I tried like this and it doesn't work:
(and obviously break the [until] loop after the first non-match), but I don't think it's possible to set [float] or [list] to $n via the right inlet, but I'd love to hear if somebody knows how to.
The only other two ways I can think of to get around this is to either create each [list append $n] dinamically (might get tricky) or to just use the approach in the patch and pre-set the [list append]s to the maximum number of possible arguments an object can have (don't know if there is such a thing).
There are two demos floating around on Pd user list-- one by Matt Barber and another by me. We both had to resort to dynamic patching, which is indeed tricky.
@weightless Here is yet another solution:
This also uses dynamic patching and the trick @jancsika described above.
@ingox This is excellent, and it works with nested arguments as well.
Thanks a lot everyone!
I've updated @ingox patch so now it works similar to [dollarg] and can output individual arguments as well. See inside the patch for more info.
Here is the solution of Jonathan Wilkes (i guess that is you, @jancsika):
creationargs.zip
from https://lists.puredata.info/pipermail/pd-list/2009-04/069941.html
It is shorter and more elegant than mine.
@ingox this gets better and better! here is the patch updated with the shorter code:
Thanks again everyone, this looks reliable enough to be used instead of the external.
updating the conversation to say vanilla now has had [pdcontrol] for that for a while
Oops! Looks like something went wrong!