Author Topic: Store a value to an arbitrary variable?  (Read 3888 times)

0 Members and 1 Guest are viewing this topic.

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Store a value to an arbitrary variable?
« on: October 15, 2012, 11:14:20 am »
Is it possible to store a value to an arbitrary real number variable? I tried expr("1"+Str0+"A") as a test (where Str0 contains a store arrow), but it throws an error. I suspect it may not be possible, but if you can think of any hackish way to do it, that would be great. I don't want to have to resort to a 27-branch conditional. :P

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Store a value to an arbitrary variable?
« Reply #1 on: October 15, 2012, 11:36:16 am »
No, that's not possible—expr( can only handle functions that return a value (no storing or executing commands that start with a capital letter).

I don't know what you need to do, but would using a list work? With lists you can calculate the offset to store to.




Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Store a value to an arbitrary variable?
« Reply #2 on: October 15, 2012, 02:00:46 pm »
You can read the value of an arbitrary real number, but I don't think you can store a value to an arbitrary real number. expr is limited in that in cannot store a value (or contain the -> character). As Deep Thought asked, is there any reason not to use a list instead of expr? Also, couldn't this be accomplished using ASM, (and accessing the BASIC variables) or is there a reason you want or need this to be in pure BASIC?

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Store a value to an arbitrary variable?
« Reply #3 on: October 15, 2012, 02:31:37 pm »
Hmm, I guess I'll either have to think of some tricky find-and-replace way of doing this or suck it up and use the 27-branch conditional. The reason why I wanted this was to let the user input a function of arbitrary variables, which is then searched for any variables and the user is prompted for their values. To then evaluate the function (or a transformation of the function), I need some way of actually assigning those values to the variables.

Offline Rhombicuboctahedron

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 437
  • Rating: +41/-6
    • View Profile
Re: Store a value to an arbitrary variable?
« Reply #4 on: October 15, 2012, 03:31:41 pm »
Why not just use Request?
Request “variable”, variable
That way variable is defined as the value. I can’t understand what you want to do.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Store a value to an arbitrary variable?
« Reply #5 on: October 15, 2012, 03:37:04 pm »
Why not just use Request?
Request “variable”, variable
That way variable is defined as the value. I can’t understand what you want to do.
We are talking about z80 Basic, not Nspire Basic.
And the equivalent to Request is Input, but that is not what he wants. He wants to put code that would store a value to a variable in a string and "execute the string" (if I understood correctly)
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Store a value to an arbitrary variable?
« Reply #6 on: October 15, 2012, 03:58:17 pm »
My suggestion would be to do a simple find and replace of all the variables in the input function.  A would become L1(1), B would become L1(2), and so on.  I created something similar earlier for discreet mathematics and it worked like a charm :)

Offline Rhombicuboctahedron

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 437
  • Rating: +41/-6
    • View Profile
Re: Store a value to an arbitrary variable?
« Reply #7 on: October 15, 2012, 05:00:04 pm »
Quote
Why not just use Request?
Request “variable”, variable
That way variable is defined as the value. I can’t understand what you want to do.

We are talking about z80 Basic, not Nspire Basic.
And the equivalent to Request is Input, but that is not what he wants. He wants to put code that would store a value to a variable in a string and "execute the string" (if I understood correctly)

Oh, wow
I don't know why I automatically assumed it was Nspire

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Store a value to an arbitrary variable?
« Reply #8 on: October 15, 2012, 08:36:06 pm »
I know I made an asm program a while ago that stores a list of values to real vars. The real vars are named via a string. Other than that, it is not directly possible in TI-BASIC.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Store a value to an arbitrary variable?
« Reply #9 on: October 15, 2012, 09:39:36 pm »
Hmm, I guess I'll either have to think of some tricky find-and-replace way of doing this or suck it up and use the 27-branch conditional. The reason why I wanted this was to let the user input a function of arbitrary variables, which is then searched for any variables and the user is prompted for their values. To then evaluate the function (or a transformation of the function), I need some way of actually assigning those values to the variables.
You can do something like Input "F=?",L1(6) to make it look like you're prompting for the value of F.

I had a program once that accepted an expression of any letter variables. The program scanned through the expression, replacing every instance of the letter with an appropriate list element and prompting for its value in that way, and finally called expr( on the tweaked expression.
« Last Edit: October 15, 2012, 09:40:00 pm by Deep Thought »




Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Store a value to an arbitrary variable?
« Reply #10 on: October 15, 2012, 11:52:50 pm »
^Yea, this is what I was thinking too if it were to be done in pure BASIC.