Feature Request: Token That Executes a Subroutine and Uses The Return Result

@peternlewis I know this is esoteric, but I'd love to have a token that executes a subroutine and uses the return result. It might even, theoretically, allow you to pass parameters, but I'm not sure how you would implement that.

So there would be a token like %ExecuteSubroutine%uuid% or %ExecuteSubroutine%My Subroutine% which would return the value of the "Return" action.

Here's what sparked this idea: I was wishing there was a token like %ExecutingMacro% that stripped out the palette order numbers, if any. So instead of this:

image

I could get this:

image

I'd still like that.

But obviously, I wrote a macro to give me the %ExecutingMacro% value without the order number. Which works fine, but I have to store it in a variable, and make sure I do it at the top of the macro, so I can use it whenever I need it. No big deal, I know.

But if there was a token that called my subroutine and returned the result, I could roll my own tokens for this, and other things.

I don't know how many people would use something like this. I know I'd use the crap out of it, but who knows about other people. Just a thought. Wouldn't want your "to do" list to get too short. :joy:

1 Like

I, too, see some value in this. Basically what you want is "functions" implemented as "tokens." Personally, I find the token syntax to be unwieldy, especially when you have to nest percent symbols (like we already have to do with Dictionaries.) But tokens are the only syntax that makes sense when the return values is a string. Most of my subroutines (that I write) would return numbers (of course, strings that represent numbers) so I would prefer a syntax that allows me to call a macro inside a calculation, like this:

10 + 20 * MyMacroFunction(123,456)

But I'm not expecting this type of thing to get implemented. Not anytime soon.

1 Like

It is not possible.

Tokens have to return their results immediately, and the engine is locked up while they do it, so it could not run a macro to return a token result.

2 Likes