Question
· 7 hr ago

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
Discussion (0)1
Log in or sign up to continue