Create a list of undefined user vars?
|
01-24-2016, 10:18 PM
Post: #1
|
|||
|
|||
Create a list of undefined user vars?
In [HOME], can a list of undefined variables somehow be created (for later use)?
Example: dogs:=0; cats:=0; // define vars first L1:={'dogs', 'cats'}; This works: INPUT({dogs, cats}); This doesn't work: INPUT(L1); // even though L1 ==> {dogs, cats} same as above. (Why not?) -Dale- |
|||
01-25-2016, 07:49 AM
Post: #2
|
|||
|
|||
RE: Create a list of undefined user vars?
Hello,
Yes, you can create a list of undefined variables, to do so, you need to use the CAS (which can do it), and transform the CAS result in a home result. For example L1:=CAS("{a, b, c, d}") will work. Now, the question about the INPUT(L1) not working is a different one. INPUT(A), as you know asks you to input a value for the variable A. therefore INPUT(L1) should ask you a value for variable L1, not for the variables contained in the list stored in L1. It's a case of 'you can not have the butter and the money from the butter'... The first parameter of INPUT is one of these special cases where the parameter is NOT evaluated by the function. So, how do you deal with the situation? Well, one way is to generate an INPUT call with the CONTENT of L1 as a parameter. exrp("INPUT("+string(L1)+")"); will do that. It creates a string that contains the command and then executes it! Cyrille Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP. |
|||
01-25-2016, 11:08 AM
Post: #3
|
|||
|
|||
RE: Create a list of undefined user vars?
Thank you, Cyrille. I really appreciate your helpful information!
I knew to use the symbolic side, [CAS], to create the list L1, which is why I was seeking a solution based on [HOME]. I wasn't able use the CAS result though, since it was saved in the variable L1. As shown in my example, L1 couldn't be evaluated as an INPUT() parameter, as you have explained. I tried many things, but I didn't know about your string-based approach, and will give that a try! If anyone is interested, I want to gather input from a changeable list of stock symbols. The idea attempts to make use of "ticker symbols" as "undefined" variable names for an investment progress, portfolio tracker. If a list of symbols, with associated share details, were available, (L1, maintained outside the program), then I could programmatically manage the rest of the portfolio tracking details, needing only current market prices as additional input. The Prime's portability makes it a handy tool for this quick status project. I've found that there's almost always a way to do things with the Prime. I ran out of ideas here, though! -Dale- |
|||
01-25-2016, 12:23 PM
Post: #4
|
|||
|
|||
RE: Create a list of undefined user vars?
(01-25-2016 07:49 AM)cyrille de brébisson Wrote: So, how do you deal with the situation? Cyrille, could you please elaborate on: exrp("INPUT("+string(L1)+")"); // ==> results in Syntax Error no info in exrp() function in help, etc. Thanks, Dale- |
|||
01-25-2016, 12:45 PM
Post: #5
|
|||
|
|||
RE: Create a list of undefined user vars? | |||
01-25-2016, 02:58 PM
Post: #6
|
|||
|
|||
RE: Create a list of undefined user vars?
Of course, thanks Didier. I should have figured that one out. (Flu bug's got me, not my best day).
-Dale- |
|||
01-25-2016, 04:18 PM
Post: #7
|
|||
|
|||
RE: Create a list of undefined user vars?
[HOME] Example: Input '5' dogs and '4' cats (quotes required by the INPUT function). I don't understand how the dogs and cats variables' content gets accessed? It's close with this format, but not quite there, yet.
Code:
-Dale- |
|||
01-25-2016, 05:45 PM
(This post was last modified: 01-25-2016 05:46 PM by toml_12953.)
Post: #8
|
|||
|
|||
RE: Create a list of undefined user vars?
(01-25-2016 04:18 PM)DrD Wrote: [HOME] Example: Input '5' dogs and '4' cats (quotes required by the INPUT function). I don't understand how the dogs and cats variables' content gets accessed? It's close with this format, but not quite there, yet. I can't get it to work at all. My line looks like this: CAS.expr("INPUT("+string(L1)+")"); and I get a syntax error with the cursor between the first open parenthesis and the quote mark. Tom L Tom L Cui bono? |
|||
01-26-2016, 06:01 AM
Post: #9
|
|||
|
|||
RE: Create a list of undefined user vars?
Hello,
1) At the time of the INPUT, the inputed variables MUST exist as INPUT uses the current value of the variable as the default value. 2) do not use CAS.INPUT, INPUT is NOT a CAS command... 3) What is the value of L1? can you show it? 4) to help you debug, you can save the string in a temporary variable and show it on the screen (PRINT(string_variable); WAIT or just (save the string in a user accessible variable and kill the program). This will probably let you see what is happening. Good luck. Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP. |
|||
01-26-2016, 12:08 PM
(This post was last modified: 01-26-2016 12:12 PM by DrD.)
Post: #10
|
|||
|
|||
RE: Create a list of undefined user vars?
(01-26-2016 06:01 AM)cyrille de brébisson Wrote: Hello, |
|||
01-27-2016, 05:59 AM
Post: #11
|
|||
|
|||
RE: Create a list of undefined user vars?
Hello,
I think that I am starting to understand what you are trying to do. you want cats and dog to be defined BY the INPUT function. Unfortunately, this can not work. INPUT requires you to have the variable available and existing at the time it is called. HVars is a function that can let you programaticaly create variables (ie, a name+value pair). You can then use them as input for INPUT (using the string trick) Cyrille Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP. |
|||
01-27-2016, 12:27 PM
Post: #12
|
|||
|
|||
RE: Create a list of undefined user vars?
Using a list of undefined variable names, created and maintained without programmatic influence, is my specific objective. It's kind of like a database list, I guess. I'll try using the HVars approach next. That's a good idea, and one I haven't tried. There's more than one way to "skin" a prime - at least if you're using the EMU version!
Thanks (again), Cyrille! -Dale- |
|||
01-27-2016, 04:13 PM
(This post was last modified: 01-27-2016 04:15 PM by Didier Lachieze.)
Post: #13
|
|||
|
|||
RE: Create a list of undefined user vars?
(01-27-2016 12:27 PM)DrD Wrote: Using a list of undefined variable names, created and maintained without programmatic influence, is my specific objective. It's kind of like a database list, I guess. I'll try using the HVars approach next. That's a good idea, and one I haven't tried. There's more than one way to "skin" a prime - at least if you're using the EMU version! I've played a bit with these different ideas and so here is a version of your test program where a list of undefined variables names is used to drive the INPUT statement and to retrieve the values: Code: EXPORT test() |
|||
01-27-2016, 04:42 PM
(This post was last modified: 01-27-2016 04:47 PM by DrD.)
Post: #14
|
|||
|
|||
RE: Create a list of undefined user vars?
Wow. That's a bunch of prep to get the list in order! I was also trying Cyrille's idea of using HVars for this. It might be simpler. I can get the HVar list, but (so far) I haven't been able to exchange any numerical data with the variables.
Here's an abbreviated example: Code:
I've tried several ways to use Tickers but no luck. Any ideas? -Dale- |
|||
01-27-2016, 04:48 PM
Post: #15
|
|||
|
|||
RE: Create a list of undefined user vars?
What do you want to do with Tickers?
|
|||
01-27-2016, 04:54 PM
(This post was last modified: 01-27-2016 05:11 PM by DrD.)
Post: #16
|
|||
|
|||
RE: Create a list of undefined user vars?
Tickers == {CAT, IBM} Each element of the list would be used to hold the current price. Lets say, the current price of Tickers(1), CAT was $60, and Tickers(2), IBM was $123. If INPUT(Tickers) would work, the idea would be to have an input field for the variable CAT, which would receive the current price ($60), and similarly for the variable IBM at $123.
This would allow the use of CAT and IBM as variables, allowing further computation as needed. CAT == 60, and IBM == 123, so 2*CAT = 120, etc. |
|||
01-27-2016, 05:10 PM
Post: #17
|
|||
|
|||
RE: Create a list of undefined user vars?
Something like that?
Code: EXPORT test2() |
|||
01-27-2016, 05:17 PM
Post: #18
|
|||
|
|||
RE: Create a list of undefined user vars?
YES! I think you've done it. I'll try to digest what's going on there, and move on to the next dilemma. Thanks for the assist! (I just knew there had to be a way to do this...)
-Dale- |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 6 Guest(s)