Updated 2011-12-24 15:48:00 by RLE


2/6/2004 MDD: My seventh-grade daughter was complaining about the limitations of her calculator when checking her homework a while back, so I thought I'd play around a bit to see if I could put together a nice little calculator app that would serve her most immediate needs now, but also be able to evolve as her requirements evolve in the future. The initial result is t-Calc 1.0. You can download the Starkit [1] (fixed a bug), as well as a Windows Starpack [2].

It should be pretty self-explanatory, via the balloon help, but one cool feature that requires a little more explanation is the way you can assign arbitrary Tcl scripts to six user-defined buttons. I've pre-loaded them with some interesting little math apps by people like RS and Keith Vetter, but you can easily replace them with code of your choosing by right-clicking on the particular user button. For the time being, the user apps run in separate slave interpreters.

I'll most likely be adding all kinds of bells and whistles as time goes by, but this is pretty workable, for a start.

RS: Re teenage daughter, maybe Fun with functions may come in handy too?

MDD: It's already there, on key u-6. Her one-word review of that one was "Cool!" ;-) I also put your A little slide-rule app on u-5 and hacked together a little gui for your A little math language on u-1 (that gui needs to be redone, though). It also uses your A little database API and Persistent arrays internally.

One thing I intend to add, is the ability to choose whether you want each particular user app to run in a slave or in the master interpreter. Running in the master would allow the buttons to initiate operations on the values on the result box, for example. I'm also going to add a row of memory buttons: M+, MR, MC, etc.

2/7/2004 MDD: OK. Here's an updated version 1.1 (Starkit[3] and Windows Starpack[4]:

I added a checkbox option to determine whether the user-defined code runs in the main interpreter or in a slave interpreter. You can also define a custom button label for each user-defined button (though they won't appear until the next time you run the calculator). I also added a set of memory buttons, to do things like clear, add, subtract, recall, and swap. Also, pressing F2 opens up the Tcl console (on Windows, at least). There are a couple of global variables that are available to user apps that run in the main interpreter. These include $pi, which contains the value of Pi (3.14159265358979), and $resultbox, which is the text variable for the result box. That way, users can write their own apps that act like the native calculator buttons, working on and replacing the value in the result box. The "enter" command will register a number so that it is available for other key-based calculations.

For example:
 global resultbox pi
 set temp [expr $resultbox * (180 / $pi)]
 set resultbox ""
 enter $temp

If you set this code for one of the user keys, then make sure the "Run in slave" box unchecked, this will cause that button to convert the value in the result box from radians to degrees.

and for degrees to radians:
 global resultbox pi
 set temp [expr $resultbox * ($pi/180)]
 set resultbox ""
 enter $temp

Another example:
 global resultbox
 proc fact n {expr {
      $n<2? 1:
      $n>20? pow($n,$n)*exp(-$n)*sqrt(2*acos(-1)*$n):
             wide($n)*[fact [incr n -1]]}
 set temp [fact $resultbox]
 set resultbox ""
 enter $temp

This code will compute the Factorial.

The one downside I see with the current design is that the tcalc_config.txt file, created by the Persistent arrays utility, will grow a little each time you change the user-defined key definitions and each time you use the memory keys. I like the way that this file mantains a version history for these data, but I can imagine that it could grow unwieldy over time. If this gets cumbersome, you can just delete that file, then relaunch the calculator, and it will rewrite the original file.

My next addition will be the ability to add an arbitrary number of user-defined keys.