Functions in 68k Basic

We're glad you came by, but you might find what you're looking for elsewhere.

TI-Basic Developer is not the site it once was. While its information on commands and other calculator features remains almost second-to-none, its forum, archives, and even hosting service, Wikidot, have been decaying for years. The calculator community would love to see what you're working on, or help you in your next coding adventure, but TI-Basic Developer is no longer the place to do it.

Instead, you should head over to Cemetech (primarily American) or TI-Planet (primarily international). Both are active, well-established forums with their own archives, chatrooms, reference material, and abundant coding tools and resources. We'll see you there, we hope.

Introduction

The 68k series can easily make an accurate distinction between programs and/or functions. Functions are just like programs except that they do not allow statements with side effects (such as Input or "Disp," or allow editing of non-local variables), and they return a single value, which in the absence of an explicit Return statement is the last expression evaluated in the system.

Moreover, the 68k version of TI-BASIC allows creating user-defined functions. Functions have the same syntax as programs except that they use the "Func…EndFunc" keywords instead of "Prgm…EndPrgm," and that they are not allowed to use instructions that perform I/O, modify non-local variables, nor call programs. However, functions can still be non-pure because they can call built-in functions such as "getTime(), getKey(), or rand()."

Lastly, all functions have a return value, which in the absence of an explicit Return statement is the last expression evaluated.

Functions Program Example

fact(x)
:Func
:If x=0
:Return 1
:If x<0
:Return undef
:x*fact(x-1)
:EndFunc

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Noncommercial 2.5 License.