Why do characters get interpreted as algebraics?
|
05-21-2014, 01:22 PM
Post: #1
|
|||
|
|||
Why do characters get interpreted as algebraics?
My post just disappeared. Let's try again.
Why do unquoted characters get interpreted as algebraics? I would like to be able to enter something and have it interpreted as "something" which has a SIZE of 9. instead it gets interpreted as 'something' with SIZE of 1. ->STR makes it into "'something'", so some code is required to strip the single quotes and make it the string I really wanted. Do we require that strings be entered double-quoted, or is there some more light that can be shed on this? Thanks. It ain't OVER 'till it's 2 PICK |
|||
05-21-2014, 03:27 PM
Post: #2
|
|||
|
|||
RE: Why do characters get interpreted as algebraics?
(05-21-2014 01:22 PM)HP67 Wrote: My post just disappeared. Let's try again. I'm assuming that your question pertains to the RPL environment. I doubt you'll find the answer to your question in any documentation, but I suspect that it's simply because the designers thought it more likely that a user would use the system for symbolic and/or algebraic calculations than string manipulations, so the default behavior for an un-quoted string placed on the stack is to assume that it's either a symbol or name (as opposed to a string). So the basic answer is: yes, you need to supply the double-quotes initially to signal that you're typing in a string as opposed to a name. My 48sx was stolen years ago, but I believe that has been the default mode of operation for all the RPL calcs. |
|||
05-21-2014, 03:49 PM
Post: #3
|
|||
|
|||
RE: Why do characters get interpreted as algebraics?
Thanks. Sorry to hear about the theft
It ain't OVER 'till it's 2 PICK |
|||
05-21-2014, 04:27 PM
Post: #4
|
|||
|
|||
RE: Why do characters get interpreted as algebraics?
An alternative way to convert to a string, avoiding the problem with single quotes is:
Code: "" 'something' + |
|||
05-21-2014, 04:34 PM
Post: #5
|
|||
|
|||
RE: Why do characters get interpreted as algebraics?
(05-21-2014 03:27 PM)DavidM Wrote: I'm assuming that your question pertains to the RPL environment. We really ought to have separate HP 48 and HP 50g forums since there are magnitudes more of those around than Primes. This is what happens when everything that isn't a Prime gets lumped into one forum. It ain't OVER 'till it's 2 PICK |
|||
05-21-2014, 04:35 PM
Post: #6
|
|||
|
|||
RE: Why do characters get interpreted as algebraics?
(05-21-2014 04:27 PM)dizzy Wrote: An alternative way to convert to a string, avoiding the problem with single quotes is: Ingenious! Thank you. I'm still trying to figure out exactly why that works. It ain't OVER 'till it's 2 PICK |
|||
05-21-2014, 04:52 PM
(This post was last modified: 05-21-2014 04:53 PM by Tim Wessman.)
Post: #7
|
|||
|
|||
RE: Why do characters get interpreted as algebraics?
Because + was overloaded to mean "concatenate" for several items (strings included) which is handy for use in cases when you are manually building a list, but has generated a whole other series of problems in which users try to use a list in a function such as << -> X 'X^2+2' >>
and get this: { 1 2 3 } => { 1 4 9 2 } You have to replace the + with ADD( ) in order for it to work properly. Hence why we reversed it on prime so you could actually use lists in algebraic objs... TW Although I work for HP, the views and opinions I post here are my own. |
|||
05-21-2014, 05:26 PM
(This post was last modified: 05-21-2014 05:30 PM by HP67.)
Post: #8
|
|||
|
|||
RE: Why do characters get interpreted as algebraics?
I understand + concatenates.
I just didn't get it that concatenating an empty string with an algebraic results in a string quoted as I wanted in this case. Edit: actually, it doesn't. It seems to only work with algebraics that aren't really algebraic in that they can't be resolved. For example 'SIN' errors out and doesn't even get to the stack. 'SINO' does. Is there some type of object that is single quoted that isn't an algebraic? It ain't OVER 'till it's 2 PICK |
|||
05-21-2014, 05:53 PM
Post: #9
|
|||
|
|||
RE: Why do characters get interpreted as algebraics?
(05-21-2014 05:26 PM)HP67 Wrote: I understand + concatenates. There are a few different object types that are represented with single quotes: Algebraic: 'X+2', TYPE = 9 Global name: 'PPAR', TYPE = 6 Local name: 'XSTP', TYPE = 7 Local names are defined with the -> operator in programs. |
|||
05-21-2014, 06:09 PM
(This post was last modified: 05-21-2014 06:11 PM by HP67.)
Post: #10
|
|||
|
|||
RE: Why do characters get interpreted as algebraics?
Thanks. I checked and a bunch of characters that isn't a command goes on the stack single-quoted as a global name (type 6).
I still don't exactly get what's going on here but Dizzy's suggestion works great in my situation. If the string is already a quoted string then concatenating the empty string to it does nothing. If it's a global name then it gets turned into a string. OTOH ->STR seems to produce strange results. A global name gets turned into a string but with single quotes inside the double quotes. It would be great if somebody can explain this. Perhaps Tim already did, but if so then I didn't understand what he wrote. It ain't OVER 'till it's 2 PICK |
|||
05-21-2014, 07:44 PM
Post: #11
|
|||
|
|||
RE: Why do characters get interpreted as algebraics?
(05-21-2014 06:09 PM)HP67 Wrote: ...OTOH ->STR seems to produce strange results. A global name gets turned into a string but with single quotes inside the double quotes. It would be great if somebody can explain this. Short answer: because that's how it was designed to work. Longer answer: It's important to remember that, in RPL terms, there is a big difference between: "String" and 'String' The first is an object containing a string of characters, the second is an identifier for an object (not the object itself). They are entirely different object types, in the same sense that a real number: 1.234 is an entirely different kind of object from a string: "abc" Generally speaking, ->STR gives you a string whose contents represent the way something would look on the stack (without the quote marks, of course). Furthermore, there's a reciprocal function to ->STR: OBJ->. OBJ-> works by attempting to evaluate the contents of the string. This is why the single quotes are important; they are needed to make sure that you get the object identifier back, not its contents. |
|||
05-21-2014, 08:34 PM
Post: #12
|
|||
|
|||
RE: Why do characters get interpreted as algebraics? | |||
05-22-2014, 04:15 AM
Post: #13
|
|||
|
|||
RE: Why do characters get interpreted as algebraics?
(05-21-2014 03:27 PM)DavidM Wrote:(05-21-2014 01:22 PM)HP67 Wrote: Why do unquoted characters get interpreted as algebraics? ... FYI, it actually is in the manuals for every RPL model. For example, in the original "HP 48 Owner's Manual" (Edition 1, 11/91), on page 6-6, under the heading "Using Quoted and Unquoted Variable Names", it says: "If you execute an unquoted name that doesn't exist (it's a formal variable, no variable has been created with that name), the name is put on the stack with quotes. The ability to use names without having to create variables enables you to do symbolic math with the HP 48." Similar info is on page 20 in the "HP-28C Reference Manual". Et cetera. <0|ΙΈ|0> -Joe- |
|||
05-22-2014, 04:39 AM
Post: #14
|
|||
|
|||
RE: Why do characters get interpreted as algebraics?
Joe does it again! Thank you. And thanks to DavidM for the explanations. And to Dizzy for a practical solution. And to everybody!
It ain't OVER 'till it's 2 PICK |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 5 Guest(s)