Non-numeric Array subscripts

Oct 18, 2009
358
17
Check out a language called MUMPS. MUMPS - Wikipedia
It's my understanding that a Computer Sciences professor has recreated all the functionality of MUMPS in various C or C++ routines.

The language has very few commands and functions, so it can literally be learned in one day. Except for one or two commands/functions, each command or function can be abbreviated to a single letter, e.g., S X=''X

That means Set X equal to NOT NOT X. (Those are 2 single quotes.)

Why? S X=5
NOT X will be zero.
NOT (this new) X will be ONE, meaning "true".

So S X=''X is a normalization routine. It could also be written SET X=''X

MUMPS stores ALL data in variables. A variable on disk (called "global") begins with ^, a memory variable (called "local") doesn't.

So: SET X=5 creates a memory variable. SET ^X=5 creates a variable on disk.

A major difference between MUMPS and other languages is array subscripts can be non-numeric:

SET ^PATIENT("name", "surname")="Smith"
That will create a variable on disk named ^PATIENT, with a node ("name", "surname")

The arrays are sparse arrays--so you only have the final node, not:
^PATIENT
^PATIENT("name")

^PATIENT("name", "surname")

You cycle through the subscripts (whether numeric or not), with the function $ORDER. You determine whether a node exists and some additional information with $DATA.

The subscript names can be held in variables, i.e., ^PATIENT(name, surname) is not the same as ^PATIENT("name", "surname").

=============
I do realize the "text names" functionality could be done with current TCC by creating a bunch of variables and substituting those, e.g.,

set name=1
set surname=2

then create a PATIENT array variable and access it as:

PATIENT[name, surname]
 
Last edited:
Oct 18, 2009
358
17
It might be possible to set up this functionality using parts of the LIBRARY system.

External to the library-type function, the user could define alphanumeric subscripts such as "name" and "surname" in Set Patient[name, surname]=Smith

But internally, the function would either assign "name" and "surname" to numbers, e.g., Patient[1,2] or just assign the whole thing to a regular variable: Set Patient_name_surname=Smith

Then for echo Patient[name, surname] the library-type function would look it up and return the value.

"Just assign to a regular variable" is probably preferable, because MUMPS is based on sparse array technology and TCC isn't.

To avoid misinterpretations, the main variable names should have to begin with a non-alphanumeric character, e.g., Set ^Patient[name, surname]=Smith
 
Oct 18, 2009
358
17
Regarding using a library-type approach, just so we're clear:

MUMPS data could produce an array like this:

{not created}^PATIENT
{not created} ^PATIENT("Demographics")

^PATIENT("Demographics", "Name_Info")="Smith, John"

{not created}^PATIENT("Demographics", "Address")
{or} ^PATIENT("Demographics", "Address")=""

^PATIENT("Demographics", "Address","Street")="123 Jones St"
^PATIENT("Demographics", "Address","City")="Charleston"
^PATIENT("Demographics", "Address","State")="South Carolina"
^PATIENT("Demographics", "Address","ZIP")="32768"

{not created}^PATIENT("Insurance")
^PATIENT("Insurance", "Address","Street")="3210 Maritime St"
^PATIENT("Insurance", "Address","City")="Cleveland"
^PATIENT("Insurance", "Address","State")="Ohio"
^PATIENT("Insurance", "Address","ZIP")="22478-3690"

^PATIENT("Insurance", "Name")="BigTime Health Insurer"

( The carat is pronounced "hat" and the functions are pronounced "dollar", e.g., "hat PATIENT sub Insurance, sub Name" and $DATA is "dollar DATA".)


The $DATA function would return whether a node exists and some additional data, e.g., there is no ^PATIENT("Insurance", "Claim Info") node.

The $ORDER function cycles through the node, e.g., it could find the next node in after ^PATIENT("Insurance", "Address"), which would be ^PATIENT("Insurance", "Address","City")

A problem with just setting up a bunch of traditional variables such as Set PATIENT_insurance_address_street=3210 Maritime St is there's no way to cycle through the "_address_" node.

---------------
By the way, in practice a MUMPS data node normally would be in the form:

^PATIENT("Insurance")="BigTime Health Insurer^!3210 Maritime St^!Cleveland^!Ohio^!22478-3690"

where ^! is the user-defined field separator, and you extract a segment with Set X=$PIECE(^PATIENT("Insurance"), "^!")