Creating a Simple Pushdown Stack

YES! I had indeed forgotten. I had been looking at Filtering the variable with a Line Count filter. But the filter will actually go through and count the lines, one by one. The [0] syntax refers to a value that is already automatically there, and therefore will execute marginally faster.

Thank you!

Pardon the sloppy terminology, I was trying to point out my sloppy thinking and the erroneous assumption that lead to a bug that was hard to find.

Yes, it behaves like a variable and KBM will assign a value to the array element, within the existing variable, even if that array element does yet exist. If the array is not long enough, KBM make it long enough in order to be able to assign the value.

I just did a simple test of how KBM handles this:
image

The variable did not exist before I ran this action using the Try button.

Here is what I got:
image

There are 24 commas in that string, as delimiters for 25 array items.

In another thread somewhere here, Peter explains that this is expected ... a coming update (maybe the one that just came out?) will limit it to creating 100 elements, if I recall correctly.

-rob.

Peter mentions that here

I remarked on the extension of an array if you write to a non-existing element in my post

Yes, I think it should definitely be expected, I just didn't think it through and when I figured it out it was a "Doh!" moment.

I read that post and at this point I guess it seemed so obvious, at the moment that I read it, that it didn't stick.

1 Like

Another BUG in the previous pushdown stack subroutine, with a simple fix:

Using the Preferences > Variables window I started seeing a final entry in the list that consisted of one long string of every item, with no delimiters, just 8, 12, 20, or whatever items run together as a single item. WTF? Except for that, it's been doing it's job, in the background, mostly being used to switch to the previous desktop.

I was contemplating creating a log that would have entries every time the variable changed so that I could match up when it happened to the KBM Engine log and have a clue. Then in adding comments to the subroutine, to walk through how it works, I found the answer. It's in the removal of the new item from its previous place in the list.

image

I realized that if the variable theNewDeskSpaceID was empty (or non existant) then this would do exactly what I was seeing. It would remove every Return from the variable. Then the next time the subroutine was called, new entries would be added to the front, and this would stay at the bottom of the list.

Wrapping it in an If/Else seems to have done the trick.

image