Talking about the CONVO program (p. 49), it says "The program will first ask you to type in your name; you should be able to type anything at this prompt."

Yes, but how is this possible if we're storing the data to a string variable, and only strings can be assigned to string variables. For example, if I do 25[STO]Str1 on the homescreen, I get ERR:DATA TYPE.

Also, on the TI-Basic Developer website, regarding the Input command, it says "If the variable is a string, the user must put quotes around the value or expression."

How is this explained?
The Input and Prompt command, when combined with a Str variable, will interpret whatever you type as a string, even without the quote marks. If you type 25, it is interpreted as the string "25", just as HELLO is interpreted as the five-character string "HELLO" rather than the implicit multiplication of H times E times L times L times O. Hope this helps clear up your confusion.
KermMartian wrote:
The Input and Prompt command, when combined with a Str variable, will interpret whatever you type as a string, even without the quote marks. If you type 25, it is interpreted as the string "25", just as HELLO is interpreted as the five-character string "HELLO" rather than the implicit multiplication of H times E times L times L times O. Hope this helps clear up your confusion.


Yes that clears it up. From my minimal experience with programming in general, I believe what you're talking about is called "type conversion" (or "type coersion"). Anyway I guess the TI Basic Developer site that says you need to enclose strings in quotes is mistaken...

Thanks Christopher!
ClrHome wrote:
Yes that clears it up. From my minimal experience with programming in general, I believe what you're talking about is called "type conversion" (or "type coersion"). Anyway I guess the TI Basic Developer site that says you need to enclose strings in quotes is mistaken...

Thanks Christopher!
No, it's not type coersion. Type coersion is the ability to convert contextually between types, for example, "1"+1 in Javascript and get either "11" or 2. Because the Input or Prompt command specifies the variable that is being filled, the TI-OS knows exactly what type to expect. If the interpreter sees Prompt L1, then it knows you need to type a list like {1,2,3}. If it sees Input Str1, it knows to interpret the input as a sequence of tokens to be stored in a string; it would be rather user-unfriendly if your BASIC programs' users had to type quotes around all their string inputs.

TI-BASIC Developer is not mistaken; when you're typing strings in your code, you always need the quote marks, because without them it's not clear if the tokens in question are data or code. In an extremely case, HELLO->Str2 might be either a Data Type error (storing H*E*L*L*O, a number, to a string) or a correct store ("HELLO" to Str2) without the necessary quote marks.

My pleasure!
KermMartian wrote:
ClrHome wrote:
Yes that clears it up. From my minimal experience with programming in general, I believe what you're talking about is called "type conversion" (or "type coersion"). Anyway I guess the TI Basic Developer site that says you need to enclose strings in quotes is mistaken...

Thanks Christopher!
No, it's not type coersion. Type coersion is the ability to convert contextually between types, for example, "1"+1 in Javascript and get either "11" or 2. Because the Input or Prompt command specifies the variable that is being filled, the TI-OS knows exactly what type to expect. If the interpreter sees Prompt L1, then it knows you need to type a list like {1,2,3}. If it sees Input Str1, it knows to interpret the input as a sequence of tokens to be stored in a string; it would be rather user-unfriendly if your BASIC programs' users had to type quotes around all their string inputs.

TI-BASIC Developer is not mistaken; when you're typing strings in your code, you always need the quote marks, because without them it's not clear if the tokens in question are data or code. In an extremely case, HELLO->Str2 might be either a Data Type error (storing H*E*L*L*O, a number, to a string) or a correct store ("HELLO" to Str2) without the necessary quote marks.

My pleasure!


OK, so I think you're saying the key with regard to type coersion is ambiguity.

Regarding the TI Basic developer description of Input, I must be misinterpreting something... Aren't they talking about the user (not the programmer) entering input. Quote:

"Input can be used to display every variable just before it requests user input, but some of the variables have to be entered in a certain way. If the variable is a string or a Y= function, the user must put quotes ("") around the value or expression. The user must also put curly braces ({}) around lists with the list elements separated by commas, and square brackets ([]) around matrices with the matrix elements separated by commas and each row individually wrapped with square brackets."

It says the user must put quotes, doesn't it? Confused!
ClrHome wrote:
It says the user must put quotes, doesn't it? Confused!


It lied (for strings, but not for equations). Putting quotation marks in string input is actually wrong, and will result in the quotation marks being present in the resulting string. Later in the page, it actually mentions that this is a way to get the quotation mark into strings, which is normally not possible.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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 vote in polls in this forum

 

Advertisement