Difference between routines and naked global indicators
I am working on MUMPS in my recent project. I have a question regarding naked indicators. I am confused between routines a开发者_高级运维nd naked global references.
Can anybody help me to understand the difference between routines and naked indicators? The syntax for routines seems very similar to the syntax for naked indicators.
I'm not sure I fully understand your question, but I suspect you're referring to the fact that both Routine and Global references start with a caret (^).
Routines use the caret to distinguish between the routine and a label within the current routine. For example:
D COMPUTATION ; executes the COMPUTATION label in the current routine
D ^COMPUTATION ; executes the COMPUTATION routine
D SUBCOMP^COMPUTATION ; executes the SUBCOMP label in the COMPUTATION routine.
For variables, the caret indicates it is a global variable and not a local variable. This is the case whether you use naked references or not (this is where more clarification on your question might be in order, since as I understand it the reference being naked makes no difference). The difference being, of course, with the naked reference you can drop the variable name, and all but the last subscript of the global. For example:
S ^MYGLOB(1,1)="one"
S ^MYGLOB(1,2)="two"
is equivalent to
S ^MYGLOB(1,1)="one"
S ^(2)="two" ;naked, ewww
All that said, I would strongly advise against using naked references. They are intended to save time when entering code from the command prompt, but are very dangerous in code that has to be maintained. For example if a reference to ^OTHERGLOB were inserted between the two lines of code above, ^(2) would now reference ^OTHERGLOB(2), not ^MYGLOB(1,2). Not to mention, it's a pain to read.
精彩评论