Programming the TI Nspire

978 views
Skip to first unread message

Phrank

unread,
Dec 19, 2008, 5:08:44 PM12/19/08
to tinspire
Just wondering if anyone has attempted to write programs in th Nspire
(non-CAS). I can see that it has commands for loops, conditionals and
subroutines. Especially, I'd like details on how to
---------- use I/O (especially input from a user -- the output
command I can already see)
---------- compile and/or run a program
---------- Filling spreadsheets and doing operations on spreadsheets

All of these could be easily done on a TI-84.

Phrank

Nelson Sousa

unread,
Dec 19, 2008, 5:34:02 PM12/19/08
to tins...@googlegroups.com

Hi!

I've programmed somewhat, although the programming capabilities are still limited.

As for input you can only pass data to a program as arguments. There's no way to input data after the program is running.

All programs are interpreted and are written in Nspire's own language, similar to the one we find on other TI calculators. There's no compiled programming language. No assembly if that's what you're asking.

To fill a spreadsheet you have to have it defined beforehand, name the columns and then perform the fill operations on those variables. 

Example: create a L&S page, and name the columns A and B as list_a and list_b; populate the lists with some data; Now open a calculator page, create a program the program

test(a,b)
Define abc(a,b)=
Prgm
:Fill a,list_a
:Fill b,list_b
:EndPrgm

When you call the program it will fill the A and B columns with the numbers passed as arguments.
Note that in this example, if the lists aren't populated, the fill command doesn't do anything. You can, of course, use all the other list functions available and/or any other kind of variable manipulation. 

But you can't edit a spreadsheet directly from within a program. Nor can you create, delete or manage pages.


Regards,
Nelson

Nelson Sousa

unread,
Dec 19, 2008, 5:41:25 PM12/19/08
to tins...@googlegroups.com

oh, yes, another thing concerning list manipulation on Nspire (as well as any other TI calculator):
if you have a list, say with 10 elements you can store a number to it's 11th position; the list will be augmented to 11 elements; however, you can't store a number to position 12. It will return an error. You can only add elements one at a time.

hope this helps.

Nelson

Eagle-Man

unread,
Dec 20, 2008, 2:57:58 AM12/20/08
to tins...@googlegroups.com
A few more notes about programming.

1) There is a difference between Programs and Functions. A Function
only has access to locally defined variables and can return a single
value (not a string). A Program has access to other variables defined
in the file, and does not return any values. There are also a few
Function/Program specific commands (ie: will run in a program but not
a function, and vice-versa)

2) Any changes to the "Mode" of the calculator done in a program is
temporary, and will reset at the end of the program.

3) The only I/O at present is the Disp command, and arguments (as mentioned)

4) Programming is a lot nicer with the use of the Program Editor,
found in the calculator app's Programming menu.

5) The Nspire now has Try-Else blocks which allow us to "catch" error
codes and run special code when the error occurs.

Examples:
Define prog1()=
Prgm
Try
z:=z+1
Disp "z incremented."
Else
Disp "Sorry, z undefined"
EndTry
EndPrgm

This one will not produce an error when z is undefined, but rather,
print out a simple message.

Define prog2()=
Prgm
Local b

For b, -10, 10, 1
Try
Disp 1/b
Else
If errCode=250 Then
Disp infinity
clrErr
Else
passErr
EndIf
EndTry
EndFor
EndPrgm

This program will attempt to display the decimal values of 1/b, where
-10 < b < 10. As wee all know, this should produce a "Div. by 0"
error about half way through, which would break the program. Not
anymore!

By placing it in a Try-Else block, we can catch the "div by 0" error
code (250) when it occurs. If it is unable to do "1/b", then it
enters the Try's "Else" block. Here we check for the error code.

