ticalc.org
Basics Archives Community Services Programming
Hardware Help About Search Your Account
   Home :: Community :: Articles :: Is it Time to Replace TI-BASIC?
Is it Time to Replace TI-BASIC?

Posted on 21 February 2005

The following text was written by George Limpert:

Anyone who remembers coding in TI-BASIC on the TI-81 or TI-85 and has then has coded for a more modern calculator knows the language has made great strides. Many of these changes have been influenced by the collection of nerds and gamers we affectionately refer to as the TI community. When TI created their original graphing calculator models, they never envisioned they would be used for the purposes we have found for them. A large portion of the changes to the language reflect the ideas of students over a decade ago who envisioned their calculators entertaining them during boring lectures. Despite the many changes to TI-BASIC, the language is still looked upon by the best game programmers as inadequate at best.

The complaint of many programmers about TI-BASIC is its speed, or the lack thereof. Unfortunately this issue is unlikely to be addressed anytime soon. When TI designed the language, they envisioned a way of adding new math functionality to the calculator, but with safeguards in place to prevent harmful behavior by programs. Speed of program execution is nice but doesn't appear to have been one of TI's primary objectives when creating the language.

Some people will suggest any serious programming ought to be done in assembly language. Compared with programming in TI-BASIC, it's like going hunting with a rifle instead of a pocket knife; it's faster, more powerful, and there's nothing to stop you from aiming that rifle squarely at your foot. If you make an error programming in TI-BASIC, you get an error message awaiting you to press a key. A mistake programming in assembly might give you a sudden boost of free RAM in exchange for your valued programs, equations, and notes. It's probably best to do serious game programming in assembly, but what about other types of programs?

Not too long ago, a fellow with a fine idea for calculator programming visited the flagship IRC channel for discussing TI calculators. Instead of compiling TI-BASIC programs so they run faster, he proposed replacing the language altogether. While he was met with ridicule, the idea is worthy of further discussion.

Last semester, I took a course on data compression techniques. One project assigned was to implement a Huffman encoder and decoder in C or Java. The discussion in class about Huffman coding went in one ear and out the other. Instead of struggling with C, I decided to implement the project first on my TI-89 because I expected TI-BASIC to be simpler. After about five minutes into coding, however, I hit a roadblock; there's no easy way to implement any sort of trees. Sure, it's possible, but to many programmers it's not obvious how to create or manipulate trees. The solution is to represent each node as a list; the first element is the value and the second and third elements are the names of child nodes within the binary tree. The child nodes are then accessed using a wonderful feature of the language known as indirection. On the TI-83 line of calculators, however, indirection isn't possible, and one would have to use a matrix, instead. Manipulating a matrix is slow and makes the programming involved even more complicated.

A tree is one of the fundamental techniques used in programming. It's applicable to many algorithms including searches and sorts. Unfortunately it can't easily be done within TI-BASIC.

This discussion also addresses another major limitation of TI-BASIC. What if, instead of storing the name of a child node, I want to store another data structure, such as a list, in one of those spots? The answer, of course, is it's not possible. One might ask why anyone would want to do this. Consider, for example, if a programming task involved pushing an integer and a list to a stack. While no such task readily comes to mind, it's a reasonable proposition. Stacks are another fundamental technique of programming. And, of course, complex data structures alone are useful at times.

There are many other such examples of why TI-BASIC is inadequate. Even if it will never be a fast language, simple programming techniques in the language ought to be exactly that -- simple. These limitations make TI-BASIC useless to many applications that are not at all related to gaming.

Programming in assembly can be difficult and dangerous to your data. It also usually requires a computer, a link cable, and a lot of patience. If that's not the best option and TI-BASIC is inadequate, maybe another programming language isn't so absurd of an idea after all.

The obvious question then becomes what features should such a language have. If a language is to truly replace TI-BASIC, it ought to have all the features that TI-BASIC currently has with some additions to fix the limitations with TI-BASIC. It's likely a replacement for TI-BASIC would need to be interpreted instead of compiled. One might assume that if we're creating a new interpreted language that has more features than TI-BASIC that it would be even slower. This is not necessarily the case.

