Another way to get a macro to return a value using pass-by-name techniques

This is a tip. It's a different way of getting a macro to return a value. An hour ago I posted a method that will probably be frowned upon by the experts, but this method is very different and will probably be approved.

It's a lovely little macro containing three actions:

This gorgeous little macro works like a function that can return a value to a variable by letting you pass the name of the variable as the first parameter to the function, and the remaining parameter acts as the expression to be evaluated.

  1. The first action splits the parameters into a LocalVar and LocalExpression pair of variables.
  2. The second action evaluates the expression and saves it into a LocalResult variable.
  3. The third action saves the result into the LocalVar's evaluated variable name.

So here's one example of how to call it:

I suppose it would be easy enough to add a SWITCH statement that would let you replace the variable's name with certain non-variable concepts, perhaps like this:

In that case you would have to change the yellow action to something like this:

This idea has lots of potential. And it's a nice example of three disparate actions working together to create a seamless result.

I love KM and I love this website, but now I have to figure out how to upload this macro. I always have trouble figuring that out. But if I can't figure it out it's a very short macro to type in yourselves.

P.S. If you look carefully at the green action, you may notice a minor display glitch in the KM editor. I'm sure there's a perfectly good explanation for it, but it does appear a bit glitchy. It's probably a feature, or more likely a design decision, not a bug. But it's cute and intriguing.

It looks like I successfully uploaded this macro, but I am not skilled enough with this website to understand how to find the macro that I just uploaded so I'll leave that to someone else to explain. I apologize for lacking this basic knowledge.

Are you familiar with the KM Set Variable to Calculation action?

It does much of what your macro/script does, but all in one simple Action:


Yes I am aware of that. The point in putting it into a macro is to allow things to be placed in the macro that can't be placed into an expression. Things like loops, other actions, various external scripts. I guess the point I'm making is that now you can create long complicated functions within an assignment statement. KM lacks user-defined functions which can be placed into an expression. This essentially achieves that. Earlier today I posted an example of this, which is a macro that goes through a complex algorithm to find the best matching string and assign that to a variable. And to call that you need only a single action. You don't have to set up global variables, call the macro, and then reassign the global variables after the macro completes. But for those people who don't mind the extra steps, they can ignore this tip.

In my example above perhaps I should have added a pause action after the mouse movement action to illustrate this more clearly. Sorry.