2

I'm writing a program for my TI-nspire calculator in TI-BASIC, an optimised version of BASIC. From what I can tell, TI-BASIC is a compiled language. I have had more experience working with scripting languages, where you can define i as i+1, where the interpreter adds the previous value of i to 1 and makes that the new value of i. But since BASIC, from my understanding, is compiled, the calculator will set the value of i to the equation of i+1 and loop. Is there a way to set the value of i to the outcome instead of the equation?

intboolstring
  • 6,891
  • 5
  • 30
  • 44
  • 2
    Can you post your code, what the expected results are, and what the *actual* results are? – Mike Christensen Sep 13 '15 at 21:04
  • I would be overwhelming surprised if your calculator had a compiler rather than a rather light-weight interpreter. – John Coleman Sep 13 '15 at 21:07
  • 1
    Don't you use the "store" syntax on those calculators? `i+1 → i`? Also check this page: http://tibasicdev.wikidot.com/nspire – Lasse V. Karlsen Sep 13 '15 at 21:07
  • 3
    `i + 1` is an **expression**, not an equation. An equation would imply you are looking at some that is _equal_ (equates to) something else. And using a compiled vs interpreted language has **zero** bearing on whether the assignment for the language assign the expression or the result of the expression. – Joel Coehoorn Sep 13 '15 at 22:39
  • @LasseV.Karlsen That's for z80 and 68k series calculators; the Nspire is different. – lirtosiast Sep 16 '15 at 03:26

2 Answers2

2

You are wrong, it is perfectly fine to reference a variable in assigning a value to the same variable, it does not result in a loop. However, in TI-Basic you do not use the = operator to assign a value to a variable.

For z80 and 68k calculators use the , character like this:

Local x

2→x
x+1→x

Return x

This returns 3. (Tested on a TI-89.)

On an TI-nspire use :=, like this:

Local x

x:=2
x:=x+1

Return x

This also returns 3.

PGmath
  • 381
  • 3
  • 16
0

Your understanding is wrong. Compilation does not change the semantics of an assignment. It is still an assignment.

And then, what number would the compiler use as the solution for i = i + 1?

Jens
  • 69,818
  • 15
  • 125
  • 179