Properly Erase Pattern Via Scripting?

I can’t get to erase patterns properly. Here’s my problem :

Starting with an empty song, I clone the first pattern (no 0) using I get a new pattern (no 1). I remove it from the sequence, using, then clear it with[]:clear. When I clone the no 0 pattern again, the new cloned pattern is no 2. But I expect it to be no 1, since I erased no 1 in every possible way.

I know we have the same problem when doing this without scripting, but at least we have the “Sort and Delete Unused Patterns” function. AFAIK, you don’t have access to this function from the API, and it would be more useful for scripting if you could delete patterns one by one.

Is there any workaround for this? Is it a planned feature?

Will automatically remove such empty patterns in “” in the next beta.