The architecture of compilers and interpreters are very similar. The first step in either is referred to as a lexical scanner. This scans through the program text for keywords and symbols. The output generated is a series of tokens which represent the text of the original program. TI-BASIC does this as well; on some calculators, programs are always represented as tokens, but on others you will notice a delay when running a program for the first time due to this conversion. The next step of a compiler or interpreter is a parser. This deals with the syntax of the language, converting the string of tokens to a tree structure. A tree in an accurate representation of how a language is actually evaluated. Following this step is semantic analysis. A statement in a language may be syntactically correct but still make no sense to the compiler or interpreter. At this step, actions such as checking type and scope of variables are performed. At this point, compilers and interpreters diverge. An interpreter will evaluate the parse tree and execute the statements while a compiler will output another language such as assembly language or machine code.

This discussion on the architecture of interpreters is relevant because the implementation of TI-BASIC is not necessarily the most efficient scheme. Most likely, TI-BASIC stores programs merely as a stream of tokens because of the space required to store a representation of a parse tree. A parse tree, however, can be converted back to plain text just as the stream of tokens can. If parsing is only done once instead of being done constantly during execution, greater speed can be realized. One need not stop after parsing, however. Much of the semantic analysis step can also be performed at this time without modifying the parse tree. One may view this as a trade-off between program size and execution speed, but it need not be the case. A parse tree, when outputted to a file, can be compressed and then uncompressed at runtime, which may gain back some or all of the space lost to representing the program as a parse tree.

Another major change to such a new language is in the area of variables. There is no method within TI-BASIC to store a reference to another variable. Therefore any reference variables will necessarily be local to the interpreted program. Such a language, however, would still need to provide easy access to variables from TI-BASIC. This means that any variables that are to use the additional features of this language will need to be declared within the program. If this is the case, it allows for a few other enhancements to the language. One potential enhancement is the concept of aggregate data types.

Dealing with variables is a major slow point of TI-BASIC. The language on some calculators provides two very useful features for programmers -- dynamic types and dynamic resizing of variables. Dynamic types mean that if I have an variable currently storing an integer and I choose to store a string it it, the variable becomes a string variable. Dynamic resizing of variables means that the space used to store a variable is automatically expanded or contracted depending on how much space is needed to store the data. While these are very useful enhancements, they are also slow. A new language could make these features optional to programmers, providing an additional speed boost.

In spite of these and other possible enhancements, some tasks are better suited for assembly language. Furthermore, programmers shouldn't have to reinvent the wheel every time they write a program. PHP had a good idea when it allowed modules to be added to the interpreter that extend the functionality of the language. While a new calculator language may be at the core a replacement for TI-BASIC, the ability to extend the language through modules instead of writing a new interpreter makes the language far more powerful than it would be otherwise.

TI-BASIC is a fine language suitable for many tasks. Assembly has many advantages over TI-BASIC and has many uses as well. There are, however, many programming tasks that for one reason are another are not suited well to either language. A replacement for TI-BASIC, if sufficiently enhanced, can make TI calculators a far more powerful tool. The question of a new programming language shouldn't be a question of if but of how and what.

  Reply to this item

Re: Is it Time to Replace TI-BASIC?
Racer9  Account Info
(Web Page)

I think that this is a good idea except for one thing, Everyone that knows TI-BASIC would have to re-learn everything they know. In my opinion we should keep the language but TI should add more commands and spped it up slightly. I think that if someone made an TI-BASIC to assembly compiler that runs on the calc that would compile a TI-BASIC file to an assembly file most of the speed problems would be solved. I would work on this but I am just learning asm now.

Reply to this comment    21 February 2005, 16:28 GMT

Re: Re: Is it Time to Replace TI-BASIC?
anthony C  Account Info

That would definitally work, although it would take a large amount of time and resources, but it is definitally possible. Also, TI could do work behind the scenes of the TI-BASIC interpreter, and speed it up by optimizing the interpreter to assembler more, but still keeping the same commands (and therefore speeding up the programs). I am not sure if TI will be willing to do that though, as their main focus in is on classroom applications of the calculator, not necessarily the geeks who try to push the calc to the limits (althought they often get many pointers from these geeks, too.)

