I usually find ways to just avoid understanding message selectors in Pd, but I can't find a way around this.
[hottentot( | [add $1(
says "argument number out of range". How on earth can I add an arbitrary symbol to a line in a [textfile]?
-Chuckk
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.
On 8/6/06, Chuckk Hubbard badmuthahubbard@gmail.com wrote:
I usually find ways to just avoid understanding message selectors in Pd, but I can't find a way around this.
[hottentot( | [add $1(
says "argument number out of range". How on earth can I add an arbitrary symbol to a line in a [textfile]?
-Chuckk
-- "Far and away the best prize that life has to offer is the chance to work hard at work worth doing." -Theodore Roosevelt
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.
If you really don't want to know the details (but is http://puredata.info/dev/PdMessages too hard to understand?) and just have a good time with messages, a catch-all object to deal with this problem is [list].
It will work for float-messages, symbol-messages and meta-messages and generally do The Right Thing (tm)
[sonofa( | | [3.14( |/[what the heck( |/ [list] | [add $1(
will print: "add sonofa", "add 3.14" or "add what" depending on which message you clicked.
Note that you generally don't want to use [list] in front of [route]. There you generally want to have the opposite object: [list trim]. As in:
[list trim] | [route freq vol] | | |
Frank Barknecht _ ______footils.org_ __goto10.org__
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.
On 8/6/06, Chuckk Hubbard badmuthahubbard@gmail.com wrote:
I usually find ways to just avoid understanding message selectors in Pd, but I can't find a way around this.
[hottentot( | [add $1(
says "argument number out of range". How on earth can I add an arbitrary symbol to a line in a [textfile]?
-Chuckk
ola or just [symbol sonofa**( | [add $1(
should also work
$$$$$$$$$$aluti
mOritz
On 8/6/06, moritz erstens@gmx.ch wrote:
Chuckk Hubbard wrote:
I got it.
[sonofa( | [symbol] | [add $1]
ola or just [symbol sonofa**( | [add $1(
should also work
Well, I was actually using the output from another [textfile], so I'd have the same problem:
[textfile] | [symbol $1( | [add $1(
-Chuckk
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__
On 8/6/06, Frank Barknecht fbar@footils.org wrote:
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.
Wow, thanks, this does make sense now. I still don't grasp why and when Pd seems to arbitrarily insert the word "symbol" or "list" instead of treating the symbol as a meta-message...
Hallo, Chuckk Hubbard hat gesagt: // Chuckk Hubbard wrote:
I still don't grasp why and when Pd seems to arbitrarily insert the word "symbol" or "list" instead of treating the symbol as a meta-message...
There is nothing (too) arbitrary about it and it's especially not Pd itself that does this: Every object generates a certain kind of output. Some objects output symbol-messages (for example the [symbol] object always outputs symbol-messages), some objects send float-messages (like [float]) while some objects generate meta messages (message boxes can do so for example, or [list trim].) Also some objects accept only messages of a certain kind to certain inlets.
It's part of getting to know Pd and all its objects to learn which objects generate and accept which kinds of messages.
Additionally there are a two conventions on messages that start with a number: A number can never be at the start of a meta message (and thus form the "selector" of a message), only words can start a meta-message.
So while "float 2" is a full float-message, a single number like "2" also is a float-message. The selector "float" in this case is implied, so that you don't always have to type the "float" part.
The second convention is, that lists that start with a number, like "1 2 3" or "0 is zero" are considered list-messages even when the selector "list" at the start is missing. So these are equivalent:
"1 2 3" == "list 1 2 3" "0 is zero" == "list 0 is zero"
Much as with the "float 2" being equal to "2" here the "list"-selector is implied and can be omitted, if the first element is a number.
So basically that's all there is to know about messages in Pd:
bang-message: * "bang"
float-message:
symbol-message:
list-message:
list-messages with no or one element get "downcasted":
float message: "list 1" ==> "float 1" ==> "1"
symbol message: "list word" ==> "symbol word"
meta-message:
Print this. ;)
Frank Barknecht _ ______footils.org_ __goto10.org__
On Sun, 6 Aug 2006, Frank Barknecht wrote:
meta-message:
- (almost) everything else. ("almost" because there also are things like pointers or GemLists, which are even more special)
pointers are essentially on the same level as floats and symbols. Together they are the three main atom types of Pd and have corresponding reserved selectors and all assumed to have one argument.
gemstate messages (GEM), grid messages (GridFlow) and packet messages (PDP) are normal "meta-messages" in the sense that they don't correspond to one atom type of the same name. However, those three meta-messages carry abnormal pointer atoms: such pointers are not accepted by [get], [set] and even [list] ! That is because Pd's concept of pointer is too limited and also it doesn't allow externals to define their own atom-types.
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju | Freelance Digital Arts Engineer, Montréal QC Canada
Hallo, Mathieu Bouchard hat gesagt: // Mathieu Bouchard wrote:
On Sun, 6 Aug 2006, Frank Barknecht wrote:
meta-message:
- (almost) everything else. ("almost" because there also are things like pointers or GemLists, which are even more special)
pointers are essentially on the same level as floats and symbols. Together they are the three main atom types of Pd and have corresponding reserved selectors and all assumed to have one argument.
Yes, that's true, I didn't want to make it more complicated than needed for a simple explanation. It's important to note that one can build a list-message not only with numbers and words (or floats and symbols) as I wrote simplifyingly (is that a word?) but additionally also with pointers as list elements:
[pack float pointer]
would create such a list. This can be handy sometimes.
Frank Barknecht _ ______footils.org_ __goto10.org__
On 8/6/06, Frank Barknecht fbar@footils.org wrote:
Hallo, Mathieu Bouchard hat gesagt: // Mathieu Bouchard wrote:
On Sun, 6 Aug 2006, Frank Barknecht wrote:
meta-message:
- (almost) everything else. ("almost" because there also are things like pointers or GemLists, which are even more special)
pointers are essentially on the same level as floats and symbols. Together they are the three main atom types of Pd and have corresponding reserved selectors and all assumed to have one argument.
Yes, that's true, I didn't want to make it more complicated than needed for a simple explanation. It's important to note that one can build a list-message not only with numbers and words (or floats and symbols) as I wrote simplifyingly (is that a word?) but additionally also with pointers as list elements:
[pack float pointer]
would create such a list. This can be handy sometimes.
Once I understood what pointers are for, I never had any troubles with them. They don't impose themselves unless explicitly called for, and it's hard to ever mix them up with anything else. And, more to the point, if you pass a pointer message through a [pointer] object, as near as I can tell, it comes out exactly the same as it went in; not so with [symbol]. A pointer's usage is never determined by what object it comes from.
Easy there Frank! Even I'm starting to understand it, and then what will I have to whine about?
On Sun, 6 Aug 2006 15:36:55 +0200 Frank Barknecht fbar@footils.org wrote:
Hallo, Chuckk Hubbard hat gesagt: // Chuckk Hubbard wrote:
I still don't grasp why and when Pd seems to arbitrarily insert the word "symbol" or "list" instead of treating the symbol as a meta-message...
There is nothing (too) arbitrary about it and it's especially not Pd itself that does this: Every object generates a certain kind of output. Some objects output symbol-messages (for example the [symbol] object always outputs symbol-messages), some objects send float-messages (like [float]) while some objects generate meta messages (message boxes can do so for example, or [list trim].) Also some objects accept only messages of a certain kind to certain inlets.
It's part of getting to know Pd and all its objects to learn which objects generate and accept which kinds of messages.
Additionally there are a two conventions on messages that start with a number: A number can never be at the start of a meta message (and thus form the "selector" of a message), only words can start a meta-message.
So while "float 2" is a full float-message, a single number like "2" also is a float-message. The selector "float" in this case is implied, so that you don't always have to type the "float" part.
The second convention is, that lists that start with a number, like "1 2 3" or "0 is zero" are considered list-messages even when the selector "list" at the start is missing. So these are equivalent:
"1 2 3" == "list 1 2 3" "0 is zero" == "list 0 is zero"
Much as with the "float 2" being equal to "2" here the "list"-selector is implied and can be omitted, if the first element is a number.
So basically that's all there is to know about messages in Pd:
bang-message: * "bang"
float-message:
- messages starting with "float" (the selector) and after that one number
- single number (the selector "float" is implied here)
symbol-message:
- messages starting with "symbol" and after that one word
list-message:
- messages starting with "list" and after that several words or numbers
- messages starting with a number and after that several words or numbers (the selector "list" is implied here)
list-messages with no or one element get "downcasted":
- an empty list-message ("list" and then nothing) is equivalent to "bang"
- a 1-element list-message where the one element is a number is a
float message: "list 1" ==> "float 1" ==> "1"
- a 1-element list-message where the one element is a word is a
symbol message: "list word" ==> "symbol word"
meta-message:
- (almost) everything else. ("almost" because there also are things like pointers or GemLists, which are even more special)
Print this. ;)
Ciao
Frank Barknecht _ ______footils.org_ __goto10.org__
PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
On Sun, 6 Aug 2006, Chuckk Hubbard wrote:
[symbol]
Wow, thanks, this does make sense now. I still don't grasp why and when Pd seems to arbitrarily insert the word "symbol" or "list" instead of treating the symbol as a meta-message...
This is not a behaviour defined by the pd kernel, it's a behaviour defined by [symbol].
[symbol] has a wildcard method (aka "anything") which picks up any lone selector (except the ones that the wildcard can't catch, of course) and treats it as a symbol.
Personally, I don't like that behaviour, because it doesn't work for all possible selectors, and tends to confuse people on what a selector is.
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju | Freelance Digital Arts Engineer, Montréal QC Canada
On Sun, 6 Aug 2006, Chuckk Hubbard wrote:
I usually find ways to just avoid understanding message selectors in Pd,
The main obstacle to understanding selectors is not selectors themselves, it's people's belief that they shouldn't learn them.
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju | Freelance Digital Arts Engineer, Montréal QC Canada