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 $tempIf 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 $tempAnother 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 $tempThis 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.