Mumpster
http://mumpster.org/

Various Interpretations of String Values
http://mumpster.org/viewtopic.php?f=14&t=49
Page 1 of 1

Author:  whitten [ Tue Nov 23, 2010 9:56 am ]
Post subject:  Various Interpretations of String Values

One of the Standard MUMPS features that is not well understood by some new programmers is based on the fact that MUMPS has a single data type of "strings of characters" but has multiple interpretations of those characters when they are used in various ways by the language.
In contrast to other programming languages, the value stored in a variable in MUMPS is always the same characters, but the way it is written or used in program code is subject to the interpretation needed by a particular function or operator.

To take a string of characters and generate the various interpretations depends on using the string either with a unary operator (called in the MUMPS Standard a "unaryop") or as part of a syntactic form of a function.

The syntax for a unary operator consists of a punctuation character followed by an expression.
There are three unaryop's in MUMPS. These are the apostrophe, the plus sign, and the hyphen.

The syntactic form of an intrinsic function includes one of these words "expr" or or "glvn" or "intexpr" or "fncodexpr" or "numexpr" or "namevalue" or "tvexpr" or "stackcodexpr" or "textarg".

The syntactic form of an extrinsic function consists of an "actual" which is either "expr" or an "actualname".

There are a few other syntactic forms used for MDC standard functions, but not in the 1995 Standard.

This topic is intended to discuss the various interpretations, what they mean, and how they affect programmers, with special emphasis on things a new MUMPS programmer won't likely know.

Author:  whitten [ Thu Jan 27, 2011 8:50 am ]
Post subject:  Re: Various Interpretations of String Values

I was thinking about the various interpretations of string values and thought I'd present a simple quiz:

1. What is the truth value of "FALSE" ?
2. What is the numeric value of "11+22" ?
3. What is the string value of "5*6" ?
4. What is the truth value of 15/20 ?
5. What is the numeric value of "TRUE" ?
6. How many fractional digits does "3Sombreros" have ?
7. If something has a value of "$49.99" what numeric value would it have ?
8. What about the numeric value of "01,234,567.89" ?

More Later.

Author:  TyraNoah [ Thu May 20, 2021 8:11 am ]
Post subject:  Re: Various Interpretations of String Values

The kinds of questions to prioritize on.
1. What is the truth value of "FALSE" ?
2. What is the numeric value of "11+22" ?
3. What is the string value of "5*6" ?
4. What is the truth value of 15/20 ?
5. What is the numeric value of "TRUE" ?
6. How many fractional digits does "3Sombreros" have ?
7. If something has a value of "$49.99" what numeric value would it have ?
8. What about the numeric value of "01,234,567.89" ?

Author:  whitten [ Sat Apr 16, 2022 11:51 am ]
Post subject:  Re: Various Interpretations of String Values

I posted this over 10 years ago, I think I can reveal the answers now.
Assuming that you type into a MUMPS program a line that has a command to evaluate
the text I mentioned, the answers are:

I was thinking about the various interpretations of string values and thought I'd present a simple quiz:

1. What is the truth value of "FALSE" ?
the truth value of an expression can be shown with two apostrophes: WRITE ''"FALSE" is "0"

2. What is the numeric value of "11+22" ?
the numeric value of an expression can be shown with a plus sign: WRITE +"11+22" is "11"

3. What is the string value of "5*6" ?
the string value of an expression can be shown with just the text: WRITE "5*6" is "5*6"

4. What is the truth value of 15/20 ?
this is not a quoted string, so to find the truth value means a parenthesis will be needed around it
so WRITE ''(15/20) yields "1" because 15/20 is ".75" and the truth value of ".75" is "1"

5. What is the numeric value of "TRUE" ?
the truth value of an expression can be shown with a plus sign: WRITE "TRUE" is "0"

6. How many fractional digits does "3Sombreros" have ?
only numbers have fractional digits so WRITE +"3Sombreros" is "3" which has zero fractional digits

7. If something has a value of "$49.99" what numeric value would it have ?
strictly speaking the $ (dollar sign) stops numeric interpretationi so
WRITE +"$49.99" is "0" to get "49.99" as a value, $TRANSLATE function can remove the "$"
WRITE +$TRANSLATE("$49.99","$") is "49.99"

8. What about the numeric value of "01,234,567.89" ?
strictly speaking a comma also stops numeric evaluation so
WRITE +"01,234,569.89" is "1"
WRITE +$TRANSLATE("01,234,569.89","$(,)") is "1234569.89"

Page 1 of 1 All times are UTC - 8 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/