Casio Programming - Defm vs. Lists

I generally divide Casio's programmable calculators into two groups: the older models with Defm/array memories, and the newer ones that use list variables. The Defm models may be older, but they offer some interesting advantages over the newer list-based models.

What's the difference?

Defm

The older Defm models - named after the Defm command that's used to allocate storage memories - use array indexing to indirectly reference storage memories. This is easiest to explain with an example.

Any of the variable names A-Z can have an array index added to the end, e.g. A[1] would actually refer to B, A[2] would refer to C, and so on. A[0] would refer to A itself, and you can even do negative references, as in G[-1], which points to F. The array index can also be any expression that returns an integer pointing to a valid memory, e.g. H[B+C] (not unlike using a base pointer and index pointer to compute an effective address in assembly programming).

So where does Defm come in? The 26 memories A-Z are permanently allocated; there is always contiguous memory reserved for them. This is how the array indexing works: by acting as an offset from the given variable name. Anybody who's worked with C arrays and pointers will find this immediately familiar. But you are not limited to just 26 memories, and this is what the Defm command is for. Defm takes one argument, which is an integer indicating how many additional memories you want to allocate. So, for example, Defm 10 will give you a total of 36 storage memories. But how do you access them? There are only 26 letters, after all. These 10 additional memories are allocated 'past' Z, meaning you can access them with Z[1] through Z[10] (or A[26] through A[35], or offsets from any other starting variable name).

The maximum number of memories you can allocate with Defm depends on the amount of memory in the calculator. In general, each additional memory consumes 8 bytes, so an fx-7000G has enough for around 52 extra memories. And you can deallocate all additional memories with Defm 0, leaving you with just A-Z (plus the special r and ϴ variables present on some later models), and reclaiming the maximum amount of memory for program storage.

You can also do range assignments to assign a single value to a contiguous range of memories in one statement. For example, 0→G~P or 0→V[1]~V[20] to zero out those blocks of memories.

Lists

Newer models, such as the fx-7400G and fx-9750G, have a more sophisticated memory allocation system. Rather than 26 (or 28) permanently allocated memories, you have a calculator with dynamic allocation of variables. No memory is allocated for the variables A-Z until you store something in them, and you can delete those variables later to reclaim the memory they consume. Thus, you can have more memory for programs if you need fewer than 26 variables.

These calculators also add list variables (as well as matrices, and other variables types), which are dedicated array variables. On the earlier models, you can have up to 6 lists, whereas current models allow for 156 - or more, if you archive some to flash memory or an SD card. The use of lists greatly eases statistical data entry and calculation, and there are a number of functions that generate or perform operations on entire lists. You can access the elements of a list with syntax very similar to the old array memory indexing, for example "List 1[7]" to access the 7th element of List 1. Indexes must be a positive integer, i.e. arrays start at 1.

But what you can't do is indirectly address the standard letter variables - no more A[5] to access the contents of F. Interestingly, range assignments are still supported, but only without array subscripts: 0→K~P will work.

What can array memories do that lists can't?

While the list-based calculators tend to be much more powerful overall, there are a few very nice programming techniques which take advantage of the old models' array memories. For example, it's much more straightforward to write a program which solves an equation for any variable.

To do this, you would write a program that uses an algorithm like Newton's method or the secant method to solve an expression, and before evaluating the expression, have the program store the value of the independent variable into A[A]. The value of A would be a pointer to the independent variable. So, if you were solving for F, store 5 into A, which will cause the store into A[A] to put the value in F. If you're solving for N, store 13 into A, directing A[A] to N. The solver program will run the same code in either case, but will be indirectly updating a different independent variable to find the solution.

For an example of this, see the TVM solver that I wrote for Defm Casios.

It's not impossible to do this with the list-based models, but the implementation is far less elegant. The solver program would have to read and write the independent variable using a bunch of conditional statements to access the correct variable based on some other index variable. This works okay if the number of potential variables is small, but is impractical if you might be using all 26.

Which is which?

The Defm models include most of the calculators starting from the fx-7000G and fx-4000P, to those up through the fx-9700GE and cfx-9800G. Note that the numerical order doesn't necessarily correspond to the chronological order.

These will typically have a Defm function printed either somewhere in the table of Mode commands on the oldest models (usually Mode + decimal point), or as a shifted function of the decimal point key. Another obvious tell is that the Defm models generally have their Alpha key placed to the right of the Shift key, whereas list-based models have it below the Shift key.

Defm Models

  • fx-4000P
  • fx-4800P
  • fx-4850P
  • fx-6000G
  • fx-6300G
  • fx-6500G
  • fx-6800G
  • fx-6900G
  • fx-7000G/GA/GB
  • fx-7200G
  • fx-7300G
  • fx-7500G
  • fx-7700G/GB/GBus
  • fx-7700GE/GH
  • fx-7800G/GC
  • fx-7900GC
  • fx-8000G
  • fx-8500G
  • fx-8700G/GB
  • fx-8800G/GC
  • fx-9700GE
  • cfx-9800G
  • cfx-9900GC
  • fx-9900GC
  • fx-9700GH

The list-based models begin with the fx-7400G, fx-9750G, and cfx-9850G, and continue through the present-day models such as the fx-9860G series and the Prizm.

List-Based Models

  • fx-6910G
  • fx-7400G
  • fx-7400G Plus
  • fx-7400G II
  • fx-7450G
  • fx-8930GT
  • fx-9750G
  • fx-9750G Plus
  • fx-9750GA Plus
  • fx-9750GII
  • cfx-9850G
  • cfx-9850G/GB Plus
  • cfx-9850G/GB Plus II
  • cfx-9850GC Plus
  • fx-9860G
  • fx-9860G SD
  • fx-9860G Slim
  • fx-9860GII
  • fx-9860GII SD
  • cfx-9930GT
  • cfx-9940GT
  • cfx-9950G
  • cfx-9950GB Plus
  • cfx-9950GB Plus II
  • cfx-9960GT
  • cfx-9990GT
  • fx-CG10 Prizm
  • fx-CG20 Prizm
  • fx-CG50 Prizm
  • fx-FD10 Pro

Other Oddities

You might have noticed that I didn't include the fx-5800P in either list. This is because it kind of straddles the line between the two designs, but without really hitting the full potential of either. There is a Defz function which allocates additional memories, but these can only be accessed as the array Z[]. The variables A-Z are dynamically allocated, and can't be addressed indirectly. So Z[1] is valid, but A[1] is not. It also has three stat lists: List X, List Y, and List Freq; but isn't as full-featured as the fully list-based models when it comes to list operations.

There are also the BASIC-programmable pocket computers to consider. Some of them, like the fx-602P, use an array allocation system that's entirely different from any of the calculators - or most computer versions of BASIC, for that matter! Some, like the fx-720P, use the traditional Defm system. And some, like the fx-730P and fx-770P, offer both Defm or standard BASIC-like Dim statements (only one mode can be in effect at a time, and the computer switches automatically when you execute Defm or Dim). Unfortunately, I don't have enough hands-on experience with different models to really know how deep the rabbit hole goes with these. There tends to be much more variation between pocket computer models than with the programmable calculators.

And for the record, all TI graphing calculators are list-based. None of them are capable of indirectly addressing real variables via array indexes, though the TI-92, TI-89, and Voyage 200 models have an indirection function #() that will convert a string to a variable or label reference.