if statement for list and how to represent an empty list
I'm a bit new to Max and excuse me if it's a stupid question.
I have a list of numbers stored in a message, and I need to get a slice of the list based on an integer value like this:
if i == 0
output empty
else
output the first i elements from the list
The context is that now I have two lists of notes represented in midi pitch for example list A {60 63 64} and list B {62 65 67}, and I want to output the first i elements from list A and j elements from B. i and j are the parameters set by the user and in reality either i and j could be 0 but not at the same time (i == 0 && j == 0 is not permitted). After that their output will be combined together.
Right now I'm trying implementing this with `zl slice`. Although it seems to be working, when i or j is zero, the output of its left outlet will not be updated and all elements go to the right outlet. In this case, whether if statement is necessary in order to achieve this purpose and how? More generally, I guess the question is about finding a good way to represent empty list in Max, for example how to properly implement the process of one non-empty list combining with another empty list?
you cant modify the input, only replace it with a constant.
to not output anything when a condition is not met, just dont use "else" at all.
It is a pity that Max does not deal with empty messages/lists, unless you use Javascript. I've had to find some "interesting" workarounds in such cases.
I've been playing around with a few things. The problem is that zl.slice will not generate any output if the message/list is empty! In this example, in the left column where the slice point is 0, zl.slice does not generate any output from the left outlet so even zl.len will output nothing either as it does not get triggered by any input. I've suggested a method to test the slice point for a zero slice - I don't know if you can use something like that?

If you can give a bit more detail about how you need to combine the list segments, I can modify this to generate the required output.
i think we´ve missed the last question until now. there is no such thing as an "empty list." and if something does not contain anything, you dont need to bother referencing it from somewhere else.
if you feel you want to send "nothing" to somewhere, you could use a placeholder (such as note number "777"), which can later be filtered out when needed. but i can assure that you sooner or later will find a solution how to patch the same without the need for "nothing".
I think this will do what you have described. You only need to work out how you will deal with the outputs!
I've added a couple of delays to eliminate a couple of situations where the sequencing gave odd results and added comments to (hopefully) make it a bit easier to understand:

NOTE: The input objects in the top row are only place markers that you will need to remove and replace with connections to your own code as required. The loadbang object only needs to be triggered once to ensure that the values for the second and third inlets of the if object on the right are primed with starting values. In the pasted patch the number objects are set so that they can't go below zero (configured at the bottom of the inspector window - you can set a maximum here too).
(See my next message for an improved version of this!)
If you really need to create and send an empty message, I came across this idea that I've tested and it actually works!

Here's the patch I posted previously that I have edited to incorporate this idea:
In case you are interested in looking at doing this in code, in Scheme there is such a thing as an empty list and you can do all manner of list processing very concisely. You might be interested in Scheme for Max, which makes this kind of coding very simple and vastly more readable (to me at least!) But then you do have to work in code.
Thanks Iain. The original post came from a beginner so I'm not sure how far he wants to go with this. Pity that he's not come back to give us any feedback yet!!!