Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples
Left Hand Pointer

$TEXT

M[UMPS] by Example

Right Hand Pointer

Introduced in the 1977 ANSI M[UMPS] language standard.

This function returns the text of a line of M[UMPS] code.

Assume that the following program is stored:

PGM  ;Author;Comment
     Set WHERE=$Text(+0)
1    Set Y=3 Write Y
     Read X
LAB1 Write !,X

$Text(PGM)="PGM ; Author;Comment"
$Text(LAB1)="LAB1 Write !,X"
$Text(PGM+1)="1 Set Y=3 Write Y"
$Text(+1)="PGM ; Author;Comment"
$Text(LAB1+1)=""
$Text(1+1)=" Read X"
Set B=3
$Text(+B)=" Read X"

If this program is executed, the value of WHERE, in the second line of the program, will become equal to the name of the routine ("PGM").

The following line of code will print a program:
For I=1:1 Set X=$Text(+I) Quit:X=""  Write X,!

Notes:
A line in a program looks like:

Optional: label with optional parameter list
Mandatory: line start character (space)
Optional: commands
Optional comment

This means that:

Many groups of programmers use conventions to make the content of the first line of a routine be according to a specific format, so that these "first lines" can be used for internal reports.

 Write !,"Routine",?12,"Author(s)",!  Set R="" For  Set R=$Order(^$Routine(R)) Quit:R=""  Do
 . Set x=$Text(+1^@R) Write !,R,?12,$Piece(X,";",2)

Note: Many of such conventions exist, and most can be supported by code written in ANSI standard M[UMPS]. The standard, however, does not endorse any specific format convention for the first line of a routine.

Assume that the the source code of a section of a routine looks like:

 ...
 For I=1:1 Set X=$Text(HDR+I) Quit:X=" --"  Write !,X
 ...
HDR ;
 End Of Year Report
 Section XXX
 --
 ...

The three lines that follow the label HDR do not conform to the syntax of a M[UMPS] routine, and may cause problems when loading the source code as a routine into a M[UMPS] environemnt.

Although this particular usage appears to have been quite popular at one time, there never was a language standard that supported such usage.

Methods of performing the intended task that do conform to the ANSI language standard would be:

 ...
 For I=1:1 Set X=$Text(HDR+I) Quit:X=" --"  Do
 . Write !,$Extract(X,3,$Length(X))
 ...
HDR ;
 ;End Of Year Report
 ;Section XXX
 ;--
 ...

Or simply:

 ...
 Do HDR
 ...
HDR ;
 Write!,"End Of Year Report"
 Write!,"Section XXX"
 Quit
 ...

Addition in the 1984 ANSI M[UMPS] language standard.

A special meaning is given to the reference $Text(+0). This reference will return the name of the currently executing routine.

Modification in the 1990 M[UMPS] language standard.

The 1984 language standard contained imprecise wording that indicated that the spaces for a line-start should be compressed in the function value and be represented as one single space. This wording was changed to reflect the original intent, which is to represent a line "as it is in the source code".

Addition in the 1995 ANSI M[UMPS] language standard.

The following line of code will print a program:
For I=1:1 Set X=$Text(+I^ROUT) Quit:X=""  Write X,!

Note: a reference like +OFFSET^ROUTINE is acceptable as a parameter for $Text, but not as an argument for the commands Do and Goto.

Approved for addition in a future M[UMPS] language standard.

Trailing spaces are allowed at the end of a line.

This means that it would be valid to create a routine containing commands like (in subroutine A the character ¤ has been used to make all space characters visible):

Xecute $Text(A+1)_$Text(A+5)
...
Quit
A¤;
¤Set¤START=1¤¤
¤Do¤VALIDATE1¤¤
¤Do¤VALIDATE2¤¤
¤Do¤QUERY7¤¤
¤Do¤RESET9¤¤
¤Do¤VALIDATE11¤¤
¤;;¤--¤end

and the code that would be Xecuted would be:

¤Set¤START=1¤¤¤Do¤RESET9¤¤

Examples with naked references:

$Text(LINEREF)
Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set ^(3,4)=$Text(@^(5,6))

; 1. fetch ^(5,6) = ^ABC(1,5,6)
; 2. store ^(3,4) = ^ABC(1,5,3,4)
; naked indicator is now: ^ABC(1,5,3,

Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

Copyright © Standard Documents; 1977-2017 MUMPS Development Committee;
Copyright © Examples: 1995-2017 Ed de Moel;
Copyright © Annotations: 2003-2017 Jacquard Systems Research.

The information in this page is NOT authoritative and subject to be modified at any moment.
Please consult the appropriate (draft) language standard for an authoritative definition.

Some specifications are "approved for inclusion in a future standard". Note that the MUMPS Development Committee cannot guarantee that such future standards will indeed be published.

This page most recently updated on 13-Sep-2014, 17:33:50 .

For comments, contact Ed de Moel (demoel@jacquardsystems.com)