If it's 250 (div by 0), then we display the infinity symbol instead
(not totally correct, but let's just go with it), and forget the
error. If it's not, then we pass the error code out of our program
and it breaks. You can do this for as many error codes as you wish to
handle with ElseIf statements.


I personally would love to have some user input and control for the
other apps, but these are a few of the things I like about the
Nspire's programming structure so far.

...Plus libraries, but I think most people here know about that
already (if you don't, ask).

--Eric F.

Eagle-Man

unread,
Dec 20, 2008, 2:59:39 AM12/20/08
to tins...@googlegroups.com
Forgot to mention. The complete list of error codes is listed at the
back of the Nspire reference guide, which you should have in hard
copy, or can find here:
http://education.ti.com/downloads/guidebooks/ti-nspire/TI-Nspire_ReferenceGuide_EN.pdf

Nelson Sousa

unread,
Dec 20, 2008, 4:13:38 AM12/20/08
to tins...@googlegroups.com

And yet another thing regarding functions and programs: Functions can be called from within anywhere (well, almost). A program can only be called from a calculator App.

Nelson

Sean Bird

unread,
Dec 20, 2008, 10:01:14 AM12/20/08
to tins...@googlegroups.com
On page 118-119 of this document there is a lovely list of shortcuts that are particularly handy when typing, whether working on programs or robust tns files. The less you need to take your hands off the keyboard to use the mouse, the faster you can go.

I compiled a list of shortcuts for Equation Editor (Math Type) a while back. http://covenantchristian.org/bird/Smart/Physics1/Equation%20editor%20suggestions.doc
It is helpful to me to look at is periodically - I'm reminded of fun tricks.

Sean Bird
blog: http://bird-godlydominion.blogspot.com/

Phrank

unread,
Dec 20, 2008, 4:18:32 PM12/20/08
to tinspire
If I understand you correctly, the 11-element limitation is only for
directly assigning a list to a table.

The lists I have done in the past have all been manually inserted from
input commands, for example, the following code takes input for a
student's mark (L), calculates its mark out of 100, stores it in list
L1 which I can treat as an array, and also displays the value using
DISP. The "->" is a single character from pressing the "STO" button.
The code has been shortened for brevity, and may contain errors due to
some changes to make things short.

INPUT "NO OF STUDENTS?", N
INPUT "TEST OUT OF", K
FOR (J, 1, N, 1)
0 -> L
INPUT "L?", L
(L/K)*100 -> L1(J)
DISP L1(J)
3 * L1 -> L2
END
1-Var Stats(L1)

Similar code, unchanged, also works in the TI-83. I am surprised that
the new NSpire can't do this.
The "3* L1 -> L2" line is just to show I can treat a list as a vector,
multiply it by a scalar, and store it in another list inside the code.
List L2 already exists internally, and does not have to be pre-
configured, as is also true for all lists from L1 to L6. I have also
encountered no memory limitstions on list size on the TI-84, as you
seem to be warning me about regarding the NSpire. I have entered lists
bigger than 30 with no problem, filling all lists from L1 to L6.

So, I guess I would have to enter things into a table manually, then
run the code on the table columns. Regarding those list members: are
they hard-coded or are they entered into a table?

Phrank

Eagle-Man

unread,
Dec 20, 2008, 7:27:17 PM12/20/08
to tins...@googlegroups.com
I think what Nelson meant is that if you have a list of size n, you
can only store to a maximum index of n+1. Then the size n=n+1 and
again, you can store to index n+1, but you cannot store to index n+2.

And I tested your example, and it works fine...except the input part.
You'd have to pass a list of marks to the program, which could replace
the number of students, then just take the number from dim(list).

--Eric F.

--- Original Message ---

>

Eagle-Man

unread,
Dec 20, 2008, 7:34:54 PM12/20/08
to tins...@googlegroups.com
*shakes head*

Again, I realized something right after I hit send.

If you wanted to add multiple indices to a list, then you could use
the Augment function, augment(list1, list2) like this:

list := {1,2,3}
i := 4
j := 5
augment(list, {i,j})->list

This method would allow you to insert multiple elements into the list
at one time (which I think is what Nelson wished to do)

Nelson Sousa

unread,
Dec 20, 2008, 7:49:05 PM12/20/08
to tins...@googlegroups.com

yes, the 10 elements were just an example. Of course you can have lists of (almost) any size. I mean, I just created a list of 10 thousand elements on my Nspire and it did ok (what's the limit, by the way? anybody knows?).

But for what you want to do I believe it's much simpler to just insert the data on a spreadsheet. I only use programs if I have no other choice, otherwise I prefer to use simpler tools. Also on a spreadsheet you can edit the values later on and correct them, while on the code you provided there's no possibility of changing a number once entered (and isn't it easy to type it wrong when you're inserting 20 or 30 numbers in a row...).

The main limitations beetwen programing for the 84+ and for Nspire is that all input must be given when you call the program, you can't have inputs in the middle of the code, and all output must be made sequentially as a set of Disp instructions, not allowing you to output a string, then delete it and output a different one, etc.

But there are a lot of advanced features, inherited from 89 Titanium/Voyage 200 programming language, that make the difference, and add significant programming power.

My view, to wrap it up, is that Nspire is so complex that one must really take the time to explore it fully before concluding about what can or can't be done. I mean, some of the stuff you see here weren't even possible in one's wildest dreams just a few months ago! 


Nelson

Nelson Sousa

unread,
Dec 20, 2008, 7:53:09 PM12/20/08
to tins...@googlegroups.com

yet another method to augment a list of an arbitrary number of elements, defined as a function:

Define augment_list(list,n)=
Func
:Return augment(list,newList(n))
:EndFunc

Example:
mylist:={1,2,3,4,5}
augment_list(mylist,10) returns a list with 15 elements (begin the first 5 the elements of mylist and the last 10 will be zeroes).

Nelson

Phrank

unread,
Dec 21, 2008, 12:24:20 AM12/21/08
to tinspire
First off, I am thankful for the attention being paid to this topic of
mine. Thanks to one of you for the link to the NSpire manual. I teach
both math and computer science, and one of the basic things we teach
in Comp Sci is that all programs must have an input and an output.
That is, they most often require some interaction with the end user. I
thus consider the lack of an input statement a glaring omission.

I agree with you that there are a whole host of new functions, and the
presence of user-defined functions, if they can be actually called in
programs or stored in a library, is a great tool with great
possibilities.

What you have suggested appears to be to fill out a table and then run
the program. This is a great suggestion, however, this can also be
done on both my TI-83 and my TI-84. Admittedly, it was something that
I hadn't thought of at the time. The greater reason for programming
the claculator the way I did was to teach myself the language, as well
as giving me a quick-and-dirty method for calculating class averages
on tests without having to fire up my laptop and starting a
spreadsheet. (to those who are curious, this is not a straightforward
job -- our marks are based on a weighted system which I don't want to
get into, which I am not sure anyone beyond us math teachers really
get).

I think it has to be generally admitted that the loss of the input
statement results in a sacrifice in flexibility. Programmable
calculators have existed since the 1980s which can accept keyboard
input. I like to teach myself how to write programs in several
languages, and if a language lacks a means of input, then just to get
on to the ground level, I would have to learn about how the program
interacts with tables, and other applets in the system, as well as the
quirks in each of the applets. Someone on this list suggested that the
columns in the tables have to be named before they are used. If the
program uses the same names, does that mean that I have to rename the
columns if I accidentally delete the spreadsheet page? Or can I save a
template of a table with the names I want?

Doing repeated claculations (the original reason for programmable
calculators) now must be done on tables, but I still think that
calculations should be made possible on direct input. That just seems
more intuitive to me, and provides a good holdover until I feel more
confident with tables.

Phrank

On Dec 20, 7:49 pm, "Nelson Sousa" <nso...@gmail.com> wrote:
> yes, the 10 elements were just an example. Of course you can have lists of
> (almost) any size. I mean, I just created a list of 10 thousand elements on
> my Nspire and it did ok (what's the limit, by the way? anybody knows?).
>
> But for what you want to do I believe it's much simpler to just insert the
> data on a spreadsheet. I only use programs if I have no other choice,
> otherwise I prefer to use simpler tools. Also on a spreadsheet you can edit
> the values later on and correct them, while on the code you provided there's
> no possibility of changing a number once entered (and isn't it easy to type
> it wrong when you're inserting 20 or 30 numbers in a row...).
>
> The main limitations beetwen programing for the 84+ and for Nspire is that
> all input must be given when you call the program, you can't have inputs in
> the middle of the code, and all output must be made sequentially as a set of
> Disp instructions, not allowing you to output a string, then delete it and
> output a different one, etc.
>
> But there are a lot of advanced features, inherited from 89 Titanium/Voyage
> 200 programming language, that make the difference, and add significant
> programming power.
>
> My view, to wrap it up, is that Nspire is so complex that one must really
> take the time to explore it fully before concluding about what can or can't
> be done. I mean, some of the stuff you see here weren't even possible in
> one's wildest dreams just a few months ago!
>
> Nelson
>

Nelson Sousa

unread,
Dec 21, 2008, 8:49:54 AM12/21/08
to tins...@googlegroups.com

Hmmmm... I think you might have gotten my opinion the wrong way.

Of course I agree that not having the ability to input and output data in a more flexible way is a huge setback to Nspire's programming capabilities! I've built my share of programs on TI calculators, more or less sophisticated, starting with TI-85 when I was in high school, and I'd surely like to have inputs in the middle of a program, custom menus, getkey functions, the ability to draw on a graph screen, create and delete tables, etc, etc.

But that's very different to say that there's something the 84+ can do and Nspire can't. You can achieve the same result on Nspire, without using any programming, if you enter the data on a spreadsheet. Just enter the data on column A and have column B display the result you want, it's a simple formula. If you can use a computer with a spreadsheet to do it, it's just the same to do it on Nspire. What Nspire can't do is perform the task the same way the 84+ does.

I think that the limitations on input/output are not permanent. I believe it's TI's goal to develop further the programming capabilities of Nspire, but probably didn't get to it as there are other priorities for development. I do also understand that given the complexity of Nspire's page/problem/document system, compared with previous generations of calculators, it will be tough to build a programming language that is both simple to use (it's meant for math teachers and students, not for professional programmers) and powerfull enough to please the most demanding users.

As of today, programming on Nspire can edit and/or create any kind of variable, being a real number, a function, a list, a matrix. On the spreadsheet you can store a column in a list variable. Combining the two, you can create your list of data on a spreadsgheet page and then edit it and manipulate it's elements with a program. Alternatively, you can call the program giving the results as arguments, instead of using a cycle of inputs. In this way the program is called with
program(k, {mark1, mark2, mark3, ...}),
where k is the maximum score. Programs allow for input. But all input has to be done when calling the program, as arguments.

The lack of input/output is a tough limitation. It forces one to be much more creative to achieve a desired result. But it's not an impossible obstacle. Just take a look at the Periodic Table I built (sorry for the lack of modesty). It uses almost no programming at all, only a few very small (and almost trivial) functions, and it gets the job done. Or the Galton bean machine document, that uses no programming at all, just geometry and a spreadsheet (two, actually).

Nelson

Eagle-Man

unread,
Dec 21, 2008, 7:14:48 PM12/21/08
to tins...@googlegroups.com
As Nelson said, I don't think the lack of input capability is a
permanent issue, because the OS is still under development (as seen in
every release - rearranging menus and adding features).

I am fairly certain that it will come (as did the rest of the
programming, not available until v1.2, and the program editor until
v1.4, I think), but we have to be patient. All this means is that a)
you have to use a spreadsheet to do your calculations, as Nelson
suggested, or b) you have to know all your data before-hand, and pass
in a list as an argument to a function or program.

As Nelson said, it's not impossible (is anything with this
calculator?), you just have to go about it in a different way.

--Eric F.

PS: When you say that all programs must have input and output I
certainly hope you don't only mean keyboard or mouse in the middle of
the program. I would consider passing arguments to a function (which
is available on the Nspire) as a form of input. It's just not as
dynamic or flexible as a true "input" command.

Nelson Sousa

unread,
Dec 21, 2008, 7:48:55 PM12/21/08
to tins...@googlegroups.com

remember the good old days?
all input was done at the start of the program with a punch card and all output came out as either blinking lights and a printed piece of paper full of seemlingly senseless numbers. 

And yet, it cracked the nazi code.

Programming is an art of the likes of cooking: the lack of the apropriate tools gives rise to the most creative solutions!


Nelson

Paul A

unread,
Dec 21, 2008, 11:01:02 PM12/21/08
to tinspire
A good parallel to cooking.

I started programming with the Nspire but tinkered a bit with my 84.
The lack of an input command does of course create limitations but
I've tried to find work arounds. One thing I do is execute the program
so the user can see the syntax of the inputs in the program name. You
can find a couple of examples at http://www.geocities.com/palves_nspire/Data_Management.html.
It's not ideal but will do in the meantime.

I agree that usually a program is not neccessary as many tools exist
within the applications that make it just as easy to create the needed
goal.

Paul

On Dec 21, 7:48 pm, "Nelson Sousa" <nso...@gmail.com> wrote:
> remember the good old days?all input was done at the start of the program
> ...
>
> read more »- Hide quoted text -
>
> - Show quoted text -

John Hanna

unread,
Dec 22, 2008, 6:09:30 AM12/22/08
to tinspire
I have a short intro TNS file on programming on my TI-Nspire page at
http://www.johnhanna.us

Reply all
Reply to author
Forward
0 new messages