It is currently Thu Mar 28, 2024 7:11 am


All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Various Interpretations of String Values
PostPosted: Tue Nov 23, 2010 9:56 am 
User avatar

Joined: Wed Nov 17, 2010 4:02 pm
Posts: 71
Location: Houston TX
Real Name: David Whitten
Began Programming in MUMPS: 06 Jan 1982
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.


Top
Offline Profile  
 
 Post subject: Re: Various Interpretations of String Values
PostPosted: Thu Jan 27, 2011 8:50 am 
User avatar

Joined: Wed Nov 17, 2010 4:02 pm
Posts: 71
Location: Houston TX
Real Name: David Whitten
Began Programming in MUMPS: 06 Jan 1982
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.


Top
Offline Profile  
 
 Post subject: Re: Various Interpretations of String Values
PostPosted: Thu May 20, 2021 8:11 am 

Joined: Thu May 20, 2021 8:09 am
Posts: 1
Real Name: Tyra
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" ?


Top
Offline Profile  
 
 Post subject: Re: Various Interpretations of String Values
PostPosted: Sat Apr 16, 2022 11:51 am 
User avatar

Joined: Wed Nov 17, 2010 4:02 pm
Posts: 71
Location: Houston TX
Real Name: David Whitten
Began Programming in MUMPS: 06 Jan 1982
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"


Top
Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net