Reply to this comment    21 February 2005, 17:34 GMT

Re: Re: Is it Time to Replace TI-BASIC?
elfprince13 Account Info
(Web Page)

There is a computer program for turning basic to assembly. I don't remember if it is for Mac or PC, but I'm assuming it's for PC. Check it out in the file archives

Reply to this comment    21 February 2005, 18:04 GMT


Re: Re: Re: Is it Time to Replace TI-BASIC?
burntfuse  Account Info
(Web Page)

I tried it, but couldn't get it to work...

Reply to this comment    26 February 2005, 02:11 GMT

Re: Re: Is it Time to Replace TI-BASIC?
Racer9  Account Info
(Web Page)

I know that there is one for the computer. I mean one for the calc so you wouldn't have to waste your time moving the program to the computer and back again.

BTW I can't seem to make the program work anyway

Reply to this comment    21 February 2005, 22:13 GMT


Re: Re: Re: Is it Time to Replace TI-BASIC?
CalcSoft  Account Info
(Web Page)

I cant get that basic to assembly program to work either, if any one has gotten it to work, tell me how plz.

I a redone Ti-Basic would be best, use same commands and structures but add more functionality, like more commands, more data types, more speed etc. I think a good option would be that ti should make their own basic to assembly program for the computer (one that works) that would compile basic programs for max speed, but have the ease of programing as basic. That or someone make a program of their own if ti doesnt have the time.

I have tried for a couple of years to learn assembly and C but i havent found a good enuff tutoral on it to learn anything more that "Hello World". The hard part for me isnt the writing of the programs but the compiling of them. That and all the tutorals expect you to know the termonlogy already so half the the things they say you dont understand. If any one has a good tutoral on either launguage that is well completed and in ENGLISH, plz post(a link to) it.

Reply to this comment    22 February 2005, 04:04 GMT


Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
Gergely Patai  Account Info
(Web Page)

You surely haven't looked at the z80 docs directory in the archives of this very site, have you? 28 days is all you need.

Reply to this comment    22 February 2005, 07:06 GMT

Re: Re: Is it Time to Replace TI-BASIC?
Rob van Wijk  Account Info

The speed (or slowness) of Basic is not the primary concern at the moment. I know that's what we've been calling for years, but now George Limpert mentioned a way more interesting point.
Even though it's always been widely known there are a lot of things Basic can't do (graphics, memory management, ...), I don't think people have often realized you can't properly create a tree in Basic, or define your own data types for example. For instance, I've personally always known which data types I could use, but I can't remember consiously being aware of the limitation of not being able to create a simple record (Pascal) or struct (C). Working around these limitations quickly became a second nature, and I never even consiously saw them.
The way I see it, the inherent limitations of Basic, and whether they are so severe they warrant the development of another language, should be the central point of this discussion. Speed is quite irrelavant, there will always be enough tricks to get extra speed.

Reply to this comment    21 February 2005, 22:29 GMT


Re: Re: Re: Is it Time to Replace TI-BASIC?
Travis Evans  Account Info

You can create a tree in 89 or 92+ BASIC, if you're clever.

On those calculators, you can encode a list or a matrix to a string using the string() function. Then you can store the string in another list or matrix.

Then you can extract the string and convert it back into its original list or matrix using the expr() function.

I fairly recently discovered this trick and it's been very helpful in complex programs. You can even store lists or matrices several layers deep. But it's a little inconvenient because you have to keep using string() or expr() to convert the embeeded lists or matrices. And if you want to modify an embeeded list or matrix, you have to first extract it, store it to a temporary variable, change it, and then convert it back to a string. But it works.

Reply to this comment    21 February 2005, 22:41 GMT


Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
nyall Account Info
(Web Page)

There is an easier way.

