Hallo, Chuckk Hubbard hat gesagt: // Chuckk Hubbard wrote:
I got it.
[sonofa( | [symbol] | [add $1]
I won't ask why, because I won't understand any more than last time I read it.
Let me try a longer explanation anyways. You may think, that [sonofa( is a symbol-message, however it isn't. As Moritz wrote [symbol sonofa( would be a symbol message that [add $1( can deal with correctly.
The difference should become clearer if you consider adding the word "set" to your textfile. If you would try to do that using your first approach it will have nasty results:
[set( | [add $1( | [textfile]
You know that instead of adding a line with the content "set" to your textfile it would just empty the add-message:
[set( | [ ( <= "And now all's gone." (Bender in "Futurama") | [textfile]
That is because "set" is a "method" of message boxes, just like "add", "add2" etc. Instead of being inserted in the place of "$1", these "method" messages make message boxes carry out certain other behaviours, like changing the content of a message box etc. These method messages are sometimes called meta-messages by Miller.
(Somehow messages starting with "symbol" also can be considered method messages, that make a message box carry out the behaviour they have programmed in for a "symbol"-meta-message and in this case make the message box send the incoming message along but replacing $-variables on the go. However messages starting with "symbol", "float" or "list" are so common in Pd, that they are generally referred to as symbol-, float- or list-messages explicitly.)
So to solve the problem of adding "set" to the [textfile] you need to convert the "set"-meta-message to a proper symbol- or list-message first, that is, convert it to something starting with "symbol" like "symbol set" or with "list" as in "list set". You can do this implicitly using [symbol] or [list] or by using [symbol set( explicitly as original message in the first place.
Taking this idea a bit further, "add" is a method-message for [textfile] as well: If you send an "add"-meta-message to [textfile] it will add a line consisting of everything, that follows the "add" in that message.
You can use this to your advantage by constructing the "add"-meta-message on demand using this idiom:
[list prepend add] | [list trim]
The [list prepend add] will convert everything that comes in into a list-message whose first element after the word "list" is "add".
For example:
[a b c( | [x( |/ [list prepend add] | [print]
will print:
print: list add a b c print: list add x
However this is a list-message, not yet an "add"-meta-message, because it starts with "list" not with "add"! To convert it to an "add"-meta-message just can trim off the "list" using [list trim] afterwards, so it prints:
print: add a b c print: add x
With [list prepend add]---[list trim] you can make an "adder" for a [textfile] that accepts input lists of arbitray length. (See attached patch.)
This is very handy not only for [textfile] but also for things like [netsend]:
"whatever ..." | [list prepend send] | [list trim] | [netsend]
Frank Barknecht _ ______footils.org_ __goto10.org__