Parameter Passing
Rough Draft by David Whitten follows:
I was thinking about the issue of passing a variable name as an argument to a function.
I know I can't declare a subroutine as having a variable number of arguments, at least until we get that added in the next M standard. It was supposed to be part of the "Millenium Standard for the year 2000, but things didn't go as planned. So the next best thing is to just have a lot of named arguments. so the tag line for the subroutine with up to 26 arguments, named after the letters of the alphabet, could be something like:
TAG(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) ;
This should be no problem for a caller, as no experienced M programmer will expect any variables with a single letter name to be unchanged after a call to a subroutine. In the VA, the variable U must always be equal to the string "^" (ASCII 65) but this could be handled by prefixing all these names with the "%" (ASCII 37) so it could look like this:
TAG(%A,%B,%C,%D,%E,%F,%G,%H,%I,%J,%K,%L,%M,%N,%O,%P,%Q,%R,%S,%T,%U,%V,%W,%X,%Y,%Z) ;
Doing this means we could enhance our number of arguments to 36 since we could have the %variables that have simple numbers as well, eg: %0 through %9. Since the called program doesn't know how it is called, the calling code must determine that.
call by value, ie: $$TAG(15,,,,,"HELLO","World")
or call by array ie: $$TAG(PATIENT,,.MED,,.LABTEST)
Notice in the second call, that MED and LABTEST are local variables with a period before their name, and the variable PATIENT is being passed by value.
If we want to pass an global array like ^UTILITY($JOB) we could call the subroutine with the name of the global like $$TAG(,,,"^UTILITY($JOB)") . Now that we have the $NAME function in the 1995 M Standard, we can use it to call by name: $$TAG(,,,$NA(^UTILITY($J)),,,) The M Standard does allow us to not pass an argument, like I have used in the examples above with nothing between the commas. The problem is that if you don't pass anything in an actual argument then that named variable will be undefined. So the subroutine must process all the arguments in some regular way or you end up counting commas to know which variable you want to pass something useful in it.