1) Extract an element from a list or matrix.
2) Use GetType to check if it is a string or number.
If it is a number then you are done.
It it is a string, then the string is a name of another list/matrix. You can use indirection (# operator) on the string to access this list.

Reply to this comment    22 February 2005, 00:35 GMT


Re: Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
Travis Evans  Account Info

That would work, except you'd lose the convenience of storing an entire tree in one file, and you'd have to come up with unique names for all the lists/matrices so they wouldn't conflict with existing ones.

I made a program ("GPShell") that made a tree using a different method: each item was stored as a row in a matrix, and it had "pointers" to the rows of its parent and child items in the same matrix (each time an item was added, the row was appended to the end of the matrix and the pointers were written accordingly). I could easily have the program crawl down an entire branch of a tree (e.g., for copying or moving it to somewhere else in the structure) by using a recursive subroutine.

Reply to this comment    24 February 2005, 00:00 GMT


Re: Re: Is it Time to Replace TI-BASIC?
Drantin  Account Info

Except that just having it stored as an ASM file doesn't necessarily make it faster... it'd have to include osme kind of optimizing routine so that extraneous ASM was removed before saving the file as an ASM one...

BASIC as it is has to be converted to machine code to run anyway, but afaik it is all curently done at run-time as it comes across each BASIC instruction.

Reply to this comment    22 February 2005, 03:54 GMT

Re: Is it Time to Replace TI-BASIC?
Travis Evans  Account Info

Does anyone know if Python would be a feasible language for a TI calc? IIRC, you can extend the language with modules written in other languages, like C or ASM. It's also pretty easy to learn, and quite powerful.

Reply to this comment    21 February 2005, 22:51 GMT

[ ! ]
anykey  Account Info
(Web Page)

I think Ti Basic should work more like Python; you can have modules and dynamic variables.
Here's an example of how Python does modules:

I've got a program called example.py that contains an object that I'd like to use in my main program, main.py
example.py:
def say(text):
(tab)print text

main.py:
import example
say("Hello World!")

See? That was easy. You can also import specific functions without having to import the whole thing.

Reply to this comment    21 February 2005, 23:12 GMT


Re: [ ! ]
ti_is_good_++  Account Info

You can define local functions in TI-BASIC.

Define func(x,y)=Func
[code]
EndFunc

Reply to this comment    22 February 2005, 00:45 GMT


[ ! ]
anykey  Account Info
(Web Page)

Yes, but not on the z80 calcs (no, I'm not going to buy an 89!).
EOL

Reply to this comment    22 February 2005, 02:27 GMT


Re: [ ! ]
no_one_2000_  Account Info
(Web Page)

Yeah, that's something that has bugged me about the BASIC programming of the z80 series. It can make them really inefficient. A better structured language would probably also cut down on size because of things like this.

Reply to this comment    23 February 2005, 21:02 GMT


Re: Re: [ ! ]
burntfuse  Account Info
(Web Page)

I agree, BASIC for the 68k calcs doesn't seem bad, with support for functions and different var scopes and things like that, but it's BASIC for the z80 calcs that REALLY can't do much (without a lot of effort on the part of the programmer), as if TI just put it in as a last-minute thought or something.

Reply to this comment    28 February 2005, 20:03 GMT

Re: Is it Time to Replace TI-BASIC?
Travis Evans  Account Info

I was impressed at the improvement of 89 and 92+ BASIC, but I still have a lot of gripes. Here are some off the top of my head (there may be others that I forgot about):

1. Subroutines are still a pain if you don't want them stored in separate files cluttering everything up. You could use the Local statement to create local subs that are deleted automatically when the program quits, but then they can't call each other. The only other solution I can find is define the subs and functions in your program and delete them manually when it exists, which has its own disadvantages. (One being, if an error occurs or I break the program and choose GOTO, I often forget that my changes will be overwritten when I restart the program unless I remember to edit the *original* program instead (and I have to search for the sub or function there to do that). Changing code only to have it overwritten and have to do it again isn't fun.)

2. Functions can't use instructions or I/O operations. (Whose dumb idea was that, anyway?) If you want something to use instructions or I/O and have it return a value, you have to resort to global variables (ugh).

3. Variables can't be passed to subs or functions by reference, which means that if you want a sub or function to modify a variable, you once again have to resort to globals.

4. Navigating large program files is a pain (the Find... function helps, but it would be nice to have true inline subs/functions and be able to jump to them using a menu).

5. No debugging tools.

6. Local variables are cleared when a program hits a runtime error, making debugging difficult unless you change them to globals or put Disp or Pause statements in your programs.

Reply to this comment    21 February 2005, 23:16 GMT


Re: Re: Is it Time to Replace TI-BASIC?
Travis Evans  Account Info

Here are the rest (ticalc.org enforces a limit on post length--too bad we can't use a mailing list or something to discuss this).

7. For some reason, when an error occurs and I choose GOTO, the cursor doesn't always appear exactly where the error actually is (and then it takes me forever to figure out what's wrong as a result).

8. Inconsistent syntax/parameters for some functions.

Example 1: RclPic takes picname, picrow (y-axis), and piccol (x-axis), but StoPic takes picname, picrow (y-axis), piccol (x-axis), width (x-axis), and height (y-axis). It would seem more logical for the order to be height (y-axis), width (x-axis) instead, for StoPic.

Example 2: Output takes row, col, expr, but PxlText takes str, row, col. Logically, it should be either expr/str, row col, or row, col, expr/str for both instructions.

9. Toolbar instructions require using Lbls, so they essentially force you to use Gotos. (Even if you don't actually use the Goto command, the menus are essentially Goto statements.)

10. A few instructions would work better as functions (e.g., SortA and SortD), so you could use them in functions (although I think instructions should have been allowed in functions, anyway).

11. Some functions/instructions are too "picky" as far as data types are concerned. Example: checkTmr() gives an Argument error if you pass it a value in the Approx mode setting, even if it is an integer. In that case, you have to use the exact() function on the argument for it to be accepted.

Anyone have any others?

Reply to this comment    21 February 2005, 23:17 GMT

Re: Re: Re: Is it Time to Replace TI-BASIC?
nyall Account Info
(Web Page)

1. Create a folder to put the functions in.

4. The editor is not the language. But yes we need a better editor.

8. Example 1. An existing picture has its dimensions as part of the picture. So RclPic lets you specify the cordinates to display the picture at. StoPic lets you specify the cordinates to grab the picture and the dimensions of the picture. The two commands are consistent, but one requires more arguments.
Example 2. I'll agree.

Reply to this comment    22 February 2005, 00:55 GMT


Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
Travis Evans  Account Info

1. True, but if I have to do that with every one of my programs, I'll have too many folders cluttering the list (since the 89 doesn't support nested folders), and then I'm back to a similar problem. :)

4. Oops. Okay, maybe I should have said "TI-BASIC and its editor."

8 ex. 1. It's inconsistent to me, because the second and third arguments of StoPic take y and x-axis coordinates, but the fourth and fifth arguments require me to think of the dimensions in the reverse order (x- then y-axis). I keep wanting to enter height then width instead of width then height (since I entered the row then column of the position). Hope that made sense.

Reply to this comment    23 February 2005, 23:54 GMT


Re: Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
Travis Evans  Account Info

Speaking of the program editor, I just remembered another thing (this applies to the text editor too): Page up and down are too slow. They're not much faster than just using the arrow keys.

I've never really understood why the TI calc editors have to scroll one line at a time to page up or down (that's probably why it's so slow). I've never seen any other software need to do that.

Reply to this comment    24 February 2005, 00:04 GMT


Re: Re: Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
Ankur Dave Account Info

Another major problem in the OS is that there is no cut and paste in the editor. This would be an extremely useful feature. In addition, in the next Ti graphing calculator, there should be an implementation of a QWERTY keyboard. I just hate hunting for a letter on the keypad. A way to implement this easily would be to make a program for the desktop that could open and edit TI-BASIC programs.

Reply to this comment    29 October 2005, 03:56 GMT

New Language Suggestions
ti_is_good_++  Account Info

Off the top of my head, I'd like an errornum for "Wrong Calculator Model," a checkbox/radiobuttons, a mouse, simple buttons, external labels, and windows.

Reply to this comment    23 February 2005, 05:25 GMT


Re: New Language Suggestions
iconmaster Account Info

Also,a wait or delay command would be nice for z80 calcs.

Reply to this comment    4 April 2009, 23:39 GMT

Re: Re: Re: Is it Time to Replace TI-BASIC?
ti_is_good_++  Account Info

Faster For loops, too.

Reply to this comment    23 February 2005, 05:26 GMT


Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
Travis Evans  Account Info

Yep. Although For loops are still faster than the other types of loops, as far as I know. But they still seem slower than on the Z80 calcs.

Reply to this comment    23 February 2005, 23:55 GMT

Re: Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
ti_is_good_++  Account Info

For is actually about the slowest loop.

Reply to this comment    24 February 2005, 00:16 GMT


Re: Re: Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
Travis Evans  Account Info

It is? In my tests, the following types of loops would always execute slower on my 89 than a For loop:

:Local x
:0->x
:While x<50
:x+1->x
:EndWhile

:Local x
:Lbl a
:x+1->x
:If x<50:Goto a

etc.

Reply to this comment    25 February 2005, 23:52 GMT


Re: Re: Re: Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
ti_is_good_++  Account Info

It's always been slower on my tests on 92+, 89, V200 and 89Ti, VTI and hardware. It might have something to do with the local variables. I don't know.

Reply to this comment    26 February 2005, 00:48 GMT


Re: Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
Kevin Kofler Account Info
(Web Page)

Try retokenizing your program with Tokens89 (available at my web page). The builtin tokenizer sometimes leaves the offsets at 0, to be computed at runtime. Tokens89 always computes the offsets, leading to faster loop execution.

Reply to this comment    24 February 2005, 01:13 GMT


Re: Re: Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
Travis Evans  Account Info

Hmm... I'll check. Does that have anything to do with the reason why after tokenizing a program with embedded Subs/Functions, the subs/functions will sometimes still have delays until they've been run a second time?

Reply to this comment    25 February 2005, 23:54 GMT


Re: Re: Re: Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
Travis Evans  Account Info

Oops, you didn't mention the platform it runs on (I didn't know it was a PC program). I'd have to see if it will run under WINE successfully on my Linux system (some Win32 programs do, others don't (mainly programs that use non-standard GUIS)).

Reply to this comment    26 February 2005, 00:03 GMT


Re: Re: Re: Re: Re: Re: Re: Re: Is it Time to Replace TI-BASIC?
Kevin Kofler Account Info
(Web Page)

I don't know if it works under WINE. I can try it (I have a Windows/Linux dual boot), but I'm not sure I can do anything for you if it doesn't. Tokens89 should really be rewritten in a more efficient, more adapted to the purpose and more portable language than VB. C would be a good candidate. But I have so many other projects...

Reply to this comment    27 February 2005, 01:49 GMT


Re: Re: Re: Re: Re: George Limpert Asks: Is it Time to Replace TI-BASIC?
CajunLuke  Account Info
(Web Page)

1. Local subroutines can too call other local subroutines. I do it all the time.

2. It's common programming practice to disallow/restrict/dissapprove of input/output statements in calculational functions. The point of a function (in 68k locution, function vs. program) is to do a calculation with data input through the parameters, and output through a Return command. It is not supposed to disrupt the calling program's input/output scheme (maybe the end programmer likes a different format than you do). They can, too use instructions, just not all of them. The TI-89/92+ manual has upwards of fifty pages on the commands available built-in, and a list of maybe ten or fifteen commands that function's can't use.

3. Point. (Although I've never had reason to use reference variables.)

4. Point. I get around this by using descriptive comments and searching for those or memorizing a unique line of code in the section (usually the label).

5. Point.

6. That's the point of local variables. Changing them to globals is as simple as commenting out the "local" statement.

7. It appears at the beginning of the line, sometimes. That's all a C or Java or Cocoa compiler gives you anyway, so be happy when the cursor is in the middle of the line.

8. Point.

9. And this is a problem.....how?

10. Point.

11. I leave my calculator in Exact, anyway, so I've never had this problem.

Overall, TI appears to make you use as much of the MVC paradigm as possible in a function-oriented language. Kudos, although it can be irritating at times. It could also be entirely accidental.

Reply to this comment    27 February 2005, 16:25 GMT

1  2  3  4  5  6  7  

You can change the number of comments per page in Account Preferences.

  Copyright © 1996-2012, the ticalc.org project. All rights reserved. | Contact Us | Disclaimer