Macro for POP and PUSH

KM has some support for variables which contain a list of numbers, but I decided to add a couple of macros to allow people to create a "stack" data structure using lists as the underlying mechanism. (There is no limit to the number of stacks, the user specifies the stack's name.) I could not find macros to do this anywhere on line so here's my contribution on this topic. Even if it has already been done, I learned some things writing these macros:

Here is the PUSH macro:

Here is the POP macro:


Some Notes:

  1. Since KM doesn't support functions (sigh) POPping is a two step process: (a) fetching the value and then popping the stack, like this:

  1. I seemed to be unable to pass Local variables to the Applescript action (not sure if it was my fault or if that's a limitation of KM) so instead of using Local variables I added a Semaphore at the top to avoid potential problems if you use concurrent macros which call these macros. I hope someone lets me know if I can pass Local variables to the Applescript action.

  2. Pushing is exactly as you would expect: (I use the clock in seconds for my example data below)

  1. A queue would be almost identical to a stack, but the code would have to be changed a little bit.

  2. It's possible that some of you might be able to improve my code. If you can, let me know. Have I overlooked anything?

  3. As I sit here and contemplate what I've written, I realize I used two different mechanisms to achieve the same thing. In the PUSH macro I used two levels of indirection within Applescript to get the contents of a variable, while in the POP macro it seems that I used a KM filter to achieve the same thing. Both methods work, and using two different methods on this post may actually prove to be educational so I'll leave them as they are. No doubt my code can be modified or improved, but I'm posting it here as an example.