(4 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
with '1 3' in the left inlet will give you the sum of 1 and 3. | with '1 3' in the left inlet will give you the sum of 1 and 3. | ||
− | Let's say we would like to only let lists of a certain length go through, you need to somehow get the list ''as a whole''. This can be done with $*i, which | + | Let's say we would like to only let lists of a certain length go through, you need to somehow get the list ''as a whole''. This can be done with $*i, which gets the input list at that specific inlet rather than the corresponding element from that list. |
($*1) | ($*1) | ||
Line 14: | Line 14: | ||
In this case, the order in which things get evaluated inside the ftm.mess object, is crucial. | In this case, the order in which things get evaluated inside the ftm.mess object, is crucial. | ||
− | The two $*1 statements are independent, in that there is, in this case, no operation that actually modifies the | + | The two $*1 statements are independent, in that there is, in this case, no operation that actually modifies the input variables ($1, $2...). |
− | So you can safely ask for the length of the input for use in the if statement and use | + | So you can safely ask for the length of the input for use in the if statement and use the input again to output if the statement is true. The problem in this case is that the list gets evaluated first and the first two elements are then used as the options for the if statement. So for example |
(if 1 $*1) | (if 1 $*1) | ||
+ | |||
with 4 5 6 as the input will give you 4, whereas | with 4 5 6 as the input will give you 4, whereas | ||
+ | |||
(if 0 $*1) | (if 0 $*1) | ||
− | |||
− | the 6 gets lost in this construction. | + | with the same input will give you 5. The 6 gets lost in this construction. |
So, what if we need to get ''the list'' through? | So, what if we need to get ''the list'' through? | ||
Line 29: | Line 30: | ||
(if ((llen $*1) == 3) {$*1}) --> this will work, but you end up with a tuple. So finally there are two ways to handle this inside the same object: | (if ((llen $*1) == 3) {$*1}) --> this will work, but you end up with a tuple. So finally there are two ways to handle this inside the same object: | ||
− | + | * check the output tuples as list checkbox in the ftm.mess inspector | |
− | + | * (l (if ((llen $*1) == 3) {$*1})) |
Latest revision as of 11:48, 5 August 2010
Working with inputs in the ftm.mess object is analogous to the standard Max message object: $1 refers to inlet 1 etc. Lists are also 'spread out', so
($1 + $2)
with '1 3' in the left inlet will give you the sum of 1 and 3. Let's say we would like to only let lists of a certain length go through, you need to somehow get the list as a whole. This can be done with $*i, which gets the input list at that specific inlet rather than the corresponding element from that list.
($*1) will output the input list.
Next, we check for the length and decide whether or not to output:
(if ((llen $*1) == 3) $*1) --> this will NOT work!
In this case, the order in which things get evaluated inside the ftm.mess object, is crucial. The two $*1 statements are independent, in that there is, in this case, no operation that actually modifies the input variables ($1, $2...). So you can safely ask for the length of the input for use in the if statement and use the input again to output if the statement is true. The problem in this case is that the list gets evaluated first and the first two elements are then used as the options for the if statement. So for example
(if 1 $*1)
with 4 5 6 as the input will give you 4, whereas
(if 0 $*1)
with the same input will give you 5. The 6 gets lost in this construction.
So, what if we need to get the list through? We have to make it an object and pass it as a whole. This can be any ftm.object, let's say a tuple:
(if ((llen $*1) == 3) {$*1}) --> this will work, but you end up with a tuple. So finally there are two ways to handle this inside the same object:
- check the output tuples as list checkbox in the ftm.mess inspector
- (l (if ((llen $*1) == 3) {$*1}))