home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / b037_1 / !MUMPS_UserDoc_Express < prev    next >
Encoding:
Text File  |  1992-12-29  |  13.9 KB  |  331 lines

  1.  
  2. Archimedes MUMPS v1.0 documentation
  3.  
  4.  
  5. MUMPS EXPRESSIONS
  6.  
  7.  
  8. In MUMPS expressions are evaluated from left to right, treating every
  9. operator ('+','*','/' etc) with the same priority, so "2+3*4" evaluates to
  10. 20, not 14 as in most languages. The one way to change the evaluation order
  11. is to use "(<expression>)", the <expression> will be evaluted as if it were
  12. an atomic expression. So if you want "2+3*4" to be 4, write "2+(3*4)".
  13.  
  14. Another feature of MUMPS that there is only one datatype, the string (or you
  15. could say that all variables are polymorphic: they can have string values,
  16. integer values and floating point values (not at the same time of course!)).
  17. Any conversions that are necessary are automatically performed by the
  18. MUMPS-interpreter. As an example, "2+"12.34"*2" evaluates to 28.68, and
  19. "1+"1017KH"" evaluates to 1018.
  20.  
  21. The syntax for <expression> is <expratom>[<rest of expression>].
  22. <rest of expression> can be either:
  23. _<expratom>
  24. <arithmetic operator><expratom>
  25. <boolean operator><expratom>
  26. '<booleanoperator><expratom>
  27. ?<pattern>
  28. '?<pattern>
  29.  
  30. The '_' operator concatenates strings, i.e. 12_45 evaluates to "1245".
  31.  
  32. An arithmetic operator is one of: +,-,*,/,\,#.
  33. In a<operator>b the operators act as follows:
  34.  
  35. +  adds a to b
  36. -  subtracts b from a
  37. *  multiplies a and b
  38. /  divides a by b
  39. \  takes the integer part of a/b
  40. #  calculates a modulo b and is defined: A#B=A-(B*floor(A/B))
  41.  
  42. A <boolean operator> evaluates a<boolean operator>b to 0 (zero) or 1 (one):
  43. <  1 if a<b
  44. >  1 if a>b
  45. =  1 if a=b (on a character by character basis, "0.0"<>0)
  46. [  1 if a "contains" b (e.g. "Hahahaha"["ahahah"=1)
  47. ]  1 if a "follows" b in the ASCII character set
  48. &  1 if the boolean interpretation of a and b, a' and b' resp. evaluate to 1
  49.         when ANDed. (boolean interpretation: a==0 ? 0 : 1)
  50. !  1 if the boolean interpretation of a and b, a' and b' resp. evaluate to 1
  51.         when ORed.
  52.  
  53. The "'" operator inverts the value of a boolean expression.
  54.  
  55. The pattern match operator tries to match a string with a specified pattern.
  56. A pattern consists od a string a or (a) code(s) (one of C,N,P,A,L,U,E)
  57. preceded by a repetition count. A repetition count looks like this:
  58. integer
  59. |[integer].[integer]
  60. so either "1", "1.","1.2",".2", or just "." will do. A repetition count
  61. specifies how many times the following code(s) (or string) must (or may) be
  62. used in matching the string. The meaning of the codes is:
  63. C :matches ASCII control characters
  64. N :matches ASCII numeric characters
  65. P :matches ASCII punctuation characters
  66. A :matches ASCII alphabet characters
  67. L :matches ASCII lowercase alphabet characters
  68. U :matches ASCII uppercase alphabet characters
  69. E :matches any ASCII character
  70.  
  71. A string in the pattern matches an exact copy of that string only.
  72.  
  73. As an example: consider checking a Dutch 'postcode', it consists of 4
  74. numerics and 2 uppercase letters. You can check if the variable A is a valid
  75. 'postcode' by evaluating "A?4N2U". To check that A contains at least 1 digit
  76. and at most 4, evaluate "A?1.4N". Very complex patterns can be specified
  77. which give you a very powerful tool for input-checking.
  78.  
  79.  
  80. EXPRESSION ATOMS
  81.  
  82. An <expratom> in MUMPS is one of the following:
  83. - a numeric like 12 or -0.1 etc.
  84. - a string like "This is a string"
  85. - a MUMPS special variable
  86. - a MUMPS function
  87. - an expression enclosed in '(' and ')', e.g. (2*3-A)
  88. - a unary operator followed by an <expratom>:
  89.         '<expratom>,
  90.         +<expratom> or
  91.         -<expratom>
  92. - a local variable (possibly indirected)
  93. - a global variable (possibly indirected)
  94.  
  95. Variable names must start with a '%' or an alphabet character and may
  96. otherwise consist of numeric or alphabet characters.
  97. Global variable names are preceded by a '^' character.
  98.  
  99.  
  100. MUMPS SPECIAL VARIABLES
  101.  
  102. MUMPS recognises a few 'special variables' that can be used in expressions
  103. just like normal variables, but whose names start with a '$'. They are a
  104. kind of MUMPS functions, but need no parameters for calculating their value.
  105. The 'special variables' are:
  106.  
  107. $H[OROLOG]
  108.         $H returns the date and time in the following format:
  109.         <days since January 1, 1841>,<seconds since last midnight>
  110.         You can convert +$H (or any other date) to a readable dateformat
  111.         using the routine %DAT, supplied with Archimedes MUMPS.
  112.  
  113. $I[O]
  114.         $I contains the current device number.
  115.  
  116. $J[OB]
  117.         $J contains the JOB number of the JOB that executes the $J.
  118.  
  119. $S[TORAGE]
  120.         $S contains the amount of memory free for use in the partition that
  121.         executes the $S. $S is not exactly defined, the suggestion in the
  122.         MUMPS standard is not followed by Archimedes MUMPS. $S contains the
  123.         amount of memory free for routines or stack, local variable space is
  124.         not taken into account when calculating $S.
  125.  
  126. $T[EST]
  127.         $T contains either 0 (zero) or 1 (one). $T is set by executing an IF
  128.         command, a LOCK, OPEN or READ command. For example, if X=2 and you
  129.         write: "IF X=3 W *7" no BELL will sound and $T will have the value
  130.         0.
  131.  
  132. $X
  133.         $X contains the current device x-coordinate. For example,
  134.         "W #?10 W $X" will print 10, because the current y-coordinate is 10
  135.         at the time when $X is evaluated.
  136.  
  137. $Y
  138.         $Y contains the current device y-coordinate. For example,
  139.         "W #!!! W $Y" will print 3, because the current y-coordinate is 3
  140.         at the time when $Y is evaluated.
  141.  
  142. $Z
  143.         $Z special variables are covered in the file "Z".
  144.  
  145.  
  146. MUMPS FUNCTIONS
  147.  
  148. MUMPS also recognises functions, whose names start with a '$', just like
  149. special variables. The functions are very powerful and make data
  150. manipulation extremely easy. Especially the $DATA, $ORDER and $PIECE
  151. provide easy access and manipulation of your databases. The MUMPS functions
  152. are:
  153.  
  154. $A[SCII](<expr 1>[,<expr 2>])
  155.         $A returns the ASCII value of the first character of <expr1>, or the
  156.         n-th character, if <expr 2> is present and evaluates to an integer
  157.         n. IF n<1 or n>$L(<expr 1> then $A returns -1.
  158.  
  159. $C[HAR](<integer expr>[,<integer expr>])
  160.         Builds a string whose characters are the ASCII characters
  161.         corresponding to the numbers in the arguments. Integers outside the
  162.         range [0,127] are skipped.
  163.  
  164. $D(ATA](<local or global variable>)
  165.         Returns a number indicating existence of the variable and it's
  166.         descendants. Suppose D is the value of $D and set to 0 (zero). If
  167.         the variable exists, 1 (one) is added to D. If any descendant
  168.         exists, add 10 to D. Then, D is the value of $D().
  169.  
  170. $E[XTRACT](<expr>[,<integer expr 2>][,<integer expr 3>])
  171.         $E extracts a substring from it's first argument. Let n be the
  172.         value of <integer expr 2> (or 1 if only one argument is specified)
  173.         and m be the value of <integer expr 2> (or n if not specified). The
  174.         substring starts at position n and ends at position m. Naturally,
  175.         the result of $E is the empty string if m<n or n>$L(<expr>).
  176.  
  177. $F[IND](<expr 1>,<expr 2>[,<integer expr>])
  178.         $F finds a substring sub (<expr 2>) in target (the first argument),
  179.         starting at position n (<integer expr 3>), or 1 if n<1 or n is
  180.         absent. If n>$L(target) or sub is not found in target, $F evaluates
  181.         to 0 (zero). If not, $F returns the starting position of the
  182.         leftmost occurrence (starting at n, of course) plus the $L(sub) plus
  183.         1 (one).
  184.  
  185. $FN[UMBER](<numexpr>,<expr>[,<integer expr>])
  186.         $FN formats numbers. Let n be the value of <numexpr>. The two
  187.         argument form uses <expr> as a 'formatting string' for n. The
  188.         following formatting codes are allowed in <expr>:
  189.  
  190.         P : put negative numbers between parentheses (and positive numbers
  191.                 between spaces). So, if n<0 then the result will be:
  192.                 "("_|n|_")" (|n| means absolutevalue of n), otherwise the 
  193.                 result is: " "_|n|_" ".
  194.  
  195.         T : trail signs (either '-', '+' or ' ' (in case no sign is to be
  196.                 displayed)).
  197.  
  198.         , : Insert a comma every three digits left of the decimal point.
  199.  
  200.         + : Use a '+' sign for positive numbers.
  201.  
  202.         - : Do not display a '-' sign for negative numbers.
  203.  
  204.         Multiple occurrences of the same formatting code have the same
  205.         effect as just one such code. The empty formatting string leaves the
  206.         numbers representation unchanged. Use of non-defined codes or use of
  207.         the "P" code togehter with "T","+" or "-" generates an error.
  208.         $FN always puts a '0' in front of the decimal point if -1<n<1.
  209.  
  210.         The three rgument form does the same as the two argument form, but
  211.         first the number is rounded to <integer expr> places.
  212.  
  213. $G[ET](<local or global variable>)
  214.         $G returns the value of the variable or the empty string if the
  215.         variable does not exist.
  216.  
  217. $J[USTIFY](<target string>,<integer expr 1>[,<integer expr 2>])
  218.         Let A1 be the targetstring, A2 the value of the second argument and
  219.         A3 the value of the third argument. If 3 arguments are specified,
  220.         the numeric interpretation of A1 is taken and N2 specifies the field
  221.         width and N3 specifies the number of decimal places.
  222.         If only two arguments are given spaces are added (if necessary) at
  223.         the front of A1 to make a field width of A2 places.
  224.  
  225. $L[ENGTH](<expr 1>[,<expr 2>])
  226.         The one-argument form returns the number of characters in the string
  227.         <expr 1>.
  228.         The two argument form returns the number of non-overlapping
  229.         occurrences of <expr 2> in <expr 1> plus 1 (one). If <expr 2> is the
  230.         empty string, $F returns 0 (zero).
  231.  
  232. $N[EXT](<local or global variable>)
  233.         $N is almost the same as $ORDER (but more limited). Instead od
  234.         'starting' with an empty string,$N 'starts' with -1. Instead of
  235.         ending with an empty string $N ends with -1 too. Not nice if you
  236.         have "-1" as a legal subscript in your database. Do NOT use $NEXT,
  237.         it will be removed from MUMPS in a future standard!
  238.  
  239. $ORDER(<local or global variable>)
  240.         $O gives 'the next subscript in the database'. That is, if the
  241.         variable looks like this: name(s1,s2,...,sn), $O returns the
  242.         subscript that 'follows' subscript sn immediately. Numeric
  243.         subscripts precede string subscripts. The empty string
  244.         precedes all other legal subscripts. Example: if you have the
  245.         following database:
  246.         ^A(-100)=1000
  247.         ^A(-10)=100
  248.         ^A(-1)=10
  249.         ^A(10)=-100
  250.         ^A("HUIB","VERWEIJ")="Human"
  251.         ^A("PIMMETJE","VERWEIJ")="Cat"
  252.         ^A("ZZZ")="YYY"
  253.         then the follwoing code will list all first subscripts:
  254.         S N1="" F  S N1=$O(^A(N1)) Q:N1=""  W N1," "
  255.         The following string will be written to the current device:
  256.         "-100 -10 -1 10 HUIB PIMMETJE ZZZ ".
  257.         The follwing code will write all data to a depth of two:
  258.         S N1="" F  S N1=$O(^A(N1)) Q:N1=""  W:$D(^(N1))#10 ^(N1)," " S N2=""
  259.          F  S N2=$O(^A(N1,N2) Q:N2=""  W:$D(^(N2))#10 ^(N2)," "
  260.         The following string will be written to the current device:
  261.         "1000 100 10 -100 Human Cat YYY ".
  262.  
  263. $P[IECE](<target string>,<delimiter string>[,<start>[,<end>]])
  264.         $P uses the delimiter to partition the targetstring. It returns the
  265.         substring from target string that includes partition start and
  266.         includes partition end. If absent, 1 (one) is used for the third
  267.         argument and the fourth argument is equal to the third.
  268.         Examples:
  269.         $P("AB*CD*EF*","*")      = "AB"
  270.         $P("AB*CD*EF*","*",1)    = "AB"
  271.         $P("AB*CD*EF*","*",1,2)  = "AB*CD"
  272.         $P("AB*CD*EF*","*",2,3)  = "CD*EF"
  273.         $P("AB*CD*EF*","*",2,4)  = "CD*EF*"
  274.         $P("AB*CD*EF*","*",4)    = ""
  275.         $P("AB*CD*EF*","*",5,10) = ""
  276.  
  277. $R[ANDOM](<integer expr>)
  278.         $R returns an integer in the interval [0,N-1], where N is the value
  279.         of it's argument.
  280.  
  281. $S[ELECT](<boolean expr>:<expr>[,<boolean expr>:<expr>])
  282.         $S selects one of it's <expr> arguments. The one selected is the
  283.         first one with a boolean that evaluates to true. It is an error when
  284.         no such <boolean expr> is given. <expr> arguments are not evaluated
  285.         when their boolean is not true.
  286.         Examples:
  287.         W $S(TYPE=1:"Globals",TYPE=2:"Routines",1:"Type unknown!")
  288.  
  289. $T[EXT](<line reference>|+<integer expr>)
  290.         Return the text of the routine, as indicated by the argument. If the
  291.         argument has the form +<integer expr>, +0 evaluates to the
  292.         routinename, +1 evaluates to the text of the first line in the
  293.         routine, +2 evaluates to the text of the second line in the
  294.         routine, etc.
  295.         If the argument has the other form (<line reference>) then the value
  296.         of $T is the text of the designated routineline.
  297.         If the line does not exist, $T returns the empty string.
  298.  
  299. $TRANSLATE(<string 1>,<string 2>[,<string 3>])
  300.         If the third argument is missing, it is taken to be the
  301.         empty string. $TRANSLATE replaces all characters in s1 (<string 1>)
  302.         that match characters in s2 with characters from s3. If s3 is the
  303.         empty string, characters are removed from s1.
  304.         Examples:
  305.         $TR("H1u2i3b4","0123456789")="Huib"
  306.         $TR("1018 KH"," ")="1018KH"
  307.         $TR(A,",.",".,") replaces all comma's with dots and vice versa.
  308.  
  309.  $V[IEW](<integer expr>[,<various other arguments>])
  310.         $V should not be used in routines designed for portability.
  311.         In Archimedes MUMPS, the following arguments can be given to $V:
  312.         $V(1) returns the Naked Indicator.
  313.         $V(2) returns the number of JOBs in the system.
  314.         $V(4) returns the routine name
  315.         $V(5) returns the principle device
  316.         $V(6) returns the current device
  317.         $V(7) returns a 'list' of open devices
  318.         $V(9) returns a 'list' of jobnumbers
  319.         $V(9,<jobnumber>) returns info about that JOB:
  320.          "UCI name,routinename,status,partition size,PD[,openlist]"
  321.           where status means: 0=awaiting input, 1=interpreting.
  322.         $V(10,n) returns sin(n)
  323.         $V(11,n) returns cos(n)
  324.         $V(12) returns $ZT value
  325.         $V(13) returns a 'list' of UCI's
  326.  
  327. $Z(...)
  328.         $Z functions are covered in the file "Z".
  329.  
  330. /* end of Express */
  331.