Written by

UKK Köln
Question Dmitrii Baranov · Dec 14, 2025

Macroses with variable number of optional arguments

Hi,

I need a simple function for formatting a string, like in Python or C#. That's easy:

Class Very.Very.Long.Class.Name
{
ClassMethod Format(fmt As %String, args...) As %String [ Language = python ]
{
return fmt.format(*args)
}
}

To simplify calls, I want to wrap the function into a macro:

ROUTINE StringUtil [Type=INC]

#define FMT(%fmt,%a0)                                           ##class(Very.Very.Long.Class.Name).Format(%fmt,%a0)
/// #define FMT(%fmt,%a0,%a1)                              ##class(Very.Very.Long.Class.Name).Format(%fmt,%a0,%a1)
/// #define FMT(%fmt,%a0,%a1,%a2)                      ##class(Very.Very.Long.Class.Name).Format(%fmt,%a0,%a1,%a2)
/// #define FMT(%fmt,%a0,%a1,%a2,%a3)              ##class(Very.Very.Long.Class.Name).Format(%fmt,%a0,%a1,%a2,%a3)
/// #define FMT(%fmt,%a0,%a1,%a2,%a3,%a4)      ##class(Very.Very.Long.Class.Name).Format(%fmt,%a0,%a1,%a2,%a3,%a4)

The following code won't compile, IRIS fails with either "MPP5614 : Not enough arguments to macro: 'FMT'" or "MPP5613 : Too many arguments to macro: 'FMT'"

Set x = $$$FMT("{0} {1}", "Hello", "World")

It seems to me IRIS supports macro overrides, so if I uncomment that overrides then the .inc file gets compiled but the .cls file doesn't. Is this problem solvable at all?

Product version: IRIS 2025.1

Comments

Gertjan Klein · Dec 14, 2025

I'd just use def1arg:

#def1arg FMT(%parms) ##class(Very.Very.Long.Class.Name).Format(%parms)

(From memory, I don't have an instance to test available at the moment.) The macro 'intellisense' doesn't help with the parameters anymore, but in your case they are very easy to remember: format, args. I use something like this myself.

0
Dmitrii Baranov  Dec 14, 2025 to Gertjan Klein

Your macro works perfectly, thanks a lot!

0