dear all, i'm wondering how to get a default value for an abstraction argument that is not specified. eg: my abstraction [equality] can take 3 arguments, but i don't want to *have* to type the arguments, in which case the abs should use a default value. i came up with the following solution:
[loadbang] | [$1] | [moses 1] | | [t b] / | / | / |/ [f 440] <-- default value
i'm not sure how elegant this is, really. any thoughts? cheers, robbert
Hallo, robbert van hulzen hat gesagt: // robbert van hulzen wrote:
dear all, i'm wondering how to get a default value for an abstraction argument that is not specified. eg: my abstraction [equality] can take 3 arguments, but i don't want to *have* to type the arguments, in which case the abs should use a default value. i came up with the following solution:
[loadbang] | [$1] | [moses 1] | | [t b] / | / | / |/ [f 440] <-- default value
i'm not sure how elegant this is, really.
Almost as elegant as possible with current Pd: Arguments, that you don't specify, get initialized as 0. So instead of [moses 1] you could also use [select 0] and omit the [t b].
To also be able to leave arguments empty that are intented to become symbols, you could use this idiom:
[loadbang] | [list append $1] | [select 0] | | | "by argument" | "default"
Also see the abstraction any_argument.pd in CVS/abstractions/purepd/
Frank Barknecht _ ______footils.org_ __goto10.org__
On Mon, 23 Jul 2007, Frank Barknecht wrote:
Almost as elegant as possible with current Pd: Arguments, that you don't specify, get initialized as 0.
That's not strictly true: if a dollsym gets expanded using nonexistent arguments, those parts do not get replaced.
A_DOLLAR atoms are atoms that are just $0 $1 $2 $3... without anything to the left or right (nonbackslashed commas-or-semicolons count as delimiters). Expanding an A_DOLLAR gives exactly what the argument passed was. In that context, nonexistent arguments become zeroes.
A_DOLLSYM atoms are atoms that are mixed symbol parts and dollar parts. Before 0.40 this instead was only one dollar part followed by one symbol part. In that context, nonexistent arguments stay exactly like they are. (Instead I would've guessed empty symbols, but Pd isn't that consistent when it comes to dummy symbols)
BTW, this can lead you to a way to figure out for sure whether a certain argument was supplied or not, by checking the discrepancy between A_DOLLAR and A_DOLLSYM, but that's quite twisted.
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801, Montréal QC Canada